MCPcopy Index your code
hub / github.com/python/cpython / test_spam_dicts

Method test_spam_dicts

Lib/test/test_descr.py:355–402  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

353 @support.impl_detail("the module 'xxsubtype' is internal")
354 @unittest.skipIf(xxsubtype is None, "requires xxsubtype module")
355 def test_spam_dicts(self):
356 # Testing spamdict operations...
357 import copy, xxsubtype as spam
358 def spamdict(d, memo=None):
359 import xxsubtype as spam
360 sd = spam.spamdict()
361 for k, v in list(d.items()):
362 sd[k] = v
363 return sd
364 # This is an ugly hack:
365 copy._deepcopy_dispatch[spam.spamdict] = spamdict
366
367 self.binop_test(spamdict({1:2,3:4}), 1, 1, "b in a", "__contains__")
368 self.binop_test(spamdict({1:2,3:4}), 2, 0, "b in a", "__contains__")
369 self.binop_test(spamdict({1:2,3:4}), 1, 2, "a[b]", "__getitem__")
370 d = spamdict({1:2,3:4})
371 l1 = []
372 for i in list(d.keys()):
373 l1.append(i)
374 l = []
375 for i in iter(d):
376 l.append(i)
377 self.assertEqual(l, l1)
378 l = []
379 for i in d.__iter__():
380 l.append(i)
381 self.assertEqual(l, l1)
382 l = []
383 for i in type(spamdict({})).__iter__(d):
384 l.append(i)
385 self.assertEqual(l, l1)
386 straightd = {1:2, 3:4}
387 spamd = spamdict(straightd)
388 self.unop_test(spamd, 2, "len(a)", "__len__")
389 self.unop_test(spamd, repr(straightd), "repr(a)", "__repr__")
390 self.set2op_test(spamdict({1:2,3:4}), 2, 3, spamdict({1:2,2:3,3:4}),
391 "a[b]=c", "__setitem__")
392 # Test subclassing
393 class C(spam.spamdict):
394 def foo(self): return 1
395 a = C()
396 self.assertEqual(list(a.items()), [])
397 self.assertEqual(a.foo(), 1)
398 a['foo'] = 'bar'
399 self.assertEqual(list(a.items()), [('foo', 'bar')])
400 self.assertEqual(a.getstate(), 0)
401 a.setstate(100)
402 self.assertEqual(a.getstate(), 100)
403
404 def test_wrap_lenfunc_bad_cast(self):
405 self.assertEqual(range(sys.maxsize).__len__(), sys.maxsize)

Callers

nothing calls this directly

Calls 13

binop_testMethod · 0.95
unop_testMethod · 0.95
set2op_testMethod · 0.95
fooMethod · 0.95
getstateMethod · 0.95
setstateMethod · 0.95
listClass · 0.85
CClass · 0.70
keysMethod · 0.45
appendMethod · 0.45
assertEqualMethod · 0.45
__iter__Method · 0.45

Tested by

no test coverage detected