Back to index

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

List of all members.

Public Member Functions

def test_roundtrip
def test_basic_attributes
def test_basic_attributes_nonzero
def test_isoformat
def test_format
def test_more_ctime
def test_tz_independent_comparing
def test_strftime_with_bad_tzname_replace
def test_bad_constructor_arguments
def test_hash_equality
def test_computations
def test_pickling
def test_more_pickling
def test_pickling_subclass_datetime
def test_more_compare
def verify_field_equality
def test_fromtimestamp
def test_utcfromtimestamp
def test_microsecond_rounding
def test_insane_fromtimestamp
def test_insane_utcfromtimestamp
def test_negative_float_fromtimestamp
def test_negative_float_utcfromtimestamp
def test_utcnow
def test_strptime
def test_more_timetuple
def test_more_strftime
def test_extract
def test_combine
def test_replace
def test_astimezone
def test_subclass_datetime
def test_ordinal_conversions
def test_extreme_ordinals
def test_overflow
def test_today
def test_weekday
def test_isocalendar
def test_iso_long_years
def test_ctime
def test_strftime
def test_resolution_info
def test_extreme_timedelta
def test_timetuple
def test_compare
def test_mixed_compare
def test_bool
def test_strftime_out_of_range
def test_subclass_date
def test_pickling_subclass_date
def test_backdoor_resistance
def test_harmless_mixed_comparison
def test_harmful_mixed_comparison

Static Public Attributes

 theclass = SubclassDatetime

Detailed Description

Definition at line 1957 of file datetimetester.py.


Member Function Documentation

Definition at line 1905 of file datetimetester.py.

01905 
01906     def test_astimezone(self):
01907         # Pretty boring!  The TZ test is more interesting here.  astimezone()
01908         # simply can't be applied to a naive object.
01909         dt = self.theclass.now()
01910         f = FixedOffset(44, "")
01911         self.assertRaises(TypeError, dt.astimezone) # not enough args
01912         self.assertRaises(TypeError, dt.astimezone, f, f) # too many args
01913         self.assertRaises(TypeError, dt.astimezone, dt) # arg wrong type
01914         self.assertRaises(ValueError, dt.astimezone, f) # naive
01915         self.assertRaises(ValueError, dt.astimezone, tz=f)  # naive
01916 
01917         class Bogus(tzinfo):
01918             def utcoffset(self, dt): return None
01919             def dst(self, dt): return timedelta(0)
01920         bog = Bogus()
01921         self.assertRaises(ValueError, dt.astimezone, bog)   # naive
01922         self.assertRaises(ValueError,
01923                           dt.replace(tzinfo=bog).astimezone, f)
01924 
01925         class AlsoBogus(tzinfo):
01926             def utcoffset(self, dt): return timedelta(0)
01927             def dst(self, dt): return None
01928         alsobog = AlsoBogus()
01929         self.assertRaises(ValueError, dt.astimezone, alsobog) # also naive

Here is the call graph for this function:

Definition at line 1355 of file datetimetester.py.

01355 
01356     def test_backdoor_resistance(self):
01357         # For fast unpickling, the constructor accepts a pickle byte string.
01358         # This is a low-overhead backdoor.  A user can (by intent or
01359         # mistake) pass a string directly, which (if it's the right length)
01360         # will get treated like a pickle, and bypass the normal sanity
01361         # checks in the constructor.  This can create insane objects.
01362         # The constructor doesn't want to burn the time to validate all
01363         # fields, but does check the month field.  This stops, e.g.,
01364         # datetime.datetime('1995-03-25') from yielding an insane object.
01365         base = b'1995-03-25'
01366         if not issubclass(self.theclass, datetime):
01367             base = base[:4]
01368         for month_byte in b'9', b'\0', b'\r', b'\xff':
01369             self.assertRaises(TypeError, self.theclass,
01370                                          base[:2] + month_byte + base[3:])
01371         # Good bytes, but bad tzinfo:
01372         self.assertRaises(TypeError, self.theclass,
01373                           bytes([1] * len(base)), 'EST')
01374 
01375         for ord_byte in range(1, 13):
01376             # This shouldn't blow up because of the month byte alone.  If
01377             # the implementation changes to do more-careful checking, it may
01378             # blow up because other fields are insane.
01379             self.theclass(base[:2] + bytes([ord_byte]) + base[3:])

Here is the call graph for this function:

Reimplemented from test.datetimetester.TestDate.

Definition at line 1515 of file datetimetester.py.

01515 
01516     def test_bad_constructor_arguments(self):
01517         # bad years
01518         self.theclass(MINYEAR, 1, 1)  # no exception
01519         self.theclass(MAXYEAR, 1, 1)  # no exception
01520         self.assertRaises(ValueError, self.theclass, MINYEAR-1, 1, 1)
01521         self.assertRaises(ValueError, self.theclass, MAXYEAR+1, 1, 1)
01522         # bad months
01523         self.theclass(2000, 1, 1)    # no exception
01524         self.theclass(2000, 12, 1)   # no exception
01525         self.assertRaises(ValueError, self.theclass, 2000, 0, 1)
01526         self.assertRaises(ValueError, self.theclass, 2000, 13, 1)
01527         # bad days
01528         self.theclass(2000, 2, 29)   # no exception
01529         self.theclass(2004, 2, 29)   # no exception
01530         self.theclass(2400, 2, 29)   # no exception
01531         self.assertRaises(ValueError, self.theclass, 2000, 2, 30)
01532         self.assertRaises(ValueError, self.theclass, 2001, 2, 29)
01533         self.assertRaises(ValueError, self.theclass, 2100, 2, 29)
01534         self.assertRaises(ValueError, self.theclass, 1900, 2, 29)
01535         self.assertRaises(ValueError, self.theclass, 2000, 1, 0)
01536         self.assertRaises(ValueError, self.theclass, 2000, 1, 32)
01537         # bad hours
01538         self.theclass(2000, 1, 31, 0)    # no exception
01539         self.theclass(2000, 1, 31, 23)   # no exception
01540         self.assertRaises(ValueError, self.theclass, 2000, 1, 31, -1)
01541         self.assertRaises(ValueError, self.theclass, 2000, 1, 31, 24)
01542         # bad minutes
01543         self.theclass(2000, 1, 31, 23, 0)    # no exception
01544         self.theclass(2000, 1, 31, 23, 59)   # no exception
01545         self.assertRaises(ValueError, self.theclass, 2000, 1, 31, 23, -1)
01546         self.assertRaises(ValueError, self.theclass, 2000, 1, 31, 23, 60)
01547         # bad seconds
01548         self.theclass(2000, 1, 31, 23, 59, 0)    # no exception
01549         self.theclass(2000, 1, 31, 23, 59, 59)   # no exception
01550         self.assertRaises(ValueError, self.theclass, 2000, 1, 31, 23, 59, -1)
01551         self.assertRaises(ValueError, self.theclass, 2000, 1, 31, 23, 59, 60)
01552         # bad microseconds
01553         self.theclass(2000, 1, 31, 23, 59, 59, 0)    # no exception
01554         self.theclass(2000, 1, 31, 23, 59, 59, 999999)   # no exception
01555         self.assertRaises(ValueError, self.theclass,
01556                           2000, 1, 31, 23, 59, 59, -1)
01557         self.assertRaises(ValueError, self.theclass,
01558                           2000, 1, 31, 23, 59, 59,
01559                           1000000)

Here is the call graph for this function:

Reimplemented from test.datetimetester.TestDate.

Definition at line 1390 of file datetimetester.py.

01390 
01391     def test_basic_attributes(self):
01392         dt = self.theclass(2002, 3, 1, 12, 0)
01393         self.assertEqual(dt.year, 2002)
01394         self.assertEqual(dt.month, 3)
01395         self.assertEqual(dt.day, 1)
01396         self.assertEqual(dt.hour, 12)
01397         self.assertEqual(dt.minute, 0)
01398         self.assertEqual(dt.second, 0)
01399         self.assertEqual(dt.microsecond, 0)

Here is the call graph for this function:

Definition at line 1400 of file datetimetester.py.

01400 
01401     def test_basic_attributes_nonzero(self):
01402         # Make sure all attributes are non-zero so bugs in
01403         # bit-shifting access show up.
01404         dt = self.theclass(2002, 3, 1, 12, 59, 59, 8000)
01405         self.assertEqual(dt.year, 2002)
01406         self.assertEqual(dt.month, 3)
01407         self.assertEqual(dt.day, 1)
01408         self.assertEqual(dt.hour, 12)
01409         self.assertEqual(dt.minute, 59)
01410         self.assertEqual(dt.second, 59)
01411         self.assertEqual(dt.microsecond, 8000)

Here is the call graph for this function:

def test.datetimetester.TestDate.test_bool (   self) [inherited]

Definition at line 1287 of file datetimetester.py.

01287 
01288     def test_bool(self):
01289         # All dates are considered true.
01290         self.assertTrue(self.theclass.min)
01291         self.assertTrue(self.theclass.max)

Here is the call graph for this function:

Reimplemented in test.datetimetester.TestDateTimeTZ.

Definition at line 1857 of file datetimetester.py.

01857 
01858     def test_combine(self):
01859         d = date(2002, 3, 4)
01860         t = time(18, 45, 3, 1234)
01861         expected = self.theclass(2002, 3, 4, 18, 45, 3, 1234)
01862         combine = self.theclass.combine
01863         dt = combine(d, t)
01864         self.assertEqual(dt, expected)
01865 
01866         dt = combine(time=t, date=d)
01867         self.assertEqual(dt, expected)
01868 
01869         self.assertEqual(d, dt.date())
01870         self.assertEqual(t, dt.time())
01871         self.assertEqual(dt, combine(dt.date(), dt.time()))
01872 
01873         self.assertRaises(TypeError, combine) # need an arg
01874         self.assertRaises(TypeError, combine, d) # need two args
01875         self.assertRaises(TypeError, combine, t, d) # args reversed
01876         self.assertRaises(TypeError, combine, d, t, 1) # too many args
01877         self.assertRaises(TypeError, combine, "date", "time") # wrong types
01878         self.assertRaises(TypeError, combine, d, "time") # wrong type
01879         self.assertRaises(TypeError, combine, "date", t) # wrong type

Here is the call graph for this function:

def test.datetimetester.TestDate.test_compare (   self) [inherited]

Definition at line 1197 of file datetimetester.py.

01197 
01198     def test_compare(self):
01199         t1 = self.theclass(2, 3, 4)
01200         t2 = self.theclass(2, 3, 4)
01201         self.assertEqual(t1, t2)
01202         self.assertTrue(t1 <= t2)
01203         self.assertTrue(t1 >= t2)
01204         self.assertTrue(not t1 != t2)
01205         self.assertTrue(not t1 < t2)
01206         self.assertTrue(not t1 > t2)
01207 
01208         for args in (3, 3, 3), (2, 4, 4), (2, 3, 5):
01209             t2 = self.theclass(*args)   # this is larger than t1
01210             self.assertTrue(t1 < t2)
01211             self.assertTrue(t2 > t1)
01212             self.assertTrue(t1 <= t2)
01213             self.assertTrue(t2 >= t1)
01214             self.assertTrue(t1 != t2)
01215             self.assertTrue(t2 != t1)
01216             self.assertTrue(not t1 == t2)
01217             self.assertTrue(not t2 == t1)
01218             self.assertTrue(not t1 > t2)
01219             self.assertTrue(not t2 < t1)
01220             self.assertTrue(not t1 >= t2)
01221             self.assertTrue(not t2 <= t1)
01222 
01223         for badarg in OTHERSTUFF:
01224             self.assertEqual(t1 == badarg, False)
01225             self.assertEqual(t1 != badarg, True)
01226             self.assertEqual(badarg == t1, False)
01227             self.assertEqual(badarg != t1, True)
01228 
01229             self.assertRaises(TypeError, lambda: t1 < badarg)
01230             self.assertRaises(TypeError, lambda: t1 > badarg)
01231             self.assertRaises(TypeError, lambda: t1 >= badarg)
01232             self.assertRaises(TypeError, lambda: badarg <= t1)
01233             self.assertRaises(TypeError, lambda: badarg < t1)
01234             self.assertRaises(TypeError, lambda: badarg > t1)
01235             self.assertRaises(TypeError, lambda: badarg >= t1)

Here is the call graph for this function:

Reimplemented from test.datetimetester.TestDate.

Definition at line 1583 of file datetimetester.py.

01583 
01584     def test_computations(self):
01585         a = self.theclass(2002, 1, 31)
01586         b = self.theclass(1956, 1, 31)
01587         diff = a-b
01588         self.assertEqual(diff.days, 46*365 + len(range(1956, 2002, 4)))
01589         self.assertEqual(diff.seconds, 0)
01590         self.assertEqual(diff.microseconds, 0)
01591         a = self.theclass(2002, 3, 2, 17, 6)
01592         millisec = timedelta(0, 0, 1000)
01593         hour = timedelta(0, 3600)
01594         day = timedelta(1)
01595         week = timedelta(7)
01596         self.assertEqual(a + hour, self.theclass(2002, 3, 2, 18, 6))
01597         self.assertEqual(hour + a, self.theclass(2002, 3, 2, 18, 6))
01598         self.assertEqual(a + 10*hour, self.theclass(2002, 3, 3, 3, 6))
01599         self.assertEqual(a - hour, self.theclass(2002, 3, 2, 16, 6))
01600         self.assertEqual(-hour + a, self.theclass(2002, 3, 2, 16, 6))
01601         self.assertEqual(a - hour, a + -hour)
01602         self.assertEqual(a - 20*hour, self.theclass(2002, 3, 1, 21, 6))
01603         self.assertEqual(a + day, self.theclass(2002, 3, 3, 17, 6))
01604         self.assertEqual(a - day, self.theclass(2002, 3, 1, 17, 6))
01605         self.assertEqual(a + week, self.theclass(2002, 3, 9, 17, 6))
01606         self.assertEqual(a - week, self.theclass(2002, 2, 23, 17, 6))
01607         self.assertEqual(a + 52*week, self.theclass(2003, 3, 1, 17, 6))
01608         self.assertEqual(a - 52*week, self.theclass(2001, 3, 3, 17, 6))
01609         self.assertEqual((a + week) - a, week)
01610         self.assertEqual((a + day) - a, day)
01611         self.assertEqual((a + hour) - a, hour)
01612         self.assertEqual((a + millisec) - a, millisec)
01613         self.assertEqual((a - week) - a, -week)
01614         self.assertEqual((a - day) - a, -day)
01615         self.assertEqual((a - hour) - a, -hour)
01616         self.assertEqual((a - millisec) - a, -millisec)
01617         self.assertEqual(a - (a + week), -week)
01618         self.assertEqual(a - (a + day), -day)
01619         self.assertEqual(a - (a + hour), -hour)
01620         self.assertEqual(a - (a + millisec), -millisec)
01621         self.assertEqual(a - (a - week), week)
01622         self.assertEqual(a - (a - day), day)
01623         self.assertEqual(a - (a - hour), hour)
01624         self.assertEqual(a - (a - millisec), millisec)
01625         self.assertEqual(a + (week + day + hour + millisec),
01626                          self.theclass(2002, 3, 10, 18, 6, 0, 1000))
01627         self.assertEqual(a + (week + day + hour + millisec),
01628                          (((a + week) + day) + hour) + millisec)
01629         self.assertEqual(a - (week + day + hour + millisec),
01630                          self.theclass(2002, 2, 22, 16, 5, 59, 999000))
01631         self.assertEqual(a - (week + day + hour + millisec),
01632                          (((a - week) - day) - hour) - millisec)
01633         # Add/sub ints or floats should be illegal
01634         for i in 1, 1.0:
01635             self.assertRaises(TypeError, lambda: a+i)
01636             self.assertRaises(TypeError, lambda: a-i)
01637             self.assertRaises(TypeError, lambda: i+a)
01638             self.assertRaises(TypeError, lambda: i-a)
01639 
01640         # delta - datetime is senseless.
01641         self.assertRaises(TypeError, lambda: day - a)
01642         # mixing datetime and (delta or datetime) via * or // is senseless
01643         self.assertRaises(TypeError, lambda: day * a)
01644         self.assertRaises(TypeError, lambda: a * day)
01645         self.assertRaises(TypeError, lambda: day // a)
01646         self.assertRaises(TypeError, lambda: a // day)
01647         self.assertRaises(TypeError, lambda: a * a)
01648         self.assertRaises(TypeError, lambda: a // a)
01649         # datetime + datetime is senseless
01650         self.assertRaises(TypeError, lambda: a + a)

Here is the call graph for this function:

def test.datetimetester.TestDate.test_ctime (   self) [inherited]

Definition at line 1079 of file datetimetester.py.

01079 
01080     def test_ctime(self):
01081         t = self.theclass(2002, 3, 2)
01082         self.assertEqual(t.ctime(), "Sat Mar  2 00:00:00 2002")

Here is the call graph for this function:

Reimplemented in test.datetimetester.TestDateTimeTZ.

Definition at line 1852 of file datetimetester.py.

01852 
01853     def test_extract(self):
01854         dt = self.theclass(2002, 3, 4, 18, 45, 3, 1234)
01855         self.assertEqual(dt.date(), date(2002, 3, 4))
01856         self.assertEqual(dt.time(), time(18, 45, 3, 1234))

Here is the call graph for this function:

Definition at line 827 of file datetimetester.py.

00827 
00828     def test_extreme_ordinals(self):
00829         a = self.theclass.min
00830         a = self.theclass(a.year, a.month, a.day)  # get rid of time parts
00831         aord = a.toordinal()
00832         b = a.fromordinal(aord)
00833         self.assertEqual(a, b)
00834 
00835         self.assertRaises(ValueError, lambda: a.fromordinal(aord - 1))
00836 
00837         b = a + timedelta(days=1)
00838         self.assertEqual(b.toordinal(), aord + 1)
00839         self.assertEqual(b, self.theclass.fromordinal(aord + 1))
00840 
00841         a = self.theclass.max
00842         a = self.theclass(a.year, a.month, a.day)  # get rid of time parts
00843         aord = a.toordinal()
00844         b = a.fromordinal(aord)
00845         self.assertEqual(a, b)
00846 
00847         self.assertRaises(ValueError, lambda: a.fromordinal(aord + 1))
00848 
00849         b = a - timedelta(days=1)
00850         self.assertEqual(b.toordinal(), aord - 1)
00851         self.assertEqual(b, self.theclass.fromordinal(aord - 1))

Here is the call graph for this function:

Definition at line 1154 of file datetimetester.py.

01154 
01155     def test_extreme_timedelta(self):
01156         big = self.theclass.max - self.theclass.min
01157         # 3652058 days, 23 hours, 59 minutes, 59 seconds, 999999 microseconds
01158         n = (big.days*24*3600 + big.seconds)*1000000 + big.microseconds
01159         # n == 315537897599999999 ~= 2**58.13
01160         justasbig = timedelta(0, 0, n)
01161         self.assertEqual(big, justasbig)
01162         self.assertEqual(self.theclass.min + big, self.theclass.max)
01163         self.assertEqual(self.theclass.max - big, self.theclass.min)

Here is the call graph for this function:

Reimplemented from test.datetimetester.TestDate.

Definition at line 1444 of file datetimetester.py.

01444 
01445     def test_format(self):
01446         dt = self.theclass(2007, 9, 10, 4, 5, 1, 123)
01447         self.assertEqual(dt.__format__(''), str(dt))
01448 
01449         # check that a derived class's __str__() gets called
01450         class A(self.theclass):
01451             def __str__(self):
01452                 return 'A'
01453         a = A(2007, 9, 10, 4, 5, 1, 123)
01454         self.assertEqual(a.__format__(''), 'A')
01455 
01456         # check that a derived class's strftime gets called
01457         class B(self.theclass):
01458             def strftime(self, format_spec):
01459                 return 'B'
01460         b = B(2007, 9, 10, 4, 5, 1, 123)
01461         self.assertEqual(b.__format__(''), str(dt))
01462 
01463         for fmt in ["m:%m d:%d y:%y",
01464                     "m:%m d:%d y:%y H:%H M:%M S:%S",
01465                     "%z %Z",
01466                     ]:
01467             self.assertEqual(dt.__format__(fmt), dt.strftime(fmt))
01468             self.assertEqual(a.__format__(fmt), dt.strftime(fmt))
01469             self.assertEqual(b.__format__(fmt), 'B')

Here is the call graph for this function:

Reimplemented from test.datetimetester.TestDate.

Definition at line 1716 of file datetimetester.py.

01716 
01717     def test_fromtimestamp(self):
01718         import time
01719 
01720         ts = time.time()
01721         expected = time.localtime(ts)
01722         got = self.theclass.fromtimestamp(ts)
01723         self.verify_field_equality(expected, got)

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:

Reimplemented from test.datetimetester.TestDate.

Definition at line 1560 of file datetimetester.py.

01560 
01561     def test_hash_equality(self):
01562         d = self.theclass(2000, 12, 31, 23, 30, 17)
01563         e = self.theclass(2000, 12, 31, 23, 30, 17)
01564         self.assertEqual(d, e)
01565         self.assertEqual(hash(d), hash(e))
01566 
01567         dic = {d: 1}
01568         dic[e] = 2
01569         self.assertEqual(len(dic), 1)
01570         self.assertEqual(dic[d], 2)
01571         self.assertEqual(dic[e], 2)
01572 
01573         d = self.theclass(2001,  1,  1,  0,  5, 17)
01574         e = self.theclass(2001,  1,  1,  0,  5, 17)
01575         self.assertEqual(d, e)
01576         self.assertEqual(hash(d), hash(e))
01577 
01578         dic = {d: 1}
01579         dic[e] = 2
01580         self.assertEqual(len(dic), 1)
01581         self.assertEqual(dic[d], 2)
01582         self.assertEqual(dic[e], 2)

Here is the call graph for this function:

Reimplemented from test.datetimetester.TestDate.

Definition at line 1740 of file datetimetester.py.

01740 
01741     def test_insane_fromtimestamp(self):
01742         # It's possible that some platform maps time_t to double,
01743         # and that this test will fail there.  This test should
01744         # exempt such platforms (provided they return reasonable
01745         # results!).
01746         for insane in -1e200, 1e200:
01747             self.assertRaises(ValueError, self.theclass.fromtimestamp,
01748                               insane)

Here is the call graph for this function:

Definition at line 1749 of file datetimetester.py.

01749 
01750     def test_insane_utcfromtimestamp(self):
01751         # It's possible that some platform maps time_t to double,
01752         # and that this test will fail there.  This test should
01753         # exempt such platforms (provided they return reasonable
01754         # results!).
01755         for insane in -1e200, 1e200:
01756             self.assertRaises(ValueError, self.theclass.utcfromtimestamp,
                              insane)

Here is the call graph for this function:

Definition at line 1037 of file datetimetester.py.

01037 
01038     def test_iso_long_years(self):
01039         # Calculate long ISO years and compare to table from
01040         # http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm
01041         ISO_LONG_YEARS_TABLE = """
01042               4   32   60   88
01043               9   37   65   93
01044              15   43   71   99
01045              20   48   76
01046              26   54   82
01047 
01048             105  133  161  189
01049             111  139  167  195
01050             116  144  172
01051             122  150  178
01052             128  156  184
01053 
01054             201  229  257  285
01055             207  235  263  291
01056             212  240  268  296
01057             218  246  274
01058             224  252  280
01059 
01060             303  331  359  387
01061             308  336  364  392
01062             314  342  370  398
01063             320  348  376
01064             325  353  381
01065         """
01066         iso_long_years = sorted(map(int, ISO_LONG_YEARS_TABLE.split()))
01067         L = []
01068         for i in range(400):
01069             d = self.theclass(2000+i, 12, 31)
01070             d1 = self.theclass(1600+i, 12, 31)
01071             self.assertEqual(d.isocalendar()[1:], d1.isocalendar()[1:])
01072             if d.isocalendar()[1] == 53:
01073                 L.append(i)
01074         self.assertEqual(L, iso_long_years)

Here is the call graph for this function:

Definition at line 1020 of file datetimetester.py.

01020 
01021     def test_isocalendar(self):
01022         # Check examples from
01023         # http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm
01024         for i in range(7):
01025             d = self.theclass(2003, 12, 22+i)
01026             self.assertEqual(d.isocalendar(), (2003, 52, i+1))
01027             d = self.theclass(2003, 12, 29) + timedelta(i)
01028             self.assertEqual(d.isocalendar(), (2004, 1, i+1))
01029             d = self.theclass(2004, 1, 5+i)
01030             self.assertEqual(d.isocalendar(), (2004, 2, i+1))
01031             d = self.theclass(2009, 12, 21+i)
01032             self.assertEqual(d.isocalendar(), (2009, 52, i+1))
01033             d = self.theclass(2009, 12, 28) + timedelta(i)
01034             self.assertEqual(d.isocalendar(), (2009, 53, i+1))
01035             d = self.theclass(2010, 1, 4+i)
01036             self.assertEqual(d.isocalendar(), (2010, 1, i+1))

Here is the call graph for this function:

Reimplemented from test.datetimetester.TestDate.

Definition at line 1428 of file datetimetester.py.

01428 
01429     def test_isoformat(self):
01430         t = self.theclass(2, 3, 2, 4, 5, 1, 123)
01431         self.assertEqual(t.isoformat(),    "0002-03-02T04:05:01.000123")
01432         self.assertEqual(t.isoformat('T'), "0002-03-02T04:05:01.000123")
01433         self.assertEqual(t.isoformat(' '), "0002-03-02 04:05:01.000123")
01434         self.assertEqual(t.isoformat('\x00'), "0002-03-02\x0004:05:01.000123")
01435         # str is ISO format with the separator forced to a blank.
01436         self.assertEqual(str(t), "0002-03-02 04:05:01.000123")
01437 
01438         t = self.theclass(2, 3, 2)
01439         self.assertEqual(t.isoformat(),    "0002-03-02T00:00:00")
01440         self.assertEqual(t.isoformat('T'), "0002-03-02T00:00:00")
01441         self.assertEqual(t.isoformat(' '), "0002-03-02 00:00:00")
01442         # str is ISO format with the separator forced to a blank.
01443         self.assertEqual(str(t), "0002-03-02 00:00:00")

Here is the call graph for this function:

Definition at line 1732 of file datetimetester.py.

01732 
01733     def test_microsecond_rounding(self):
01734         # Test whether fromtimestamp "rounds up" floats that are less
01735         # than 1/2 microsecond smaller than an integer.
01736         for fts in [self.theclass.fromtimestamp,
01737                     self.theclass.utcfromtimestamp]:
01738             self.assertEqual(fts(0.9999999), fts(1))
01739             self.assertEqual(fts(0.99999949).microsecond, 999999)

Here is the call graph for this function:

Reimplemented in test.datetimetester.TestDateTimeTZ.

Definition at line 1236 of file datetimetester.py.

01236 
01237     def test_mixed_compare(self):
01238         our = self.theclass(2000, 4, 5)
01239 
01240         # Our class can be compared for equality to other classes
01241         self.assertEqual(our == 1, False)
01242         self.assertEqual(1 == our, False)
01243         self.assertEqual(our != 1, True)
01244         self.assertEqual(1 != our, True)
01245 
01246         # But the ordering is undefined
01247         self.assertRaises(TypeError, lambda: our < 1)
01248         self.assertRaises(TypeError, lambda: 1 < our)
01249 
01250         # Repeat those tests with a different class
01251 
01252         class SomeClass:
01253             pass
01254 
01255         their = SomeClass()
01256         self.assertEqual(our == their, False)
01257         self.assertEqual(their == our, False)
01258         self.assertEqual(our != their, True)
01259         self.assertEqual(their != our, True)
01260         self.assertRaises(TypeError, lambda: our < their)
01261         self.assertRaises(TypeError, lambda: their < our)
01262 
01263         # However, if the other class explicitly defines ordering
01264         # relative to our class, it is allowed to do so
01265 
01266         class LargerThanAnything:
01267             def __lt__(self, other):
01268                 return False
01269             def __le__(self, other):
01270                 return isinstance(other, LargerThanAnything)
01271             def __eq__(self, other):
01272                 return isinstance(other, LargerThanAnything)
01273             def __ne__(self, other):
01274                 return not isinstance(other, LargerThanAnything)
01275             def __gt__(self, other):
01276                 return not isinstance(other, LargerThanAnything)
01277             def __ge__(self, other):
01278                 return True
01279 
01280         their = LargerThanAnything()
01281         self.assertEqual(our == their, False)
01282         self.assertEqual(their == our, False)
01283         self.assertEqual(our != their, True)
01284         self.assertEqual(their != our, True)
01285         self.assertEqual(our < their, True)
01286         self.assertEqual(their < our, False)

Here is the call graph for this function:

Definition at line 1675 of file datetimetester.py.

01675 
01676     def test_more_compare(self):
01677         # The test_compare() inherited from TestDate covers the error cases.
01678         # We just want to test lexicographic ordering on the members datetime
01679         # has that date lacks.
01680         args = [2000, 11, 29, 20, 58, 16, 999998]
01681         t1 = self.theclass(*args)
01682         t2 = self.theclass(*args)
01683         self.assertEqual(t1, t2)
01684         self.assertTrue(t1 <= t2)
01685         self.assertTrue(t1 >= t2)
01686         self.assertTrue(not t1 != t2)
01687         self.assertTrue(not t1 < t2)
01688         self.assertTrue(not t1 > t2)
01689 
01690         for i in range(len(args)):
01691             newargs = args[:]
01692             newargs[i] = args[i] + 1
01693             t2 = self.theclass(*newargs)   # this is larger than t1
01694             self.assertTrue(t1 < t2)
01695             self.assertTrue(t2 > t1)
01696             self.assertTrue(t1 <= t2)
01697             self.assertTrue(t2 >= t1)
01698             self.assertTrue(t1 != t2)
01699             self.assertTrue(t2 != t1)
01700             self.assertTrue(not t1 == t2)
01701             self.assertTrue(not t2 == t1)
01702             self.assertTrue(not t1 > t2)
01703             self.assertTrue(not t2 < t1)
01704             self.assertTrue(not t1 >= t2)
01705             self.assertTrue(not t2 <= t1)
01706 

Here is the call graph for this function:

Definition at line 1470 of file datetimetester.py.

01470 
01471     def test_more_ctime(self):
01472         # Test fields that TestDate doesn't touch.
01473         import time
01474 
01475         t = self.theclass(2002, 3, 2, 18, 3, 5, 123)
01476         self.assertEqual(t.ctime(), "Sat Mar  2 18:03:05 2002")
01477         # Oops!  The next line fails on Win2K under MSVC 6, so it's commented
01478         # out.  The difference is that t.ctime() produces " 2" for the day,
01479         # but platform ctime() produces "02" for the day.  According to
01480         # C99, t.ctime() is correct here.
01481         # self.assertEqual(t.ctime(), time.ctime(time.mktime(t.timetuple())))
01482 
01483         # So test a case where that difference doesn't matter.
01484         t = self.theclass(2002, 3, 22, 18, 3, 5, 123)
01485         self.assertEqual(t.ctime(), time.ctime(time.mktime(t.timetuple())))

Here is the call graph for this function:

Definition at line 1659 of file datetimetester.py.

01659 
01660     def test_more_pickling(self):
01661         a = self.theclass(2003, 2, 7, 16, 48, 37, 444116)
01662         s = pickle.dumps(a)
01663         b = pickle.loads(s)
01664         self.assertEqual(b.year, 2003)
01665         self.assertEqual(b.month, 2)
01666         self.assertEqual(b.day, 7)

Here is the call graph for this function:

Definition at line 1846 of file datetimetester.py.

01846 
01847     def test_more_strftime(self):
01848         # This tests fields beyond those tested by the TestDate.test_strftime.
01849         t = self.theclass(2004, 12, 31, 6, 22, 33, 47)
01850         self.assertEqual(t.strftime("%m %d %y %f %S %M %H %j"),
01851                                     "12 31 04 000047 33 22 06 366")

Here is the call graph for this function:

Definition at line 1824 of file datetimetester.py.

01824 
01825     def test_more_timetuple(self):
01826         # This tests fields beyond those tested by the TestDate.test_timetuple.
01827         t = self.theclass(2004, 12, 31, 6, 22, 33)
01828         self.assertEqual(t.timetuple(), (2004, 12, 31, 6, 22, 33, 4, 366, -1))
01829         self.assertEqual(t.timetuple(),
01830                          (t.year, t.month, t.day,
01831                           t.hour, t.minute, t.second,
01832                           t.weekday(),
01833                           t.toordinal() - date(t.year, 1, 1).toordinal() + 1,
01834                           -1))
01835         tt = t.timetuple()
01836         self.assertEqual(tt.tm_year, t.year)
01837         self.assertEqual(tt.tm_mon, t.month)
01838         self.assertEqual(tt.tm_mday, t.day)
01839         self.assertEqual(tt.tm_hour, t.hour)
01840         self.assertEqual(tt.tm_min, t.minute)
01841         self.assertEqual(tt.tm_sec, t.second)
01842         self.assertEqual(tt.tm_wday, t.weekday())
01843         self.assertEqual(tt.tm_yday, t.toordinal() -
01844                                      date(t.year, 1, 1).toordinal() + 1)
01845         self.assertEqual(tt.tm_isdst, -1)

Here is the call graph for this function:

Definition at line 1758 of file datetimetester.py.

01758 
01759     def test_negative_float_fromtimestamp(self):
01760         # The result is tz-dependent; at least test that this doesn't
01761         # fail (like it did before bug 1646728 was fixed).
01762         self.theclass.fromtimestamp(-1.05)

Definition at line 1764 of file datetimetester.py.

01764 
01765     def test_negative_float_utcfromtimestamp(self):
01766         d = self.theclass.utcfromtimestamp(-1.05)
01767         self.assertEqual(d, self.theclass(1969, 12, 31, 23, 59, 58, 950000))

Here is the call graph for this function:

Definition at line 780 of file datetimetester.py.

00780 
00781     def test_ordinal_conversions(self):
00782         # Check some fixed values.
00783         for y, m, d, n in [(1, 1, 1, 1),      # calendar origin
00784                            (1, 12, 31, 365),
00785                            (2, 1, 1, 366),
00786                            # first example from "Calendrical Calculations"
00787                            (1945, 11, 12, 710347)]:
00788             d = self.theclass(y, m, d)
00789             self.assertEqual(n, d.toordinal())
00790             fromord = self.theclass.fromordinal(n)
00791             self.assertEqual(d, fromord)
00792             if hasattr(fromord, "hour"):
00793             # if we're checking something fancier than a date, verify
00794             # the extra fields have been zeroed out
00795                 self.assertEqual(fromord.hour, 0)
00796                 self.assertEqual(fromord.minute, 0)
00797                 self.assertEqual(fromord.second, 0)
00798                 self.assertEqual(fromord.microsecond, 0)
00799 
00800         # Check first and last days of year spottily across the whole
00801         # range of years supported.
00802         for year in range(MINYEAR, MAXYEAR+1, 7):
00803             # Verify (year, 1, 1) -> ordinal -> y, m, d is identity.
00804             d = self.theclass(year, 1, 1)
00805             n = d.toordinal()
00806             d2 = self.theclass.fromordinal(n)
00807             self.assertEqual(d, d2)
00808             # Verify that moving back a day gets to the end of year-1.
00809             if year > 1:
00810                 d = self.theclass.fromordinal(n-1)
00811                 d2 = self.theclass(year-1, 12, 31)
00812                 self.assertEqual(d, d2)
00813                 self.assertEqual(d2.toordinal(), n-1)
00814 
00815         # Test every day in a leap-year and a non-leap year.
00816         dim = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
00817         for year, isleap in (2000, True), (2002, False):
00818             n = self.theclass(year, 1, 1).toordinal()
00819             for month, maxday in zip(range(1, 13), dim):
00820                 if month == 2 and isleap:
00821                     maxday += 1
00822                 for day in range(1, maxday+1):
00823                     d = self.theclass(year, month, day)
00824                     self.assertEqual(d.toordinal(), n)
00825                     self.assertEqual(d, self.theclass.fromordinal(n))
00826                     n += 1

Here is the call graph for this function:

def test.datetimetester.TestDate.test_overflow (   self) [inherited]

Definition at line 949 of file datetimetester.py.

00949 
00950     def test_overflow(self):
00951         tiny = self.theclass.resolution
00952 
00953         for delta in [tiny, timedelta(1), timedelta(2)]:
00954             dt = self.theclass.min + delta
00955             dt -= delta  # no problem
00956             self.assertRaises(OverflowError, dt.__sub__, delta)
00957             self.assertRaises(OverflowError, dt.__add__, -delta)
00958 
00959             dt = self.theclass.max - delta
00960             dt += delta  # no problem
00961             self.assertRaises(OverflowError, dt.__add__, delta)
00962             self.assertRaises(OverflowError, dt.__sub__, -delta)

Here is the call graph for this function:

Reimplemented from test.datetimetester.TestDate.

Reimplemented in test.datetimetester.TestDateTimeTZ.

Definition at line 1651 of file datetimetester.py.

01651 
01652     def test_pickling(self):
01653         args = 6, 7, 23, 20, 59, 1, 64**2
01654         orig = self.theclass(*args)
01655         for pickler, unpickler, proto in pickle_choices:
01656             green = pickler.dumps(orig, proto)
01657             derived = unpickler.loads(green)
01658             self.assertEqual(orig, derived)

Here is the call graph for this function:

Definition at line 1346 of file datetimetester.py.

01346 
01347     def test_pickling_subclass_date(self):
01348 
01349         args = 6, 7, 23
01350         orig = SubclassDate(*args)
01351         for pickler, unpickler, proto in pickle_choices:
01352             green = pickler.dumps(orig, proto)
01353             derived = unpickler.loads(green)
01354             self.assertEqual(orig, derived)

Here is the call graph for this function:

Definition at line 1667 of file datetimetester.py.

01667 
01668     def test_pickling_subclass_datetime(self):
01669         args = 6, 7, 23, 20, 59, 1, 64**2
01670         orig = SubclassDatetime(*args)
01671         for pickler, unpickler, proto in pickle_choices:
01672             green = pickler.dumps(orig, proto)
01673             derived = unpickler.loads(green)
01674             self.assertEqual(orig, derived)

Here is the call graph for this function:

Reimplemented from test.datetimetester.TestDate.

Reimplemented in test.datetimetester.TestDateTimeTZ.

Definition at line 1880 of file datetimetester.py.

01880 
01881     def test_replace(self):
01882         cls = self.theclass
01883         args = [1, 2, 3, 4, 5, 6, 7]
01884         base = cls(*args)
01885         self.assertEqual(base, base.replace())
01886 
01887         i = 0
01888         for name, newval in (("year", 2),
01889                              ("month", 3),
01890                              ("day", 4),
01891                              ("hour", 5),
01892                              ("minute", 6),
01893                              ("second", 7),
01894                              ("microsecond", 8)):
01895             newargs = args[:]
01896             newargs[i] = newval
01897             expected = cls(*newargs)
01898             got = base.replace(**{name: newval})
01899             self.assertEqual(expected, got)
01900             i += 1
01901 
01902         # Out of bounds.
01903         base = cls(2000, 2, 29)
01904         self.assertRaises(ValueError, base.replace, year=2001)

Here is the call graph for this function:

Definition at line 1143 of file datetimetester.py.

01143 
01144     def test_resolution_info(self):
01145         # XXX: Should min and max respect subclassing?
01146         if issubclass(self.theclass, datetime):
01147             expected_class = datetime
01148         else:
01149             expected_class = date
01150         self.assertIsInstance(self.theclass.min, expected_class)
01151         self.assertIsInstance(self.theclass.max, expected_class)
01152         self.assertIsInstance(self.theclass.resolution, timedelta)
01153         self.assertTrue(self.theclass.max > self.theclass.min)

Here is the call graph for this function:

Reimplemented from test.datetimetester.TestDateTime.

Definition at line 1960 of file datetimetester.py.

01960 
01961     def test_roundtrip(self):
01962         pass

def test.datetimetester.TestDate.test_strftime (   self) [inherited]

Definition at line 1083 of file datetimetester.py.

01083 
01084     def test_strftime(self):
01085         t = self.theclass(2005, 3, 2)
01086         self.assertEqual(t.strftime("m:%m d:%d y:%y"), "m:03 d:02 y:05")
01087         self.assertEqual(t.strftime(""), "") # SF bug #761337
01088         self.assertEqual(t.strftime('x'*1000), 'x'*1000) # SF bug #1556784
01089 
01090         self.assertRaises(TypeError, t.strftime) # needs an arg
01091         self.assertRaises(TypeError, t.strftime, "one", "two") # too many args
01092         self.assertRaises(TypeError, t.strftime, 42) # arg wrong type
01093 
01094         # test that unicode input is allowed (issue 2782)
01095         self.assertEqual(t.strftime("%m"), "03")
01096 
01097         # A naive object replaces %z and %Z w/ empty strings.
01098         self.assertEqual(t.strftime("'%z' '%Z'"), "'' ''")
01099 
01100         #make sure that invalid format specifiers are handled correctly
01101         #self.assertRaises(ValueError, t.strftime, "%e")
01102         #self.assertRaises(ValueError, t.strftime, "%")
01103         #self.assertRaises(ValueError, t.strftime, "%#")
01104 
01105         #oh well, some systems just ignore those invalid ones.
01106         #at least, excercise them to make sure that no crashes
01107         #are generated
01108         for f in ["%e", "%", "%#"]:
01109             try:
01110                 t.strftime(f)
01111             except ValueError:
01112                 pass
01113 
01114         #check that this standard extension works
01115         t.strftime("%f")
01116 

Here is the call graph for this function:

Definition at line 1292 of file datetimetester.py.

01292 
01293     def test_strftime_out_of_range(self):
01294         # For nasty technical reasons, we can't handle years before 1000.
01295         cls = self.theclass
01296         self.assertEqual(cls(1000, 1, 1).strftime("%Y"), "1000")
01297         for y in 1, 49, 51, 99, 100, 999:
01298             self.assertRaises(ValueError, cls(y, 1, 1).strftime, "%Y")

Here is the call graph for this function:

Definition at line 1504 of file datetimetester.py.

01504 
01505     def test_strftime_with_bad_tzname_replace(self):
01506         # verify ok if tzinfo.tzname().replace() returns a non-string
01507         class MyTzInfo(FixedOffset):
01508             def tzname(self, dt):
01509                 class MyStr(str):
01510                     def replace(self, *args):
01511                         return None
01512                 return MyStr('name')
01513         t = self.theclass(2005, 3, 2, 0, 0, 0, 0, MyTzInfo(3, 'name'))
01514         self.assertRaises(TypeError, t.strftime, '%Z')

Here is the call graph for this function:

Definition at line 1782 of file datetimetester.py.

01782 
01783     def test_strptime(self):
01784         import _strptime
01785 
01786         string = '2004-12-01 13:02:47.197'
01787         format = '%Y-%m-%d %H:%M:%S.%f'
01788         expected = _strptime._strptime_datetime(self.theclass, string, format)
01789         got = self.theclass.strptime(string, format)
01790         self.assertEqual(expected, got)
01791         self.assertIs(type(expected), self.theclass)
01792         self.assertIs(type(got), self.theclass)
01793 
01794         strptime = self.theclass.strptime
01795         self.assertEqual(strptime("+0002", "%z").utcoffset(), 2 * MINUTE)
01796         self.assertEqual(strptime("-0002", "%z").utcoffset(), -2 * MINUTE)
01797         # Only local timezone and UTC are supported
01798         for tzseconds, tzname in ((0, 'UTC'), (0, 'GMT'),
01799                                  (-_time.timezone, _time.tzname[0])):
01800             if tzseconds < 0:
01801                 sign = '-'
01802                 seconds = -tzseconds
01803             else:
01804                 sign ='+'
01805                 seconds = tzseconds
01806             hours, minutes = divmod(seconds//60, 60)
01807             dtstr = "{}{:02d}{:02d} {}".format(sign, hours, minutes, tzname)
01808             dt = strptime(dtstr, "%z %Z")
01809             self.assertEqual(dt.utcoffset(), timedelta(seconds=tzseconds))
01810             self.assertEqual(dt.tzname(), tzname)
01811         # Can produce inconsistent datetime
01812         dtstr, fmt = "+1234 UTC", "%z %Z"
01813         dt = strptime(dtstr, fmt)
01814         self.assertEqual(dt.utcoffset(), 12 * HOUR + 34 * MINUTE)
01815         self.assertEqual(dt.tzname(), 'UTC')
01816         # yet will roundtrip
01817         self.assertEqual(dt.strftime(fmt), dtstr)
01818 
01819         # Produce naive datetime if no %z is provided
01820         self.assertEqual(strptime("UTC", "%Z").tzinfo, None)
01821 
01822         with self.assertRaises(ValueError): strptime("-2400", "%z")
01823         with self.assertRaises(ValueError): strptime("-000", "%z")

Here is the call graph for this function:

Definition at line 1320 of file datetimetester.py.

01320 
01321     def test_subclass_date(self):
01322 
01323         class C(self.theclass):
01324             theAnswer = 42
01325 
01326             def __new__(cls, *args, **kws):
01327                 temp = kws.copy()
01328                 extra = temp.pop('extra')
01329                 result = self.theclass.__new__(cls, *args, **temp)
01330                 result.extra = extra
01331                 return result
01332 
01333             def newmeth(self, start):
01334                 return start + self.year + self.month
01335 
01336         args = 2003, 4, 14
01337 
01338         dt1 = self.theclass(*args)
01339         dt2 = C(*args, **{'extra': 7})
01340 
01341         self.assertEqual(dt2.__class__, C)
01342         self.assertEqual(dt2.theAnswer, 42)
01343         self.assertEqual(dt2.extra, 7)
01344         self.assertEqual(dt1.toordinal(), dt2.toordinal())
01345         self.assertEqual(dt2.newmeth(-7), dt1.year + dt1.month - 7)

Here is the call graph for this function:

Definition at line 1930 of file datetimetester.py.

01930 
01931     def test_subclass_datetime(self):
01932 
01933         class C(self.theclass):
01934             theAnswer = 42
01935 
01936             def __new__(cls, *args, **kws):
01937                 temp = kws.copy()
01938                 extra = temp.pop('extra')
01939                 result = self.theclass.__new__(cls, *args, **temp)
01940                 result.extra = extra
01941                 return result
01942 
01943             def newmeth(self, start):
01944                 return start + self.year + self.month + self.second
01945 
01946         args = 2003, 4, 14, 12, 13, 41
01947 
01948         dt1 = self.theclass(*args)
01949         dt2 = C(*args, **{'extra': 7})
01950 
01951         self.assertEqual(dt2.__class__, C)
01952         self.assertEqual(dt2.theAnswer, 42)
01953         self.assertEqual(dt2.extra, 7)
01954         self.assertEqual(dt1.toordinal(), dt2.toordinal())
01955         self.assertEqual(dt2.newmeth(-7), dt1.year + dt1.month +
01956                                           dt1.second - 7)

Here is the call graph for this function:

def test.datetimetester.TestDate.test_timetuple (   self) [inherited]

Definition at line 1164 of file datetimetester.py.

01164 
01165     def test_timetuple(self):
01166         for i in range(7):
01167             # January 2, 1956 is a Monday (0)
01168             d = self.theclass(1956, 1, 2+i)
01169             t = d.timetuple()
01170             self.assertEqual(t, (1956, 1, 2+i, 0, 0, 0, i, 2+i, -1))
01171             # February 1, 1956 is a Wednesday (2)
01172             d = self.theclass(1956, 2, 1+i)
01173             t = d.timetuple()
01174             self.assertEqual(t, (1956, 2, 1+i, 0, 0, 0, (2+i)%7, 32+i, -1))
01175             # March 1, 1956 is a Thursday (3), and is the 31+29+1 = 61st day
01176             # of the year.
01177             d = self.theclass(1956, 3, 1+i)
01178             t = d.timetuple()
01179             self.assertEqual(t, (1956, 3, 1+i, 0, 0, 0, (3+i)%7, 61+i, -1))
01180             self.assertEqual(t.tm_year, 1956)
01181             self.assertEqual(t.tm_mon, 3)
01182             self.assertEqual(t.tm_mday, 1+i)
01183             self.assertEqual(t.tm_hour, 0)
01184             self.assertEqual(t.tm_min, 0)
01185             self.assertEqual(t.tm_sec, 0)
01186             self.assertEqual(t.tm_wday, (3+i)%7)
01187             self.assertEqual(t.tm_yday, 61+i)
01188             self.assertEqual(t.tm_isdst, -1)

Here is the call graph for this function:

def test.datetimetester.TestDate.test_today (   self) [inherited]

Definition at line 983 of file datetimetester.py.

00983 
00984     def test_today(self):
00985         import time
00986 
00987         # We claim that today() is like fromtimestamp(time.time()), so
00988         # prove it.
00989         for dummy in range(3):
00990             today = self.theclass.today()
00991             ts = time.time()
00992             todayagain = self.theclass.fromtimestamp(ts)
00993             if today == todayagain:
00994                 break
00995             # There are several legit reasons that could fail:
00996             # 1. It recently became midnight, between the today() and the
00997             #    time() calls.
00998             # 2. The platform time() has such fine resolution that we'll
00999             #    never get the same value twice.
01000             # 3. The platform time() has poor resolution, and we just
01001             #    happened to call today() right before a resolution quantum
01002             #    boundary.
01003             # 4. The system clock got fiddled between calls.
01004             # In any case, wait a little while and try again.
01005             time.sleep(0.1)
01006 
01007         # It worked or it didn't.  If it didn't, assume it's reason #2, and
01008         # let the test pass if they're within half a second of each other.
01009         self.assertTrue(today == todayagain or
01010                         abs(todayagain - today) < timedelta(seconds=0.5))

Here is the call graph for this function:

Definition at line 1486 of file datetimetester.py.

01486 
01487     def test_tz_independent_comparing(self):
01488         dt1 = self.theclass(2002, 3, 1, 9, 0, 0)
01489         dt2 = self.theclass(2002, 3, 1, 10, 0, 0)
01490         dt3 = self.theclass(2002, 3, 1, 9, 0, 0)
01491         self.assertEqual(dt1, dt3)
01492         self.assertTrue(dt2 > dt3)
01493 
01494         # Make sure comparison doesn't forget microseconds, and isn't done
01495         # via comparing a float timestamp (an IEEE double doesn't have enough
01496         # precision to span microsecond resolution across years 1 thru 9999,
01497         # so comparing via timestamp necessarily calls some distinct values
01498         # equal).
01499         dt1 = self.theclass(MAXYEAR, 12, 31, 23, 59, 59, 999998)
01500         us = timedelta(microseconds=1)
01501         dt2 = dt1 + us
01502         self.assertEqual(dt2 - dt1, us)
01503         self.assertTrue(dt1 < dt2)

Here is the call graph for this function:

Definition at line 1724 of file datetimetester.py.

01724 
01725     def test_utcfromtimestamp(self):
01726         import time
01727 
01728         ts = time.time()
01729         expected = time.gmtime(ts)
01730         got = self.theclass.utcfromtimestamp(ts)
01731         self.verify_field_equality(expected, got)

Here is the call graph for this function:

Definition at line 1768 of file datetimetester.py.

01768 
01769     def test_utcnow(self):
01770         import time
01771 
01772         # Call it a success if utcnow() and utcfromtimestamp() are within
01773         # a second of each other.
01774         tolerance = timedelta(seconds=1)
01775         for dummy in range(3):
01776             from_now = self.theclass.utcnow()
01777             from_timestamp = self.theclass.utcfromtimestamp(time.time())
01778             if abs(from_timestamp - from_now) <= tolerance:
01779                 break
01780             # Else try again a few times.
01781         self.assertTrue(abs(from_timestamp - from_now) <= tolerance)

Here is the call graph for this function:

def test.datetimetester.TestDate.test_weekday (   self) [inherited]

Definition at line 1011 of file datetimetester.py.

01011 
01012     def test_weekday(self):
01013         for i in range(7):
01014             # March 4, 2002 is a Monday
01015             self.assertEqual(self.theclass(2002, 3, 4+i).weekday(), i)
01016             self.assertEqual(self.theclass(2002, 3, 4+i).isoweekday(), i+1)
01017             # January 2, 1956 is a Monday
01018             self.assertEqual(self.theclass(1956, 1, 2+i).weekday(), i)
01019             self.assertEqual(self.theclass(1956, 1, 2+i).isoweekday(), i+1)

Here is the call graph for this function:

def test.datetimetester.TestDateTime.verify_field_equality (   self,
  expected,
  got 
) [inherited]

Definition at line 1708 of file datetimetester.py.

01708 
01709     def verify_field_equality(self, expected, got):
01710         self.assertEqual(expected.tm_year, got.year)
01711         self.assertEqual(expected.tm_mon, got.month)
01712         self.assertEqual(expected.tm_mday, got.day)
01713         self.assertEqual(expected.tm_hour, got.hour)
01714         self.assertEqual(expected.tm_min, got.minute)
01715         self.assertEqual(expected.tm_sec, got.second)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from test.datetimetester.TestDateTime.

Definition at line 1958 of file datetimetester.py.


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