summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Bishop <stuart.bishop@canonical.com>2019-07-31 15:15:17 +0000
committerStuart Bishop <stuart.bishop@canonical.com>2019-07-31 15:21:05 +0000
commitf417f5398e4df1ef79c6c3835368f72b39a08af7 (patch)
tree5fcb6535448ee3784a6fc438d081b0c1ed0ab584
parent0537ddc6a7724f10b59c78c9ca8c7ac7b9bc11af (diff)
downloadpytz-git-f417f5398e4df1ef79c6c3835368f72b39a08af7.tar.gz
Use explicit pickle protocol versions in tests
Addresses lp:1819751 using fix by Victor Stinner
-rw-r--r--src/pytz/tests/test_tzinfo.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/pytz/tests/test_tzinfo.py b/src/pytz/tests/test_tzinfo.py
index e56fef5..85aae12 100644
--- a/src/pytz/tests/test_tzinfo.py
+++ b/src/pytz/tests/test_tzinfo.py
@@ -183,8 +183,14 @@ class PicklingTest(unittest.TestCase):
# Python 3 introduced a new pickle protocol where numbers are stored in
# hexadecimal representation. Here we extract the pickle
# representation of the number for the current Python version.
- old_pickle_pattern = pickle.dumps(tz._utcoffset.seconds)[3:-1]
- new_pickle_pattern = pickle.dumps(new_utcoffset)[3:-1]
+ #
+ # Test protocol 3 on Python 3 and protocol 0 on Python 2.
+ if sys.version_info >= (3,):
+ protocol = 3
+ else:
+ protocol = 0
+ old_pickle_pattern = pickle.dumps(tz._utcoffset.seconds, protocol)[3:-1]
+ new_pickle_pattern = pickle.dumps(new_utcoffset, protocol)[3:-1]
hacked_p = p.replace(old_pickle_pattern, new_pickle_pattern)
self.assertNotEqual(p, hacked_p)