MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_all

Method test_all

Lib/test/test_userdict.py:17–142  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

15 type2test = collections.UserDict
16
17 def test_all(self):
18 # Test constructors
19 u = collections.UserDict()
20 u0 = collections.UserDict(d0)
21 u1 = collections.UserDict(d1)
22 u2 = collections.UserDict(d2)
23
24 uu = collections.UserDict(u)
25 uu0 = collections.UserDict(u0)
26 uu1 = collections.UserDict(u1)
27 uu2 = collections.UserDict(u2)
28
29 # keyword arg constructor
30 self.assertEqual(collections.UserDict(one=1, two=2), d2)
31 # item sequence constructor
32 self.assertEqual(collections.UserDict([('one',1), ('two',2)]), d2)
33 self.assertEqual(collections.UserDict(dict=[('one',1), ('two',2)]),
34 {'dict': [('one', 1), ('two', 2)]})
35 # both together
36 self.assertEqual(collections.UserDict([('one',1), ('two',2)], two=3, three=5), d3)
37
38 # alternate constructor
39 self.assertEqual(collections.UserDict.fromkeys('one two'.split()), d4)
40 self.assertEqual(collections.UserDict().fromkeys('one two'.split()), d4)
41 self.assertEqual(collections.UserDict.fromkeys('one two'.split(), 1), d5)
42 self.assertEqual(collections.UserDict().fromkeys('one two'.split(), 1), d5)
43 self.assertTrue(u1.fromkeys('one two'.split()) is not u1)
44 self.assertIsInstance(u1.fromkeys('one two'.split()), collections.UserDict)
45 self.assertIsInstance(u2.fromkeys('one two'.split()), collections.UserDict)
46
47 # Test __repr__
48 self.assertEqual(str(u0), str(d0))
49 self.assertEqual(repr(u1), repr(d1))
50 self.assertIn(repr(u2), ("{'one': 1, 'two': 2}",
51 "{'two': 2, 'one': 1}"))
52
53 # Test rich comparison and __len__
54 all = [d0, d1, d2, u, u0, u1, u2, uu, uu0, uu1, uu2]
55 for a in all:
56 for b in all:
57 self.assertEqual(a == b, len(a) == len(b))
58
59 # Test __getitem__
60 self.assertEqual(u2["one"], 1)
61 self.assertRaises(KeyError, u1.__getitem__, "two")
62
63 # Test __setitem__
64 u3 = collections.UserDict(u2)
65 u3["two"] = 2
66 u3["three"] = 3
67
68 # Test __delitem__
69 del u3["three"]
70 self.assertRaises(KeyError, u3.__delitem__, "three")
71
72 # Test clear
73 u3.clear()
74 self.assertEqual(u3, {})

Callers

nothing calls this directly

Calls 15

fromkeysMethod · 0.95
copyMethod · 0.95
getMethod · 0.95
strFunction · 0.85
reprFunction · 0.85
lenFunction · 0.85
MyUserDictClass · 0.85
sortedFunction · 0.85
setFunction · 0.85
assertTrueMethod · 0.80
assertIsInstanceMethod · 0.80
assertInMethod · 0.80

Tested by

no test coverage detected