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