From a5c4cd034081d7dcdbd4b46bd69718edb45d4719 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 21 May 2016 11:37:36 +1200 Subject: A clearer implementation of MultiDictView This makes MultiDictView work with a simple getter/setter pair, rather than using attributes with implicit leading underscores. Also move MultiDictView into multidict.py and adds some simple unit tests. --- test/netlib/test_multidict.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'test/netlib') diff --git a/test/netlib/test_multidict.py b/test/netlib/test_multidict.py index ceea3806..5bb65e3f 100644 --- a/test/netlib/test_multidict.py +++ b/test/netlib/test_multidict.py @@ -1,5 +1,5 @@ from netlib import tutils -from netlib.multidict import MultiDict, ImmutableMultiDict +from netlib.multidict import MultiDict, ImmutableMultiDict, MultiDictView class _TMulti(object): @@ -214,4 +214,26 @@ class TestImmutableMultiDict(object): def test_with_insert(self): md = TImmutableMultiDict() assert md.with_insert(0, "foo", "bar").fields == (("foo", "bar"),) - assert md.fields == () \ No newline at end of file + + +class TParent(object): + def __init__(self): + self.vals = tuple() + + def setter(self, vals): + self.vals = vals + + def getter(self): + return self.vals + + +class TestMultiDictView(object): + def test_modify(self): + p = TParent() + tv = MultiDictView(p.getter, p.setter) + assert len(tv) == 0 + tv["a"] = "b" + assert p.vals == (("a", "b"),) + tv["c"] = "b" + assert p.vals == (("a", "b"), ("c", "b")) + assert tv["a"] == "b" -- cgit v1.2.3