Exceptions raised during renaming in rotating file handlers are now passed to handleE...
[python.git] / Lib / test / test_xrange.py
blob9f9daa7bf88ff8628c4bf80a7d156c724ade7d3c
1 # Python test set -- built-in functions
3 import test.test_support, unittest
4 import sys
6 import warnings
7 warnings.filterwarnings("ignore", "integer argument expected",
8 DeprecationWarning, "unittest")
10 class XrangeTest(unittest.TestCase):
11 def test_xrange(self):
12 self.assertEqual(list(xrange(3)), [0, 1, 2])
13 self.assertEqual(list(xrange(1, 5)), [1, 2, 3, 4])
14 self.assertEqual(list(xrange(0)), [])
15 self.assertEqual(list(xrange(-3)), [])
16 self.assertEqual(list(xrange(1, 10, 3)), [1, 4, 7])
17 self.assertEqual(list(xrange(5, -5, -3)), [5, 2, -1, -4])
19 a = 10
20 b = 100
21 c = 50
23 self.assertEqual(list(xrange(a, a+2)), [a, a+1])
24 self.assertEqual(list(xrange(a+2, a, -1L)), [a+2, a+1])
25 self.assertEqual(list(xrange(a+4, a, -2)), [a+4, a+2])
27 seq = list(xrange(a, b, c))
28 self.assert_(a in seq)
29 self.assert_(b not in seq)
30 self.assertEqual(len(seq), 2)
32 seq = list(xrange(b, a, -c))
33 self.assert_(b in seq)
34 self.assert_(a not in seq)
35 self.assertEqual(len(seq), 2)
37 seq = list(xrange(-a, -b, -c))
38 self.assert_(-a in seq)
39 self.assert_(-b not in seq)
40 self.assertEqual(len(seq), 2)
42 self.assertRaises(TypeError, xrange)
43 self.assertRaises(TypeError, xrange, 1, 2, 3, 4)
44 self.assertRaises(ValueError, xrange, 1, 2, 0)
46 self.assertRaises(OverflowError, xrange, 1e100, 1e101, 1e101)
48 self.assertRaises(TypeError, xrange, 0, "spam")
49 self.assertRaises(TypeError, xrange, 0, 42, "spam")
51 self.assertEqual(len(xrange(0, sys.maxint, sys.maxint-1)), 2)
53 self.assertRaises(OverflowError, xrange, -sys.maxint, sys.maxint)
54 self.assertRaises(OverflowError, xrange, 0, 2*sys.maxint)
56 r = xrange(-sys.maxint, sys.maxint, 2)
57 if sys.maxint > 0x7fffffff:
58 # XXX raising ValueError is less than ideal, but this can't
59 # be fixed until range_length() returns a long in rangeobject.c
60 self.assertRaises(ValueError, len, r)
61 else:
62 self.assertEqual(len(r), sys.maxint)
63 self.assertRaises(OverflowError, xrange, -sys.maxint-1, sys.maxint, 2)
65 def test_main():
66 test.test_support.run_unittest(XrangeTest)
68 if __name__ == "__main__":
69 test_main()