MCPcopy Create free account
hub / github.com/RustPython/RustPython / test_copying

Method test_copying

Lib/test/test_ordered_dict.py:297–338  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

295 self.assertNotEqual(od1, OrderedDict(pairs[:-1]))
296
297 def test_copying(self):
298 OrderedDict = self.OrderedDict
299 # Check that ordered dicts are copyable, deepcopyable, picklable,
300 # and have a repr/eval round-trip
301 pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
302 od = OrderedDict(pairs)
303 od.x = ['x']
304 od.z = ['z']
305 def check(dup):
306 msg = "\ncopy: %s\nod: %s" % (dup, od)
307 self.assertIsNot(dup, od, msg)
308 self.assertEqual(dup, od)
309 self.assertEqual(list(dup.items()), list(od.items()))
310 self.assertEqual(len(dup), len(od))
311 self.assertEqual(type(dup), type(od))
312 check(od.copy())
313 dup = copy.copy(od)
314 check(dup)
315 self.assertIs(dup.x, od.x)
316 self.assertIs(dup.z, od.z)
317 self.assertNotHasAttr(dup, 'y')
318 dup = copy.deepcopy(od)
319 check(dup)
320 self.assertEqual(dup.x, od.x)
321 self.assertIsNot(dup.x, od.x)
322 self.assertEqual(dup.z, od.z)
323 self.assertIsNot(dup.z, od.z)
324 self.assertNotHasAttr(dup, 'y')
325 # pickle directly pulls the module, so we have to fake it
326 with replaced_module('collections', self.module):
327 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
328 with self.subTest(proto=proto):
329 dup = pickle.loads(pickle.dumps(od, proto))
330 check(dup)
331 self.assertEqual(dup.x, od.x)
332 self.assertEqual(dup.z, od.z)
333 self.assertNotHasAttr(dup, 'y')
334 check(eval(repr(od)))
335 update_test = OrderedDict()
336 update_test.update(od)
337 check(update_test)
338 check(OrderedDict(od))
339
340 def test_yaml_linkage(self):
341 OrderedDict = self.OrderedDict

Callers

nothing calls this directly

Calls 15

copyMethod · 0.95
reprFunction · 0.85
assertIsNotMethod · 0.80
subTestMethod · 0.80
OrderedDictClass · 0.70
checkFunction · 0.70
replaced_moduleFunction · 0.70
evalFunction · 0.50
copyMethod · 0.45
assertIsMethod · 0.45
assertNotHasAttrMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected