diff options
author | Raymond Hettinger <python@rcn.com> | 2008-02-04 22:07:15 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-02-04 22:07:15 (GMT) |
commit | edf3b734c05b754f03e36c1eb69bfc7343b8a150 (patch) | |
tree | 1bbfa338b8b264a123476aa5a8a454367dd013b7 /Lib/test/test_userdict.py | |
parent | d190f9c45e07caa77f8f79ac34560d41271a7c7b (diff) | |
download | cpython-edf3b734c05b754f03e36c1eb69bfc7343b8a150.zip cpython-edf3b734c05b754f03e36c1eb69bfc7343b8a150.tar.gz cpython-edf3b734c05b754f03e36c1eb69bfc7343b8a150.tar.bz2 |
Remove DictMixin which is superceded by collections.MutableMapping
Diffstat (limited to 'Lib/test/test_userdict.py')
-rw-r--r-- | Lib/test/test_userdict.py | 139 |
1 files changed, 0 insertions, 139 deletions
diff --git a/Lib/test/test_userdict.py b/Lib/test/test_userdict.py index 039ed65..ac33be7 100644 --- a/Lib/test/test_userdict.py +++ b/Lib/test/test_userdict.py @@ -194,150 +194,11 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol): else: self.fail("g[42] didn't raise KeyError") -########################## -# Test Dict Mixin -class SeqDict(UserDict.DictMixin): - """Dictionary lookalike implemented with lists. - - Used to test and demonstrate DictMixin - """ - def __init__(self, other=None, **kwargs): - self.keylist = [] - self.valuelist = [] - if other is not None: - for (key, value) in other: - self[key] = value - for (key, value) in kwargs.items(): - self[key] = value - def __getitem__(self, key): - try: - i = self.keylist.index(key) - except ValueError: - raise KeyError - return self.valuelist[i] - def __setitem__(self, key, value): - try: - i = self.keylist.index(key) - self.valuelist[i] = value - except ValueError: - self.keylist.append(key) - self.valuelist.append(value) - def __delitem__(self, key): - try: - i = self.keylist.index(key) - except ValueError: - raise KeyError - self.keylist.pop(i) - self.valuelist.pop(i) - def keys(self): - return list(self.keylist) - def copy(self): - d = self.__class__() - for key, value in self.items(): - d[key] = value - return d - @classmethod - def fromkeys(cls, keys, value=None): - d = cls() - for key in keys: - d[key] = value - return d - -class UserDictMixinTest(mapping_tests.TestMappingProtocol): - type2test = SeqDict - - def test_all(self): - ## Setup test and verify working of the test class - - # check init - s = SeqDict() - - # exercise setitem - s[10] = 'ten' - s[20] = 'twenty' - s[30] = 'thirty' - - # exercise delitem - del s[20] - # check getitem and setitem - self.assertEqual(s[10], 'ten') - # check keys() and delitem - self.assertEqual(s.keys(), [10, 30]) - - ## Now, test the DictMixin methods one by one - - # __contains__ - self.assert_(10 in s) - self.assert_(20 not in s) - - # __iter__ - self.assertEqual([k for k in s], [10, 30]) - - # __len__ - self.assertEqual(len(s), 2) - - # iteritems - self.assertEqual(list(s.items()), [(10,'ten'), (30, 'thirty')]) - - # iterkeys - self.assertEqual(list(s.keys()), [10, 30]) - - # itervalues - self.assertEqual(list(s.values()), ['ten', 'thirty']) - - # values - self.assertEqual(s.values(), ['ten', 'thirty']) - - # items - self.assertEqual(s.items(), [(10,'ten'), (30, 'thirty')]) - - # get - self.assertEqual(s.get(10), 'ten') - self.assertEqual(s.get(15,'fifteen'), 'fifteen') - self.assertEqual(s.get(15), None) - - # setdefault - self.assertEqual(s.setdefault(40, 'forty'), 'forty') - self.assertEqual(s.setdefault(10, 'null'), 'ten') - del s[40] - - # pop - self.assertEqual(s.pop(10), 'ten') - self.assert_(10 not in s) - s[10] = 'ten' - self.assertEqual(s.pop("x", 1), 1) - s["x"] = 42 - self.assertEqual(s.pop("x", 1), 42) - - # popitem - k, v = s.popitem() - self.assert_(k not in s) - s[k] = v - - # clear - s.clear() - self.assertEqual(len(s), 0) - - # empty popitem - self.assertRaises(KeyError, s.popitem) - - # update - s.update({10: 'ten', 20:'twenty'}) - self.assertEqual(s[10], 'ten') - self.assertEqual(s[20], 'twenty') - - # cmp - self.assertEqual(s, {10: 'ten', 20:'twenty'}) - t = SeqDict() - t[20] = 'twenty' - t[10] = 'ten' - self.assertEqual(s, t) def test_main(): test_support.run_unittest( UserDictTest, - UserDictMixinTest ) if __name__ == "__main__": |