diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-01-11 20:13:03 +0200 |
---|---|---|
committer | Chris Withers <chris@withers.org> | 2019-04-30 08:39:55 +0100 |
commit | 5a0e779b61ef3a87d6bc48bc3355a73f0deb523a (patch) | |
tree | 463ace25c0d86e463f00521200ab0d2034f48b0e /mock/tests | |
parent | f9efc3e82452b7a7c936d85ff08eb9368a2f03eb (diff) | |
download | mock-5a0e779b61ef3a87d6bc48bc3355a73f0deb523a.tar.gz |
Issue #20804: The unittest.mock.sentinel attributes now preserve their
identity when they are copied or pickled.
Backports: d9c956fb23f1c38c8050e9531ff5a77559f7f7af
Signed-off-by: Chris Withers <chris@simplistix.co.uk>
Diffstat (limited to 'mock/tests')
-rw-r--r-- | mock/tests/testsentinel.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/mock/tests/testsentinel.py b/mock/tests/testsentinel.py index 3253fa3..afaa194 100644 --- a/mock/tests/testsentinel.py +++ b/mock/tests/testsentinel.py @@ -3,7 +3,8 @@ # http://www.voidspace.org.uk/python/mock/ import unittest - +import copy +import pickle from mock import sentinel, DEFAULT @@ -28,6 +29,17 @@ class SentinelTest(unittest.TestCase): # If this doesn't raise an AttributeError then help(mock) is broken self.assertRaises(AttributeError, lambda: sentinel.__bases__) + def testPickle(self): + for proto in range(pickle.HIGHEST_PROTOCOL+1): + with self.subTest(protocol=proto): + pickled = pickle.dumps(sentinel.whatever, proto) + unpickled = pickle.loads(pickled) + self.assertIs(unpickled, sentinel.whatever) + + def testCopy(self): + self.assertIs(copy.copy(sentinel.whatever), sentinel.whatever) + self.assertIs(copy.deepcopy(sentinel.whatever), sentinel.whatever) + if __name__ == '__main__': unittest.main() |