mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Added better pickling support to xrange objects.
Cleaned up the unit test.
This commit is contained in:
parent
1f2f61a78f
commit
602d8db2bc
2 changed files with 13 additions and 12 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
import test.test_support, unittest
|
||||
import sys
|
||||
import pickle
|
||||
|
||||
import warnings
|
||||
warnings.filterwarnings("ignore", "integer argument expected",
|
||||
|
@ -57,15 +58,15 @@ class XrangeTest(unittest.TestCase):
|
|||
self.assertEqual(len(r), sys.maxint)
|
||||
self.assertRaises(OverflowError, xrange, -sys.maxint-1, sys.maxint, 2)
|
||||
|
||||
def test_getnewargs(self):
|
||||
def test(*args):
|
||||
r = xrange(*args)
|
||||
return list(r) == list(xrange(*r.__getnewargs__()))
|
||||
tests = [(13,), (0, 11), (-22, 10), (20, 3, -1),
|
||||
(13, 21, 3), (-2, 2, 2)]
|
||||
for t in tests:
|
||||
self.assert_(test(*t),
|
||||
"xrange.__getnewargs__() failed with %r" % (t,))
|
||||
def test_pickling(self):
|
||||
testcases = [(13,), (0, 11), (-22, 10), (20, 3, -1),
|
||||
(13, 21, 3), (-2, 2, 2)]
|
||||
for proto in range(pickle.HIGHEST_PROTOCOL):
|
||||
for t in testcases:
|
||||
r = xrange(*t)
|
||||
self.assertEquals(list(pickle.loads(pickle.dumps(r, proto))),
|
||||
list(r))
|
||||
|
||||
|
||||
def test_main():
|
||||
test.test_support.run_unittest(XrangeTest)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue