Back to index

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

List of all members.

Public Member Functions

def setUp
def compare_against_time
def test_weekday
def test_month
def test_am_pm
def test_timezone
def test_date_time
def test_lang

Public Attributes

 time_tuple
 LT_ins

Detailed Description

Tests for _strptime.LocaleTime.

All values are lower-cased when stored in LocaleTime, so make sure to
compare values after running ``lower`` on them.

Definition at line 18 of file test_strptime.py.


Member Function Documentation

def test.test_strptime.LocaleTime_Tests.compare_against_time (   self,
  testing,
  directive,
  tuple_position,
  error_msg 
)
Helper method that tests testing against directive based on the
tuple_position of time_tuple.  Uses error_msg as error message.

Definition at line 32 of file test_strptime.py.

00032 
00033                              error_msg):
00034         """Helper method that tests testing against directive based on the
00035         tuple_position of time_tuple.  Uses error_msg as error message.
00036 
00037         """
00038         strftime_output = time.strftime(directive, self.time_tuple).lower()
00039         comparison = testing[self.time_tuple[tuple_position]]
00040         self.assertIn(strftime_output, testing,
00041                       "%s: not found in tuple" % error_msg)
00042         self.assertTrue(comparison == strftime_output,
00043                         "%s: position within tuple incorrect; %s != %s" %
00044                         (error_msg, comparison, strftime_output))

Here is the call graph for this function:

Here is the caller graph for this function:

Create time tuple based on current time.

Definition at line 26 of file test_strptime.py.

00026 
00027     def setUp(self):
00028         """Create time tuple based on current time."""
00029         self.time_tuple = time.localtime()
00030         self.LT_ins = _strptime.LocaleTime()

Here is the caller graph for this function:

Definition at line 61 of file test_strptime.py.

00061 
00062     def test_am_pm(self):
00063         # Make sure AM/PM representation done properly
00064         strftime_output = time.strftime("%p", self.time_tuple).lower()
00065         self.assertIn(strftime_output, self.LT_ins.am_pm,
00066                       "AM/PM representation not in tuple")
00067         if self.time_tuple[3] < 12: position = 0
00068         else: position = 1
00069         self.assertTrue(strftime_output == self.LT_ins.am_pm[position],
00070                         "AM/PM representation in the wrong position within the tuple")

Here is the call graph for this function:

Definition at line 80 of file test_strptime.py.

00080 
00081     def test_date_time(self):
00082         # Check that LC_date_time, LC_date, and LC_time are correct
00083         # the magic date is used so as to not have issues with %c when day of
00084         #  the month is a single digit and has a leading space.  This is not an
00085         #  issue since strptime still parses it correctly.  The problem is
00086         #  testing these directives for correctness by comparing strftime
00087         #  output.
00088         magic_date = (1999, 3, 17, 22, 44, 55, 2, 76, 0)
00089         strftime_output = time.strftime("%c", magic_date)
00090         self.assertTrue(strftime_output == time.strftime(self.LT_ins.LC_date_time,
00091                                                          magic_date),
00092                         "LC_date_time incorrect")
00093         strftime_output = time.strftime("%x", magic_date)
00094         self.assertTrue(strftime_output == time.strftime(self.LT_ins.LC_date,
00095                                                          magic_date),
00096                         "LC_date incorrect")
00097         strftime_output = time.strftime("%X", magic_date)
00098         self.assertTrue(strftime_output == time.strftime(self.LT_ins.LC_time,
00099                                                          magic_date),
00100                         "LC_time incorrect")
00101         LT = _strptime.LocaleTime()
00102         LT.am_pm = ('', '')
00103         self.assertTrue(LT.LC_time, "LocaleTime's LC directives cannot handle "
00104                                     "empty strings")

Here is the call graph for this function:

Definition at line 105 of file test_strptime.py.

00105 
00106     def test_lang(self):
00107         # Make sure lang is set to what _getlang() returns
00108         # Assuming locale has not changed between now and when self.LT_ins was created
00109         self.assertEqual(self.LT_ins.lang, _strptime._getlang())
00110 

Here is the call graph for this function:

Definition at line 53 of file test_strptime.py.

00053 
00054     def test_month(self):
00055         # Test full and abbreviated month names; both string and position
00056         # within the tuple
00057         self.compare_against_time(self.LT_ins.f_month, '%B', 1,
00058                                   "Testing against full month name failed")
00059         self.compare_against_time(self.LT_ins.a_month, '%b', 1,
00060                                   "Testing against abbreviated month name failed")

Here is the call graph for this function:

Definition at line 71 of file test_strptime.py.

00071 
00072     def test_timezone(self):
00073         # Make sure timezone is correct
00074         timezone = time.strftime("%Z", self.time_tuple).lower()
00075         if timezone:
00076             self.assertTrue(timezone in self.LT_ins.timezone[0] or
00077                             timezone in self.LT_ins.timezone[1],
00078                             "timezone %s not found in %s" %
00079                             (timezone, self.LT_ins.timezone))

Here is the call graph for this function:

Definition at line 45 of file test_strptime.py.

00045 
00046     def test_weekday(self):
00047         # Make sure that full and abbreviated weekday names are correct in
00048         # both string and position with tuple
00049         self.compare_against_time(self.LT_ins.f_weekday, '%A', 6,
00050                                   "Testing of full weekday name failed")
00051         self.compare_against_time(self.LT_ins.a_weekday, '%a', 6,
00052                                   "Testing of abbreviated weekday name failed")

Here is the call graph for this function:


Member Data Documentation

Definition at line 29 of file test_strptime.py.

Definition at line 28 of file test_strptime.py.


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