]> granicus.if.org Git - python/commitdiff
Test re pickling for all protocols.
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 15 Sep 2014 08:35:06 +0000 (11:35 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 15 Sep 2014 08:35:06 +0000 (11:35 +0300)
Lib/test/test_re.py

index f285c6bed2ca0032855d3b0ff171effb1a520c15..88eafc99a599fe8c0ec1199e38f88bac9ecc7c50 100644 (file)
@@ -560,12 +560,15 @@ class ReTests(unittest.TestCase):
         # old pickles expect the _compile() reconstructor in sre module
         import_module("sre", deprecated=True)
         from sre import _compile
+        # current pickle expects the _compile() reconstructor in re module
+        from re import _compile
 
     def pickle_test(self, pickle):
         oldpat = re.compile('a(?:b|(c|e){1,2}?|d)+?(.)')
-        s = pickle.dumps(oldpat)
-        newpat = pickle.loads(s)
-        self.assertEqual(oldpat, newpat)
+        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+            pickled = pickle.dumps(oldpat, proto)
+            newpat = pickle.loads(pickled)
+            self.assertEqual(newpat, oldpat)
 
     def test_constants(self):
         self.assertEqual(re.I, re.IGNORECASE)