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