Back to index

python3.2  3.2.2
Public Member Functions
test.test_structseq.StructSeqTest Class Reference

List of all members.

Public Member Functions

def test_tuple
def test_repr
def test_concat
def test_repeat
def test_contains
def test_hash
def test_cmp
def test_fields
def test_constructor
def test_eviltuple
def test_reduce
def test_extended_getslice

Detailed Description

Definition at line 7 of file test_structseq.py.


Member Function Documentation

Definition at line 69 of file test_structseq.py.

00069 
00070     def test_cmp(self):
00071         t1 = time.gmtime()
00072         t2 = type(t1)(t1)
00073         self.assertEqual(t1, t2)
00074         self.assertTrue(not (t1 < t2))
00075         self.assertTrue(t1 <= t2)
00076         self.assertTrue(not (t1 > t2))
00077         self.assertTrue(t1 >= t2)
00078         self.assertTrue(not (t1 != t2))

Here is the call graph for this function:

Definition at line 46 of file test_structseq.py.

00046 
00047     def test_concat(self):
00048         t1 = time.gmtime()
00049         t2 = t1 + tuple(t1)
00050         for i in range(len(t1)):
00051             self.assertEqual(t2[i], t2[i+len(t1)])

Here is the call graph for this function:

Definition at line 84 of file test_structseq.py.

00084 
00085     def test_constructor(self):
00086         t = time.struct_time
00087 
00088         self.assertRaises(TypeError, t)
00089         self.assertRaises(TypeError, t, None)
00090         self.assertRaises(TypeError, t, "123")
00091         self.assertRaises(TypeError, t, "123", dict={})
00092         self.assertRaises(TypeError, t, "123456789", dict=None)
00093 
00094         s = "123456789"
00095         self.assertEqual("".join(t(s)), s)

Here is the call graph for this function:

Definition at line 59 of file test_structseq.py.

00059 
00060     def test_contains(self):
00061         t1 = time.gmtime()
00062         for item in t1:
00063             self.assertIn(item, t1)
00064         self.assertNotIn(-42, t1)

Here is the call graph for this function:

Definition at line 96 of file test_structseq.py.

00096 
00097     def test_eviltuple(self):
00098         class Exc(Exception):
00099             pass
00100 
00101         # Devious code could crash structseqs' contructors
00102         class C:
00103             def __getitem__(self, i):
00104                 raise Exc
00105             def __len__(self):
00106                 return 9
00107 
00108         self.assertRaises(Exc, time.struct_time, C())

Definition at line 113 of file test_structseq.py.

00113 
00114     def test_extended_getslice(self):
00115         # Test extended slicing by comparing with list slicing.
00116         t = time.gmtime()
00117         L = list(t)
00118         indices = (0, None, 1, 3, 19, 300, -1, -2, -31, -300)
00119         for start in indices:
00120             for stop in indices:
00121                 # Skip step 0 (invalid)
00122                 for step in indices[1:]:
00123                     self.assertEqual(list(t[start:stop:step]),
00124                                      L[start:stop:step])

Here is the call graph for this function:

Definition at line 79 of file test_structseq.py.

00079 
00080     def test_fields(self):
00081         t = time.gmtime()
00082         self.assertEqual(len(t), t.n_fields)
00083         self.assertEqual(t.n_fields, t.n_sequence_fields+t.n_unnamed_fields)

Here is the call graph for this function:

Definition at line 65 of file test_structseq.py.

00065 
00066     def test_hash(self):
00067         t1 = time.gmtime()
00068         self.assertEqual(hash(t1), hash(tuple(t1)))

Here is the call graph for this function:

Definition at line 109 of file test_structseq.py.

00109 
00110     def test_reduce(self):
00111         t = time.gmtime()
00112         x = t.__reduce__()

Definition at line 52 of file test_structseq.py.

00052 
00053     def test_repeat(self):
00054         t1 = time.gmtime()
00055         t2 = 3 * t1
00056         for i in range(len(t1)):
00057             self.assertEqual(t2[i], t2[i+len(t1)])
00058             self.assertEqual(t2[i], t2[i+2*len(t1)])

Here is the call graph for this function:

Definition at line 31 of file test_structseq.py.

00031 
00032     def test_repr(self):
00033         t = time.gmtime()
00034         self.assertTrue(repr(t))
00035         t = time.gmtime(0)
00036         self.assertEqual(repr(t),
00037             "time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, "
00038             "tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)")
00039         # os.stat() gives a complicated struct sequence.
00040         st = os.stat(__file__)
00041         rep = repr(st)
00042         self.assertTrue(rep.startswith(os.name + ".stat_result"))
00043         self.assertIn("st_mode=", rep)
00044         self.assertIn("st_ino=", rep)
00045         self.assertIn("st_dev=", rep)

Here is the call graph for this function:

Definition at line 9 of file test_structseq.py.

00009 
00010     def test_tuple(self):
00011         t = time.gmtime()
00012         self.assertIsInstance(t, tuple)
00013         astuple = tuple(t)
00014         self.assertEqual(len(t), len(astuple))
00015         self.assertEqual(t, astuple)
00016 
00017         # Check that slicing works the same way; at one point, slicing t[i:j] with
00018         # 0 < i < j could produce NULLs in the result.
00019         for i in range(-len(t), len(t)):
00020             self.assertEqual(t[i:], astuple[i:])
00021             for j in range(-len(t), len(t)):
00022                 self.assertEqual(t[i:j], astuple[i:j])
00023 
00024         for j in range(-len(t), len(t)):
00025             self.assertEqual(t[:j], astuple[:j])
00026 
00027         self.assertRaises(IndexError, t.__getitem__, -len(t)-1)
00028         self.assertRaises(IndexError, t.__getitem__, len(t))
00029         for i in range(-len(t), len(t)-1):
00030             self.assertEqual(t[i], astuple[i])

Here is the call graph for this function:


The documentation for this class was generated from the following file: