diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2015-04-15 10:28:17 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2015-04-15 10:28:17 +1200 |
commit | 0c85c72dc43d0d017e2bf5af9c2def46968d0499 (patch) | |
tree | ab361a7c2972e666f9e565c02bc83a9348bec7aa /test/test_odict.py | |
parent | aeebf31927eb3ff74824525005c7b146024de6d5 (diff) | |
download | mitmproxy-0c85c72dc43d0d017e2bf5af9c2def46968d0499.tar.gz mitmproxy-0c85c72dc43d0d017e2bf5af9c2def46968d0499.tar.bz2 mitmproxy-0c85c72dc43d0d017e2bf5af9c2def46968d0499.zip |
ODict improvements
- Setting values now tries to preserve the existing order, rather than
just appending to the end.
- __repr__ now returns a repr of the tuple list. The old repr becomes a
.format() method. This is clearer, makes troubleshooting easier, and
doesn't assume all data in ODicts are header-like
Diffstat (limited to 'test/test_odict.py')
-rw-r--r-- | test/test_odict.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/test/test_odict.py b/test/test_odict.py index c2415b6d..c01c4dbe 100644 --- a/test/test_odict.py +++ b/test/test_odict.py @@ -6,6 +6,11 @@ class TestODict: def setUp(self): self.od = odict.ODict() + def test_repr(self): + h = odict.ODict() + h["one"] = ["two"] + assert repr(h) + def test_str_err(self): h = odict.ODict() tutils.raises(ValueError, h.__setitem__, "key", "foo") @@ -20,7 +25,7 @@ class TestODict: "two: tre\r\n", "\r\n" ] - out = repr(self.od) + out = self.od.format() for i in expected: assert out.find(i) >= 0 @@ -39,7 +44,7 @@ class TestODict: self.od["one"] = ["uno"] expected1 = "one: uno\r\n" expected2 = "\r\n" - out = repr(self.od) + out = self.od.format() assert out.find(expected1) >= 0 assert out.find(expected2) >= 0 @@ -150,3 +155,19 @@ class TestODictCaseless: assert self.od.keys() == ["foo"] self.od.add("bar", 2) assert len(self.od.keys()) == 2 + + def test_add_order(self): + od = odict.ODict( + [ + ["one", "uno"], + ["two", "due"], + ["three", "tre"], + ] + ) + od["two"] = ["foo", "bar"] + assert od.lst == [ + ["one", "uno"], + ["two", "foo"], + ["three", "tre"], + ["two", "bar"], + ] |