aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_structseq.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_structseq.py')
-rw-r--r--Lib/test/test_structseq.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/Lib/test/test_structseq.py b/Lib/test/test_structseq.py
index daa12aa4c02..d6c63b792fe 100644
--- a/Lib/test/test_structseq.py
+++ b/Lib/test/test_structseq.py
@@ -1,29 +1,31 @@
+import os
+import time
import unittest
-from test import test_support
+from test import support
-import time
class StructSeqTest(unittest.TestCase):
def test_tuple(self):
t = time.gmtime()
+ self.assertIsInstance(t, tuple)
astuple = tuple(t)
self.assertEqual(len(t), len(astuple))
self.assertEqual(t, astuple)
# Check that slicing works the same way; at one point, slicing t[i:j] with
# 0 < i < j could produce NULLs in the result.
- for i in xrange(-len(t), len(t)):
+ for i in range(-len(t), len(t)):
self.assertEqual(t[i:], astuple[i:])
- for j in xrange(-len(t), len(t)):
+ for j in range(-len(t), len(t)):
self.assertEqual(t[i:j], astuple[i:j])
- for j in xrange(-len(t), len(t)):
+ for j in range(-len(t), len(t)):
self.assertEqual(t[:j], astuple[:j])
self.assertRaises(IndexError, t.__getitem__, -len(t)-1)
self.assertRaises(IndexError, t.__getitem__, len(t))
- for i in xrange(-len(t), len(t)-1):
+ for i in range(-len(t), len(t)-1):
self.assertEqual(t[i], astuple[i])
def test_repr(self):
@@ -33,17 +35,24 @@ class StructSeqTest(unittest.TestCase):
self.assertEqual(repr(t),
"time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, "
"tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)")
+ # os.stat() gives a complicated struct sequence.
+ st = os.stat(__file__)
+ rep = repr(st)
+ self.assertTrue(rep.startswith(os.name + ".stat_result"))
+ self.assertIn("st_mode=", rep)
+ self.assertIn("st_ino=", rep)
+ self.assertIn("st_dev=", rep)
def test_concat(self):
t1 = time.gmtime()
t2 = t1 + tuple(t1)
- for i in xrange(len(t1)):
+ for i in range(len(t1)):
self.assertEqual(t2[i], t2[i+len(t1)])
def test_repeat(self):
t1 = time.gmtime()
t2 = 3 * t1
- for i in xrange(len(t1)):
+ for i in range(len(t1)):
self.assertEqual(t2[i], t2[i+len(t1)])
self.assertEqual(t2[i], t2[i+2*len(t1)])
@@ -114,7 +123,7 @@ class StructSeqTest(unittest.TestCase):
L[start:stop:step])
def test_main():
- test_support.run_unittest(StructSeqTest)
+ support.run_unittest(StructSeqTest)
if __name__ == "__main__":
test_main()