ยปCore Development>Code coverage>Lib/unittest/test/testmock/testsentinel.py

Python code coverage for Lib/unittest/test/testmock/testsentinel.py

#countcontent
1n/aimport unittest
2n/aimport copy
3n/aimport pickle
4n/afrom unittest.mock import sentinel, DEFAULT
5n/a
6n/a
7n/aclass SentinelTest(unittest.TestCase):
8n/a
9n/a def testSentinels(self):
10n/a self.assertEqual(sentinel.whatever, sentinel.whatever,
11n/a 'sentinel not stored')
12n/a self.assertNotEqual(sentinel.whatever, sentinel.whateverelse,
13n/a 'sentinel should be unique')
14n/a
15n/a
16n/a def testSentinelName(self):
17n/a self.assertEqual(str(sentinel.whatever), 'sentinel.whatever',
18n/a 'sentinel name incorrect')
19n/a
20n/a
21n/a def testDEFAULT(self):
22n/a self.assertIs(DEFAULT, sentinel.DEFAULT)
23n/a
24n/a def testBases(self):
25n/a # If this doesn't raise an AttributeError then help(mock) is broken
26n/a self.assertRaises(AttributeError, lambda: sentinel.__bases__)
27n/a
28n/a def testPickle(self):
29n/a for proto in range(pickle.HIGHEST_PROTOCOL+1):
30n/a with self.subTest(protocol=proto):
31n/a pickled = pickle.dumps(sentinel.whatever, proto)
32n/a unpickled = pickle.loads(pickled)
33n/a self.assertIs(unpickled, sentinel.whatever)
34n/a
35n/a def testCopy(self):
36n/a self.assertIs(copy.copy(sentinel.whatever), sentinel.whatever)
37n/a self.assertIs(copy.deepcopy(sentinel.whatever), sentinel.whatever)
38n/a
39n/a
40n/aif __name__ == '__main__':
41n/a unittest.main()