Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.datetimetester.TestTime Class Reference
Inheritance diagram for test.datetimetester.TestTime:
Inheritance graph
[legend]
Collaboration diagram for test.datetimetester.TestTime:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_basic_attributes
def test_basic_attributes_nonzero
def test_roundtrip
def test_comparing
def test_bad_constructor_arguments
def test_hash_equality
def test_isoformat
def test_1653736
def test_strftime
def test_format
def test_str
def test_repr
def test_resolution_info
def test_pickling
def test_pickling_subclass_time
def test_bool
def test_replace
def test_subclass_time
def test_backdoor_resistance
def test_harmless_mixed_comparison
def test_harmful_mixed_comparison

Static Public Attributes

 theclass = time

Detailed Description

Definition at line 1966 of file datetimetester.py.


Member Function Documentation

Definition at line 2122 of file datetimetester.py.

02122 
02123     def test_1653736(self):
02124         # verify it doesn't accept extra keyword arguments
02125         t = self.theclass(second=1)
02126         self.assertRaises(TypeError, t.isoformat, foo=3)

Here is the call graph for this function:

Definition at line 2259 of file datetimetester.py.

02259 
02260     def test_backdoor_resistance(self):
02261         # see TestDate.test_backdoor_resistance().
02262         base = '2:59.0'
02263         for hour_byte in ' ', '9', chr(24), '\xff':
02264             self.assertRaises(TypeError, self.theclass,
02265                                          hour_byte + base[1:])
02266 
02267 # A mixin for classes with a tzinfo= argument.  Subclasses must define
02268 # theclass as a class atribute, and theclass(1, 1, 1, tzinfo=whatever)
# must be legit (which is true for time and datetime).

Here is the call graph for this function:

Definition at line 2044 of file datetimetester.py.

02044 
02045     def test_bad_constructor_arguments(self):
02046         # bad hours
02047         self.theclass(0, 0)    # no exception
02048         self.theclass(23, 0)   # no exception
02049         self.assertRaises(ValueError, self.theclass, -1, 0)
02050         self.assertRaises(ValueError, self.theclass, 24, 0)
02051         # bad minutes
02052         self.theclass(23, 0)    # no exception
02053         self.theclass(23, 59)   # no exception
02054         self.assertRaises(ValueError, self.theclass, 23, -1)
02055         self.assertRaises(ValueError, self.theclass, 23, 60)
02056         # bad seconds
02057         self.theclass(23, 59, 0)    # no exception
02058         self.theclass(23, 59, 59)   # no exception
02059         self.assertRaises(ValueError, self.theclass, 23, 59, -1)
02060         self.assertRaises(ValueError, self.theclass, 23, 59, 60)
02061         # bad microseconds
02062         self.theclass(23, 59, 59, 0)        # no exception
02063         self.theclass(23, 59, 59, 999999)   # no exception
02064         self.assertRaises(ValueError, self.theclass, 23, 59, 59, -1)
02065         self.assertRaises(ValueError, self.theclass, 23, 59, 59, 1000000)

Here is the call graph for this function:

Definition at line 1970 of file datetimetester.py.

01970 
01971     def test_basic_attributes(self):
01972         t = self.theclass(12, 0)
01973         self.assertEqual(t.hour, 12)
01974         self.assertEqual(t.minute, 0)
01975         self.assertEqual(t.second, 0)
01976         self.assertEqual(t.microsecond, 0)

Here is the call graph for this function:

Definition at line 1977 of file datetimetester.py.

01977 
01978     def test_basic_attributes_nonzero(self):
01979         # Make sure all attributes are non-zero so bugs in
01980         # bit-shifting access show up.
01981         t = self.theclass(12, 59, 59, 8000)
01982         self.assertEqual(t.hour, 12)
01983         self.assertEqual(t.minute, 59)
01984         self.assertEqual(t.second, 59)
01985         self.assertEqual(t.microsecond, 8000)

Here is the call graph for this function:

Definition at line 2199 of file datetimetester.py.

02199 
02200     def test_bool(self):
02201         cls = self.theclass
02202         self.assertTrue(cls(1))
02203         self.assertTrue(cls(0, 1))
02204         self.assertTrue(cls(0, 0, 1))
02205         self.assertTrue(cls(0, 0, 0, 1))
02206         self.assertTrue(not cls(0))
02207         self.assertTrue(not cls())

Here is the call graph for this function:

Definition at line 2001 of file datetimetester.py.

02001 
02002     def test_comparing(self):
02003         args = [1, 2, 3, 4]
02004         t1 = self.theclass(*args)
02005         t2 = self.theclass(*args)
02006         self.assertEqual(t1, t2)
02007         self.assertTrue(t1 <= t2)
02008         self.assertTrue(t1 >= t2)
02009         self.assertTrue(not t1 != t2)
02010         self.assertTrue(not t1 < t2)
02011         self.assertTrue(not t1 > t2)
02012 
02013         for i in range(len(args)):
02014             newargs = args[:]
02015             newargs[i] = args[i] + 1
02016             t2 = self.theclass(*newargs)   # this is larger than t1
02017             self.assertTrue(t1 < t2)
02018             self.assertTrue(t2 > t1)
02019             self.assertTrue(t1 <= t2)
02020             self.assertTrue(t2 >= t1)
02021             self.assertTrue(t1 != t2)
02022             self.assertTrue(t2 != t1)
02023             self.assertTrue(not t1 == t2)
02024             self.assertTrue(not t2 == t1)
02025             self.assertTrue(not t1 > t2)
02026             self.assertTrue(not t2 < t1)
02027             self.assertTrue(not t1 >= t2)
02028             self.assertTrue(not t2 <= t1)
02029 
02030         for badarg in OTHERSTUFF:
02031             self.assertEqual(t1 == badarg, False)
02032             self.assertEqual(t1 != badarg, True)
02033             self.assertEqual(badarg == t1, False)
02034             self.assertEqual(badarg != t1, True)
02035 
02036             self.assertRaises(TypeError, lambda: t1 <= badarg)
02037             self.assertRaises(TypeError, lambda: t1 < badarg)
02038             self.assertRaises(TypeError, lambda: t1 > badarg)
02039             self.assertRaises(TypeError, lambda: t1 >= badarg)
02040             self.assertRaises(TypeError, lambda: badarg <= t1)
02041             self.assertRaises(TypeError, lambda: badarg < t1)
02042             self.assertRaises(TypeError, lambda: badarg > t1)
02043             self.assertRaises(TypeError, lambda: badarg >= t1)

Here is the call graph for this function:

Definition at line 2133 of file datetimetester.py.

02133 
02134     def test_format(self):
02135         t = self.theclass(1, 2, 3, 4)
02136         self.assertEqual(t.__format__(''), str(t))
02137 
02138         # check that a derived class's __str__() gets called
02139         class A(self.theclass):
02140             def __str__(self):
02141                 return 'A'
02142         a = A(1, 2, 3, 4)
02143         self.assertEqual(a.__format__(''), 'A')
02144 
02145         # check that a derived class's strftime gets called
02146         class B(self.theclass):
02147             def strftime(self, format_spec):
02148                 return 'B'
02149         b = B(1, 2, 3, 4)
02150         self.assertEqual(b.__format__(''), str(t))
02151 
02152         for fmt in ['%H %M %S',
02153                     ]:
02154             self.assertEqual(t.__format__(fmt), t.strftime(fmt))
02155             self.assertEqual(a.__format__(fmt), t.strftime(fmt))
02156             self.assertEqual(b.__format__(fmt), 'B')

Here is the call graph for this function:

Definition at line 271 of file datetimetester.py.

00271 
00272     def test_harmful_mixed_comparison(self):
00273         me = self.theclass(1, 1, 1)
00274 
00275         self.assertRaises(TypeError, lambda: me < ())
00276         self.assertRaises(TypeError, lambda: me <= ())
00277         self.assertRaises(TypeError, lambda: me > ())
00278         self.assertRaises(TypeError, lambda: me >= ())
00279 
00280         self.assertRaises(TypeError, lambda: () < me)
00281         self.assertRaises(TypeError, lambda: () <= me)
00282         self.assertRaises(TypeError, lambda: () > me)
00283         self.assertRaises(TypeError, lambda: () >= me)

Here is the call graph for this function:

Definition at line 260 of file datetimetester.py.

00260 
00261     def test_harmless_mixed_comparison(self):
00262         me = self.theclass(1, 1, 1)
00263 
00264         self.assertFalse(me == ())
00265         self.assertTrue(me != ())
00266         self.assertFalse(() == me)
00267         self.assertTrue(() != me)
00268 
00269         self.assertIn(me, [1, 20, [], me])
00270         self.assertIn([], [me, 1, 20, []])

Here is the call graph for this function:

Definition at line 2066 of file datetimetester.py.

02066 
02067     def test_hash_equality(self):
02068         d = self.theclass(23, 30, 17)
02069         e = self.theclass(23, 30, 17)
02070         self.assertEqual(d, e)
02071         self.assertEqual(hash(d), hash(e))
02072 
02073         dic = {d: 1}
02074         dic[e] = 2
02075         self.assertEqual(len(dic), 1)
02076         self.assertEqual(dic[d], 2)
02077         self.assertEqual(dic[e], 2)
02078 
02079         d = self.theclass(0,  5, 17)
02080         e = self.theclass(0,  5, 17)
02081         self.assertEqual(d, e)
02082         self.assertEqual(hash(d), hash(e))
02083 
02084         dic = {d: 1}
02085         dic[e] = 2
02086         self.assertEqual(len(dic), 1)
02087         self.assertEqual(dic[d], 2)
02088         self.assertEqual(dic[e], 2)

Here is the call graph for this function:

Definition at line 2089 of file datetimetester.py.

02089 
02090     def test_isoformat(self):
02091         t = self.theclass(4, 5, 1, 123)
02092         self.assertEqual(t.isoformat(), "04:05:01.000123")
02093         self.assertEqual(t.isoformat(), str(t))
02094 
02095         t = self.theclass()
02096         self.assertEqual(t.isoformat(), "00:00:00")
02097         self.assertEqual(t.isoformat(), str(t))
02098 
02099         t = self.theclass(microsecond=1)
02100         self.assertEqual(t.isoformat(), "00:00:00.000001")
02101         self.assertEqual(t.isoformat(), str(t))
02102 
02103         t = self.theclass(microsecond=10)
02104         self.assertEqual(t.isoformat(), "00:00:00.000010")
02105         self.assertEqual(t.isoformat(), str(t))
02106 
02107         t = self.theclass(microsecond=100)
02108         self.assertEqual(t.isoformat(), "00:00:00.000100")
02109         self.assertEqual(t.isoformat(), str(t))
02110 
02111         t = self.theclass(microsecond=1000)
02112         self.assertEqual(t.isoformat(), "00:00:00.001000")
02113         self.assertEqual(t.isoformat(), str(t))
02114 
02115         t = self.theclass(microsecond=10000)
02116         self.assertEqual(t.isoformat(), "00:00:00.010000")
02117         self.assertEqual(t.isoformat(), str(t))
02118 
02119         t = self.theclass(microsecond=100000)
02120         self.assertEqual(t.isoformat(), "00:00:00.100000")
02121         self.assertEqual(t.isoformat(), str(t))

Here is the call graph for this function:

Reimplemented in test.datetimetester.TestTimeTZ.

Definition at line 2183 of file datetimetester.py.

02183 
02184     def test_pickling(self):
02185         args = 20, 59, 16, 64**2
02186         orig = self.theclass(*args)
02187         for pickler, unpickler, proto in pickle_choices:
02188             green = pickler.dumps(orig, proto)
02189             derived = unpickler.loads(green)
02190             self.assertEqual(orig, derived)

Here is the call graph for this function:

Definition at line 2191 of file datetimetester.py.

02191 
02192     def test_pickling_subclass_time(self):
02193         args = 20, 59, 16, 64**2
02194         orig = SubclassTime(*args)
02195         for pickler, unpickler, proto in pickle_choices:
02196             green = pickler.dumps(orig, proto)
02197             derived = unpickler.loads(green)
02198             self.assertEqual(orig, derived)

Here is the call graph for this function:

Reimplemented in test.datetimetester.TestTimeTZ.

Definition at line 2208 of file datetimetester.py.

02208 
02209     def test_replace(self):
02210         cls = self.theclass
02211         args = [1, 2, 3, 4]
02212         base = cls(*args)
02213         self.assertEqual(base, base.replace())
02214 
02215         i = 0
02216         for name, newval in (("hour", 5),
02217                              ("minute", 6),
02218                              ("second", 7),
02219                              ("microsecond", 8)):
02220             newargs = args[:]
02221             newargs[i] = newval
02222             expected = cls(*newargs)
02223             got = base.replace(**{name: newval})
02224             self.assertEqual(expected, got)
02225             i += 1
02226 
02227         # Out of bounds.
02228         base = cls(1)
02229         self.assertRaises(ValueError, base.replace, hour=24)
02230         self.assertRaises(ValueError, base.replace, minute=-1)
02231         self.assertRaises(ValueError, base.replace, second=100)
02232         self.assertRaises(ValueError, base.replace, microsecond=1000000)

Here is the call graph for this function:

Definition at line 2164 of file datetimetester.py.

02164 
02165     def test_repr(self):
02166         name = 'datetime.' + self.theclass.__name__
02167         self.assertEqual(repr(self.theclass(1, 2, 3, 4)),
02168                          "%s(1, 2, 3, 4)" % name)
02169         self.assertEqual(repr(self.theclass(10, 2, 3, 4000)),
02170                          "%s(10, 2, 3, 4000)" % name)
02171         self.assertEqual(repr(self.theclass(0, 2, 3, 400000)),
02172                          "%s(0, 2, 3, 400000)" % name)
02173         self.assertEqual(repr(self.theclass(12, 2, 3, 0)),
02174                          "%s(12, 2, 3)" % name)
02175         self.assertEqual(repr(self.theclass(23, 15, 0, 0)),
02176                          "%s(23, 15)" % name)

Here is the call graph for this function:

Definition at line 2177 of file datetimetester.py.

02177 
02178     def test_resolution_info(self):
02179         self.assertIsInstance(self.theclass.min, self.theclass)
02180         self.assertIsInstance(self.theclass.max, self.theclass)
02181         self.assertIsInstance(self.theclass.resolution, timedelta)
02182         self.assertTrue(self.theclass.max > self.theclass.min)

Here is the call graph for this function:

Definition at line 1986 of file datetimetester.py.

01986 
01987     def test_roundtrip(self):
01988         t = self.theclass(1, 2, 3, 4)
01989 
01990         # Verify t -> string -> time identity.
01991         s = repr(t)
01992         self.assertTrue(s.startswith('datetime.'))
01993         s = s[9:]
01994         t2 = eval(s)
01995         self.assertEqual(t, t2)
01996 
01997         # Verify identity via reconstructing from pieces.
01998         t2 = self.theclass(t.hour, t.minute, t.second,
01999                            t.microsecond)
02000         self.assertEqual(t, t2)

Here is the call graph for this function:

Definition at line 2157 of file datetimetester.py.

02157 
02158     def test_str(self):
02159         self.assertEqual(str(self.theclass(1, 2, 3, 4)), "01:02:03.000004")
02160         self.assertEqual(str(self.theclass(10, 2, 3, 4000)), "10:02:03.004000")
02161         self.assertEqual(str(self.theclass(0, 2, 3, 400000)), "00:02:03.400000")
02162         self.assertEqual(str(self.theclass(12, 2, 3, 0)), "12:02:03")
02163         self.assertEqual(str(self.theclass(23, 15, 0, 0)), "23:15:00")

Here is the call graph for this function:

Definition at line 2127 of file datetimetester.py.

02127 
02128     def test_strftime(self):
02129         t = self.theclass(1, 2, 3, 4)
02130         self.assertEqual(t.strftime('%H %M %S %f'), "01 02 03 000004")
02131         # A naive object replaces %z and %Z with empty strings.
02132         self.assertEqual(t.strftime("'%z' '%Z'"), "'' ''")

Here is the call graph for this function:

Definition at line 2233 of file datetimetester.py.

02233 
02234     def test_subclass_time(self):
02235 
02236         class C(self.theclass):
02237             theAnswer = 42
02238 
02239             def __new__(cls, *args, **kws):
02240                 temp = kws.copy()
02241                 extra = temp.pop('extra')
02242                 result = self.theclass.__new__(cls, *args, **temp)
02243                 result.extra = extra
02244                 return result
02245 
02246             def newmeth(self, start):
02247                 return start + self.hour + self.second
02248 
02249         args = 4, 5, 6
02250 
02251         dt1 = self.theclass(*args)
02252         dt2 = C(*args, **{'extra': 7})
02253 
02254         self.assertEqual(dt2.__class__, C)
02255         self.assertEqual(dt2.theAnswer, 42)
02256         self.assertEqual(dt2.extra, 7)
02257         self.assertEqual(dt1.isoformat(), dt2.isoformat())
02258         self.assertEqual(dt2.newmeth(-7), dt1.hour + dt1.second - 7)

Here is the call graph for this function:


Member Data Documentation

Reimplemented in test.datetimetester.TestTimeTZ.

Definition at line 1968 of file datetimetester.py.


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