Back to index

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

List of all members.

Public Member Functions

def setUp
def test_ValueError
def test_unconverteddata
def helper
def test_year
def test_month
def test_day
def test_hour
def test_minute
def test_second
def test_fraction
def test_weekday
def test_julian
def test_timezone
def test_bad_timezone
def test_date_time
def test_date
def test_time
def test_percent
def test_caseinsensitive
def test_defaults
def test_escaping

Public Attributes

 time_tuple

Detailed Description

Tests for _strptime.strptime.

Definition at line 202 of file test_strptime.py.


Member Function Documentation

def test.test_strptime.StrptimeTests.helper (   self,
  directive,
  position 
)
Helper fxn in testing.

Definition at line 228 of file test_strptime.py.

00228 
00229     def helper(self, directive, position):
00230         """Helper fxn in testing."""
00231         strf_output = time.strftime("%" + directive, self.time_tuple)
00232         strp_output = _strptime._strptime_time(strf_output, "%" + directive)
00233         self.assertTrue(strp_output[position] == self.time_tuple[position],
00234                         "testing of '%s' directive failed; '%s' -> %s != %s" %
00235                          (directive, strf_output, strp_output[position],
00236                           self.time_tuple[position]))

Here is the call graph for this function:

Here is the caller graph for this function:

Create testing time tuple.

Definition at line 205 of file test_strptime.py.

00205 
00206     def setUp(self):
00207         """Create testing time tuple."""
00208         self.time_tuple = time.gmtime()

Here is the caller graph for this function:

Definition at line 314 of file test_strptime.py.

00314 
00315     def test_bad_timezone(self):
00316         # Explicitly test possibility of bad timezone;
00317         # when time.tzname[0] == time.tzname[1] and time.daylight
00318         tz_name = time.tzname[0]
00319         if tz_name.upper() in ("UTC", "GMT"):
00320             return
00321         try:
00322             original_tzname = time.tzname
00323             original_daylight = time.daylight
00324             time.tzname = (tz_name, tz_name)
00325             time.daylight = 1
00326             tz_value = _strptime._strptime_time(tz_name, "%Z")[8]
00327             self.assertEqual(tz_value, -1,
00328                     "%s lead to a timezone value of %s instead of -1 when "
00329                     "time.daylight set to %s and passing in %s" %
00330                     (time.tzname, tz_value, time.daylight, tz_name))
00331         finally:
00332             time.tzname = original_tzname
00333             time.daylight = original_daylight

Here is the call graph for this function:

Definition at line 357 of file test_strptime.py.

00357 
00358     def test_caseinsensitive(self):
00359         # Should handle names case-insensitively.
00360         strf_output = time.strftime("%B", self.time_tuple)
00361         self.assertTrue(_strptime._strptime_time(strf_output.upper(), "%B"),
00362                         "strptime does not handle ALL-CAPS names properly")
00363         self.assertTrue(_strptime._strptime_time(strf_output.lower(), "%B"),
00364                         "strptime does not handle lowercase names properly")
00365         self.assertTrue(_strptime._strptime_time(strf_output.capitalize(), "%B"),
00366                         "strptime does not handle capword names properly")

Here is the call graph for this function:

Definition at line 339 of file test_strptime.py.

00339 
00340     def test_date(self):
00341         # Test %x directive
00342         for position in range(0,3):
00343             self.helper('x', position)

Here is the call graph for this function:

Definition at line 334 of file test_strptime.py.

00334 
00335     def test_date_time(self):
00336         # Test %c directive
00337         for position in range(6):
00338             self.helper('c', position)

Here is the call graph for this function:

Definition at line 255 of file test_strptime.py.

00255 
00256     def test_day(self):
00257         # Test for day directives
00258         self.helper('d', 2)

Here is the call graph for this function:

Definition at line 367 of file test_strptime.py.

00367 
00368     def test_defaults(self):
00369         # Default return value should be (1900, 1, 1, 0, 0, 0, 0, 1, 0)
00370         defaults = (1900, 1, 1, 0, 0, 0, 0, 1, -1)
00371         strp_output = _strptime._strptime_time('1', '%m')
00372         self.assertTrue(strp_output == defaults,
00373                         "Default values for strptime() are incorrect;"
00374                         " %s != %s" % (strp_output, defaults))

Here is the call graph for this function:

Definition at line 375 of file test_strptime.py.

00375 
00376     def test_escaping(self):
00377         # Make sure all characters that have regex significance are escaped.
00378         # Parentheses are in a purposeful order; will cause an error of
00379         # unbalanced parentheses when the regex is compiled if they are not
00380         # escaped.
00381         # Test instigated by bug #796149 .
00382         need_escaping = ".^$*+?{}\[]|)("
00383         self.assertTrue(_strptime._strptime_time(need_escaping, need_escaping))

Here is the call graph for this function:

Definition at line 276 of file test_strptime.py.

00276 
00277     def test_fraction(self):
00278         # Test microseconds
00279         import datetime
00280         d = datetime.datetime(2012, 12, 20, 12, 34, 56, 78987)
00281         tup, frac = _strptime._strptime(str(d), format="%Y-%m-%d %H:%M:%S.%f")
00282         self.assertEqual(frac, d.microsecond)

Here is the call graph for this function:

Definition at line 259 of file test_strptime.py.

00259 
00260     def test_hour(self):
00261         # Test hour directives
00262         self.helper('H', 3)
00263         strf_output = time.strftime("%I %p", self.time_tuple)
00264         strp_output = _strptime._strptime_time(strf_output, "%I %p")
00265         self.assertTrue(strp_output[3] == self.time_tuple[3],
00266                         "testing of '%%I %%p' directive failed; '%s' -> %s != %s" %
00267                          (strf_output, strp_output[3], self.time_tuple[3]))

Here is the call graph for this function:

Definition at line 288 of file test_strptime.py.

00288 
00289     def test_julian(self):
00290         # Test julian directives
00291         self.helper('j', 7)

Here is the call graph for this function:

Definition at line 268 of file test_strptime.py.

00268 
00269     def test_minute(self):
00270         # Test minute directives
00271         self.helper('M', 4)

Here is the call graph for this function:

Definition at line 250 of file test_strptime.py.

00250 
00251     def test_month(self):
00252         # Test for month directives
00253         for directive in ('B', 'b', 'm'):
00254             self.helper(directive, 1)

Here is the call graph for this function:

Definition at line 349 of file test_strptime.py.

00349 
00350     def test_percent(self):
00351         # Make sure % signs are handled properly
00352         strf_output = time.strftime("%m %% %Y", self.time_tuple)
00353         strp_output = _strptime._strptime_time(strf_output, "%m %% %Y")
00354         self.assertTrue(strp_output[0] == self.time_tuple[0] and
00355                          strp_output[1] == self.time_tuple[1],
00356                         "handling of percent sign failed")

Here is the call graph for this function:

Definition at line 272 of file test_strptime.py.

00272 
00273     def test_second(self):
00274         # Test second directives
00275         self.helper('S', 5)

Here is the call graph for this function:

Definition at line 344 of file test_strptime.py.

00344 
00345     def test_time(self):
00346         # Test %X directive
00347         for position in range(3,6):
00348             self.helper('X', position)

Here is the call graph for this function:

Definition at line 292 of file test_strptime.py.

00292 
00293     def test_timezone(self):
00294         # Test timezone directives.
00295         # When gmtime() is used with %Z, entire result of strftime() is empty.
00296         # Check for equal timezone names deals with bad locale info when this
00297         # occurs; first found in FreeBSD 4.4.
00298         strp_output = _strptime._strptime_time("UTC", "%Z")
00299         self.assertEqual(strp_output.tm_isdst, 0)
00300         strp_output = _strptime._strptime_time("GMT", "%Z")
00301         self.assertEqual(strp_output.tm_isdst, 0)
00302         time_tuple = time.localtime()
00303         strf_output = time.strftime("%Z")  #UTC does not have a timezone
00304         strp_output = _strptime._strptime_time(strf_output, "%Z")
00305         locale_time = _strptime.LocaleTime()
00306         if time.tzname[0] != time.tzname[1] or not time.daylight:
00307             self.assertTrue(strp_output[8] == time_tuple[8],
00308                             "timezone check failed; '%s' -> %s != %s" %
00309                              (strf_output, strp_output[8], time_tuple[8]))
00310         else:
00311             self.assertTrue(strp_output[8] == -1,
00312                             "LocaleTime().timezone has duplicate values and "
00313                              "time.daylight but timezone value not set to -1")

Here is the call graph for this function:

Definition at line 224 of file test_strptime.py.

00224 
00225     def test_unconverteddata(self):
00226         # Check ValueError is raised when there is unconverted data
00227         self.assertRaises(ValueError, _strptime._strptime_time, "10 12", "%m")

Here is the call graph for this function:

Definition at line 209 of file test_strptime.py.

00209 
00210     def test_ValueError(self):
00211         # Make sure ValueError is raised when match fails or format is bad
00212         self.assertRaises(ValueError, _strptime._strptime_time, data_string="%d",
00213                           format="%A")
00214         for bad_format in ("%", "% ", "%e"):
00215             try:
00216                 _strptime._strptime_time("2005", bad_format)
00217             except ValueError:
00218                 continue
00219             except Exception as err:
00220                 self.fail("'%s' raised %s, not ValueError" %
00221                             (bad_format, err.__class__.__name__))
00222             else:
00223                 self.fail("'%s' did not raise ValueError" % bad_format)

Here is the call graph for this function:

Definition at line 283 of file test_strptime.py.

00283 
00284     def test_weekday(self):
00285         # Test weekday directives
00286         for directive in ('A', 'a', 'w'):
00287             self.helper(directive,6)

Here is the call graph for this function:

Definition at line 237 of file test_strptime.py.

00237 
00238     def test_year(self):
00239         # Test that the year is handled properly
00240         for directive in ('y', 'Y'):
00241             self.helper(directive, 0)
00242         # Must also make sure %y values are correct for bounds set by Open Group
00243         for century, bounds in ((1900, ('69', '99')), (2000, ('00', '68'))):
00244             for bound in bounds:
00245                 strp_output = _strptime._strptime_time(bound, '%y')
00246                 expected_result = century + int(bound)
00247                 self.assertTrue(strp_output[0] == expected_result,
00248                                 "'y' test failed; passed in '%s' "
00249                                 "and returned '%s'" % (bound, strp_output[0]))

Here is the call graph for this function:


Member Data Documentation

Definition at line 207 of file test_strptime.py.


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