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

Method unop_test

Lib/test/test_descr.py:82–96  ·  view source on GitHub ↗
(self, a, res, expr="len(a)", meth="__len__")

Source from the content-addressed store, hash-verified

80 self.unops[name] = expr
81
82 def unop_test(self, a, res, expr="len(a)", meth="__len__"):
83 d = {'a': a}
84 self.assertEqual(eval(expr, d), res)
85 t = type(a)
86 m = getattr(t, meth)
87
88 # Find method in parent class
89 while meth not in t.__dict__:
90 t = t.__bases__[0]
91 # in some implementations (e.g. PyPy), 'm' can be a regular unbound
92 # method object; the getattr() below obtains its underlying function.
93 self.assertEqual(getattr(m, 'im_func', m), t.__dict__[meth])
94 self.assertEqual(m(a), res)
95 bm = getattr(a, meth)
96 self.assertEqual(bm(), res)
97
98 def binop_test(self, a, b, res, expr="a+b", meth="__add__"):
99 d = {'a': a, 'b': b}

Callers 5

test_listsMethod · 0.95
test_dictsMethod · 0.95
number_operatorsMethod · 0.95
test_spam_listsMethod · 0.95
test_spam_dictsMethod · 0.95

Calls 2

mFunction · 0.50
assertEqualMethod · 0.45

Tested by

no test coverage detected