Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_strptime.CalculationTests Class Reference

List of all members.

Public Member Functions

def setUp
def test_julian_calculation
def test_gregorian_calculation
def test_day_of_week_calculation
def test_week_of_year_and_day_of_week_calculation

Public Attributes

 time_tuple

Detailed Description

Test that strptime() fills in missing info correctly

Definition at line 404 of file test_strptime.py.


Member Function Documentation

Definition at line 407 of file test_strptime.py.

00407 
00408     def setUp(self):
00409         self.time_tuple = time.gmtime()

Here is the caller graph for this function:

Definition at line 433 of file test_strptime.py.

00433 
00434     def test_day_of_week_calculation(self):
00435         # Test that the day of the week is calculated as needed
00436         format_string = "%Y %m %d %H %S %j %Z"
00437         result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
00438                                     format_string)
00439         self.assertTrue(result.tm_wday == self.time_tuple.tm_wday,
00440                         "Calculation of day of the week failed;"
00441                          "%s != %s" % (result.tm_wday, self.time_tuple.tm_wday))

Here is the call graph for this function:

Definition at line 419 of file test_strptime.py.

00419 
00420     def test_gregorian_calculation(self):
00421         # Test that Gregorian date can be calculated from Julian day
00422         format_string = "%Y %H %M %S %w %j %Z"
00423         result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
00424                                     format_string)
00425         self.assertTrue(result.tm_year == self.time_tuple.tm_year and
00426                          result.tm_mon == self.time_tuple.tm_mon and
00427                          result.tm_mday == self.time_tuple.tm_mday,
00428                         "Calculation of Gregorian date failed;"
00429                          "%s-%s-%s != %s-%s-%s" %
00430                          (result.tm_year, result.tm_mon, result.tm_mday,
00431                           self.time_tuple.tm_year, self.time_tuple.tm_mon,
00432                           self.time_tuple.tm_mday))

Here is the call graph for this function:

Definition at line 410 of file test_strptime.py.

00410 
00411     def test_julian_calculation(self):
00412         # Make sure that when Julian is missing that it is calculated
00413         format_string = "%Y %m %d %H %M %S %w %Z"
00414         result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
00415                                     format_string)
00416         self.assertTrue(result.tm_yday == self.time_tuple.tm_yday,
00417                         "Calculation of tm_yday failed; %s != %s" %
00418                          (result.tm_yday, self.time_tuple.tm_yday))

Here is the call graph for this function:

Definition at line 442 of file test_strptime.py.

00442 
00443     def test_week_of_year_and_day_of_week_calculation(self):
00444         # Should be able to infer date if given year, week of year (%U or %W)
00445         # and day of the week
00446         def test_helper(ymd_tuple, test_reason):
00447             for directive in ('W', 'U'):
00448                 format_string = "%%Y %%%s %%w" % directive
00449                 dt_date = datetime_date(*ymd_tuple)
00450                 strp_input = dt_date.strftime(format_string)
00451                 strp_output = _strptime._strptime_time(strp_input, format_string)
00452                 self.assertTrue(strp_output[:3] == ymd_tuple,
00453                         "%s(%s) test failed w/ '%s': %s != %s (%s != %s)" %
00454                             (test_reason, directive, strp_input,
00455                                 strp_output[:3], ymd_tuple,
00456                                 strp_output[7], dt_date.timetuple()[7]))
00457         test_helper((1901, 1, 3), "week 0")
00458         test_helper((1901, 1, 8), "common case")
00459         test_helper((1901, 1, 13), "day on Sunday")
00460         test_helper((1901, 1, 14), "day on Monday")
00461         test_helper((1905, 1, 1), "Jan 1 on Sunday")
00462         test_helper((1906, 1, 1), "Jan 1 on Monday")
00463         test_helper((1906, 1, 7), "first Sunday in a year starting on Monday")
00464         test_helper((1905, 12, 31), "Dec 31 on Sunday")
00465         test_helper((1906, 12, 31), "Dec 31 on Monday")
00466         test_helper((2008, 12, 29), "Monday in the last week of the year")
00467         test_helper((2008, 12, 22), "Monday in the second-to-last week of the "
00468                                     "year")
00469         test_helper((1978, 10, 23), "randomly chosen date")
00470         test_helper((2004, 12, 18), "randomly chosen date")
00471         test_helper((1978, 10, 23), "year starting and ending on Monday while "
00472                                         "date not on Sunday or Monday")
00473         test_helper((1917, 12, 17), "year starting and ending on Monday with "
00474                                         "a Monday not at the beginning or end "
00475                                         "of the year")
00476         test_helper((1917, 12, 31), "Dec 31 on Monday with year starting and "
00477                                         "ending on Monday")
00478         test_helper((2007, 1, 7), "First Sunday of 2007")
00479         test_helper((2007, 1, 14), "Second Sunday of 2007")
00480         test_helper((2006, 12, 31), "Last Sunday of 2006")
00481         test_helper((2006, 12, 24), "Second to last Sunday of 2006")
00482 

Here is the call graph for this function:


Member Data Documentation

Definition at line 408 of file test_strptime.py.


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