(root)/
Python-3.12.0/
Lib/
test/
test_unittest/
testmock/
testsentinel.py
       1  import unittest
       2  import copy
       3  import pickle
       4  from unittest.mock import sentinel, DEFAULT
       5  
       6  
       7  class ESC[4;38;5;81mSentinelTest(ESC[4;38;5;149munittestESC[4;38;5;149m.ESC[4;38;5;149mTestCase):
       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  
      40  if __name__ == '__main__':
      41      unittest.main()