Back to index

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

List of all members.

Public Member Functions

def setUp
def test_pattern
def test_pattern_escaping
def test_compile
def test_blankpattern
def test_matching_with_escapes
def test_locale_data_w_regex_metacharacters
def test_whitespace_substitution

Public Attributes

 time_re
 locale_time

Detailed Description

Tests for TimeRE.

Definition at line 111 of file test_strptime.py.


Member Function Documentation

Construct generic TimeRE object.

Definition at line 114 of file test_strptime.py.

00114 
00115     def setUp(self):
00116         """Construct generic TimeRE object."""
00117         self.time_re = _strptime.TimeRE()
00118         self.locale_time = _strptime.LocaleTime()

Here is the caller graph for this function:

Definition at line 166 of file test_strptime.py.

00166 
00167     def test_blankpattern(self):
00168         # Make sure when tuple or something has no values no regex is generated.
00169         # Fixes bug #661354
00170         test_locale = _strptime.LocaleTime()
00171         test_locale.timezone = (frozenset(), frozenset())
00172         self.assertTrue(_strptime.TimeRE(test_locale).pattern("%Z") == '',
00173                         "with timezone == ('',''), TimeRE().pattern('%Z') != ''")

Here is the call graph for this function:

Definition at line 140 of file test_strptime.py.

00140 
00141     def test_compile(self):
00142         # Check that compiled regex is correct
00143         found = self.time_re.compile(r"%A").match(self.locale_time.f_weekday[6])
00144         self.assertTrue(found and found.group('A') == self.locale_time.f_weekday[6],
00145                         "re object for '%A' failed")
00146         compiled = self.time_re.compile(r"%a %b")
00147         found = compiled.match("%s %s" % (self.locale_time.a_weekday[4],
00148                                self.locale_time.a_month[4]))
00149         self.assertTrue(found,
00150             "Match failed with '%s' regex and '%s' string" %
00151              (compiled.pattern, "%s %s" % (self.locale_time.a_weekday[4],
00152                                            self.locale_time.a_month[4])))
00153         self.assertTrue(found.group('a') == self.locale_time.a_weekday[4] and
00154                          found.group('b') == self.locale_time.a_month[4],
00155                         "re object couldn't find the abbreviated weekday month in "
00156                          "'%s' using '%s'; group 'a' = '%s', group 'b' = %s'" %
00157                          (found.string, found.re.pattern, found.group('a'),
00158                           found.group('b')))
00159         for directive in ('a','A','b','B','c','d','H','I','j','m','M','p','S',
00160                           'U','w','W','x','X','y','Y','Z','%'):
00161             compiled = self.time_re.compile("%" + directive)
00162             found = compiled.match(time.strftime("%" + directive))
00163             self.assertTrue(found, "Matching failed on '%s' using '%s' regex" %
00164                                     (time.strftime("%" + directive),
00165                                      compiled.pattern))

Here is the call graph for this function:

Definition at line 180 of file test_strptime.py.

00180 
00181     def test_locale_data_w_regex_metacharacters(self):
00182         # Check that if locale data contains regex metacharacters they are
00183         # escaped properly.
00184         # Discovered by bug #1039270 .
00185         locale_time = _strptime.LocaleTime()
00186         locale_time.timezone = (frozenset(("utc", "gmt",
00187                                             "Tokyo (standard time)")),
00188                                 frozenset("Tokyo (daylight time)"))
00189         time_re = _strptime.TimeRE(locale_time)
00190         self.assertTrue(time_re.compile("%Z").match("Tokyo (standard time)"),
00191                         "locale data that contains regex metacharacters is not"
00192                         " properly escaped")

Here is the call graph for this function:

Definition at line 174 of file test_strptime.py.

00174 
00175     def test_matching_with_escapes(self):
00176         # Make sure a format that requires escaping of characters works
00177         compiled_re = self.time_re.compile("\w+ %m")
00178         found = compiled_re.match("\w+ 10")
00179         self.assertTrue(found, "Escaping failed of format '\w+ 10'")

Here is the call graph for this function:

Definition at line 119 of file test_strptime.py.

00119 
00120     def test_pattern(self):
00121         # Test TimeRE.pattern
00122         pattern_string = self.time_re.pattern(r"%a %A %d")
00123         self.assertTrue(pattern_string.find(self.locale_time.a_weekday[2]) != -1,
00124                         "did not find abbreviated weekday in pattern string '%s'" %
00125                          pattern_string)
00126         self.assertTrue(pattern_string.find(self.locale_time.f_weekday[4]) != -1,
00127                         "did not find full weekday in pattern string '%s'" %
00128                          pattern_string)
00129         self.assertTrue(pattern_string.find(self.time_re['d']) != -1,
00130                         "did not find 'd' directive pattern string '%s'" %
00131                          pattern_string)

Here is the call graph for this function:

Definition at line 132 of file test_strptime.py.

00132 
00133     def test_pattern_escaping(self):
00134         # Make sure any characters in the format string that might be taken as
00135         # regex syntax is escaped.
00136         pattern_string = self.time_re.pattern("\d+")
00137         self.assertIn(r"\\d\+", pattern_string,
00138                       "%s does not have re characters escaped properly" %
00139                       pattern_string)

Here is the call graph for this function:

Definition at line 193 of file test_strptime.py.

00193 
00194     def test_whitespace_substitution(self):
00195         # When pattern contains whitespace, make sure it is taken into account
00196         # so as to not allow to subpatterns to end up next to each other and
00197         # "steal" characters from each other.
00198         pattern = self.time_re.pattern('%j %H')
00199         self.assertTrue(not re.match(pattern, "180"))
00200         self.assertTrue(re.match(pattern, "18 0"))
00201 

Here is the call graph for this function:


Member Data Documentation

Definition at line 117 of file test_strptime.py.

Definition at line 116 of file test_strptime.py.


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