MCPcopy Create free account
hub / github.com/python/cpython / test_mydel

Method test_mydel

Lib/idlelib/idle_test/test_delegator.py:9–40  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

7class DelegatorTest(unittest.TestCase):
8
9 def test_mydel(self):
10 # Test a simple use scenario.
11
12 # Initialize an int delegator.
13 mydel = Delegator(int)
14 self.assertIs(mydel.delegate, int)
15 self.assertEqual(mydel._Delegator__cache, set())
16 # Trying to access a non-attribute of int fails.
17 self.assertRaises(AttributeError, mydel.__getattr__, 'xyz')
18
19 # Add real int attribute 'bit_length' by accessing it.
20 bl = mydel.bit_length
21 self.assertIs(bl, int.bit_length)
22 self.assertIs(mydel.__dict__['bit_length'], int.bit_length)
23 self.assertEqual(mydel._Delegator__cache, {'bit_length'})
24
25 # Add attribute 'numerator'.
26 mydel.numerator
27 self.assertEqual(mydel._Delegator__cache, {'bit_length', 'numerator'})
28
29 # Delete 'numerator'.
30 del mydel.numerator
31 self.assertNotIn('numerator', mydel.__dict__)
32 # The current implementation leaves it in the name cache.
33 # self.assertIn('numerator', mydel._Delegator__cache)
34 # However, this is not required and not part of the specification
35
36 # Change delegate to float, first resetting the attributes.
37 mydel.setdelegate(float) # calls resetcache
38 self.assertNotIn('bit_length', mydel.__dict__)
39 self.assertEqual(mydel._Delegator__cache, set())
40 self.assertIs(mydel.delegate, float)
41
42
43if __name__ == '__main__':

Callers

nothing calls this directly

Calls 7

setdelegateMethod · 0.95
DelegatorClass · 0.90
setFunction · 0.85
assertNotInMethod · 0.80
assertIsMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected