[Python-checkins] python/dist/src/Lib/test test_strptime.py,1.2,1.3
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Thu, 22 Aug 2002 12:57:52 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv20518
Modified Files:
test_strptime.py
Log Message:
Standardize behavior: no docstrings in test functions; add a proper
test_main() that creates a suite and runs it. Don't mess with sys.path!!!
Index: test_strptime.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_strptime.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** test_strptime.py 8 Aug 2002 20:19:19 -0000 1.2
--- test_strptime.py 22 Aug 2002 19:57:50 -0000 1.3
***************
*** 1,10 ****
"""PyUnit testing against strptime >= 2.1.0."""
- import sys
- sys.path.append('..')
import unittest
import time
import locale
import re
import _strptime
--- 1,9 ----
"""PyUnit testing against strptime >= 2.1.0."""
import unittest
import time
import locale
import re
+ from test import test_support
import _strptime
***************
*** 13,17 ****
class LocaleTime_Tests(unittest.TestCase):
! """Contains all tests for _strptime.LocaleTime."""
def setUp(self):
--- 12,16 ----
class LocaleTime_Tests(unittest.TestCase):
! """Tests for _strptime.LocaleTime."""
def setUp(self):
***************
*** 31,51 ****
def test_weekday(self):
! """Make sure that full and abbreviated weekday names are correct in
! both string and position with tuple.
!
! """
self.compare_against_time(self.LT_ins.f_weekday, '%A', 6, "Testing of full weekday name failed")
self.compare_against_time(self.LT_ins.a_weekday, '%a', 6, "Testing of abbreviated weekday name failed")
def test_month(self):
! """Test full and abbreviated month names; both string and position
! within the tuple.
!
! """
self.compare_against_time(self.LT_ins.f_month, '%B', 1, "Testing against full month name failed")
self.compare_against_time(self.LT_ins.a_month, '%b', 1, "Testing against abbreviated month name failed")
def test_am_pm(self):
! """Make sure AM/PM representation done properly."""
strftime_output = time.strftime("%p", self.time_tuple)
self.failUnless(strftime_output in self.LT_ins.am_pm, "AM/PM representation not in tuple")
--- 30,46 ----
def test_weekday(self):
! # Make sure that full and abbreviated weekday names are correct in
! # both string and position with tuple
self.compare_against_time(self.LT_ins.f_weekday, '%A', 6, "Testing of full weekday name failed")
self.compare_against_time(self.LT_ins.a_weekday, '%a', 6, "Testing of abbreviated weekday name failed")
def test_month(self):
! # Test full and abbreviated month names; both string and position
! # within the tuple
self.compare_against_time(self.LT_ins.f_month, '%B', 1, "Testing against full month name failed")
self.compare_against_time(self.LT_ins.a_month, '%b', 1, "Testing against abbreviated month name failed")
def test_am_pm(self):
! # Make sure AM/PM representation done properly
strftime_output = time.strftime("%p", self.time_tuple)
self.failUnless(strftime_output in self.LT_ins.am_pm, "AM/PM representation not in tuple")
***************
*** 55,64 ****
def test_timezone(self):
! """Make sure timezone is correct."""
if time.strftime("%Z", self.time_tuple):
self.compare_against_time(self.LT_ins.timezone, '%Z', 8, "Testing against timezone failed")
def test_date_time(self):
! """Check that LC_date_time, LC_date, and LC_time are correct."""
strftime_output = time.strftime("%c", self.time_tuple)
self.failUnless(strftime_output == time.strftime(self.LT_ins.LC_date_time, self.time_tuple), "LC_date_time incorrect")
--- 50,59 ----
def test_timezone(self):
! # Make sure timezone is correct
if time.strftime("%Z", self.time_tuple):
self.compare_against_time(self.LT_ins.timezone, '%Z', 8, "Testing against timezone failed")
def test_date_time(self):
! # Check that LC_date_time, LC_date, and LC_time are correct
strftime_output = time.strftime("%c", self.time_tuple)
self.failUnless(strftime_output == time.strftime(self.LT_ins.LC_date_time, self.time_tuple), "LC_date_time incorrect")
***************
*** 69,77 ****
def test_lang(self):
! """Make sure lang is set."""
self.failUnless(self.LT_ins.lang in (locale.getdefaultlocale()[0], locale.getlocale(locale.LC_TIME)), "Setting of lang failed")
def test_by_hand_input(self):
! """Test passed-in initialization value checks."""
self.failUnless(_strptime.LocaleTime(f_weekday=range(7)), "Argument size check for f_weekday failed")
self.assertRaises(TypeError, _strptime.LocaleTime, f_weekday=range(8))
--- 64,72 ----
def test_lang(self):
! # Make sure lang is set
self.failUnless(self.LT_ins.lang in (locale.getdefaultlocale()[0], locale.getlocale(locale.LC_TIME)), "Setting of lang failed")
def test_by_hand_input(self):
! # Test passed-in initialization value checks
self.failUnless(_strptime.LocaleTime(f_weekday=range(7)), "Argument size check for f_weekday failed")
self.assertRaises(TypeError, _strptime.LocaleTime, f_weekday=range(8))
***************
*** 104,108 ****
def test_getitem(self):
! """Make sure that __getitem__ works properly."""
self.failUnless(self.time_re['m'], "Fetching 'm' directive (built-in) failed")
self.failUnless(self.time_re['b'], "Fetching 'b' directive (built w/ __tupleToRE) failed")
--- 99,103 ----
def test_getitem(self):
! # Make sure that __getitem__ works properly
self.failUnless(self.time_re['m'], "Fetching 'm' directive (built-in) failed")
self.failUnless(self.time_re['b'], "Fetching 'b' directive (built w/ __tupleToRE) failed")
***************
*** 114,118 ****
def test_pattern(self):
! """Test TimeRE.pattern."""
pattern_string = self.time_re.pattern(r"%a %A %d")
self.failUnless(pattern_string.find(self.locale_time.a_weekday[2]) != -1, "did not find abbreviated weekday in pattern string '%s'" % pattern_string)
--- 109,113 ----
def test_pattern(self):
! # Test TimeRE.pattern
pattern_string = self.time_re.pattern(r"%a %A %d")
self.failUnless(pattern_string.find(self.locale_time.a_weekday[2]) != -1, "did not find abbreviated weekday in pattern string '%s'" % pattern_string)
***************
*** 121,125 ****
def test_compile(self):
! """Check that compiled regex is correct."""
found = self.time_re.compile(r"%A").match(self.locale_time.f_weekday[6])
self.failUnless(found and found.group('A') == self.locale_time.f_weekday[6], "re object for '%A' failed")
--- 116,120 ----
def test_compile(self):
! # Check that compiled regex is correct
found = self.time_re.compile(r"%A").match(self.locale_time.f_weekday[6])
self.failUnless(found and found.group('A') == self.locale_time.f_weekday[6], "re object for '%A' failed")
***************
*** 143,151 ****
def test_TypeError(self):
! """Make sure ValueError is raised when match fails."""
self.assertRaises(ValueError,_strptime.strptime, data_string="%d", format="%A")
def test_returning_RE(self):
! """Make sure that an re can be returned."""
strp_output = _strptime.strptime(False, "%Y")
self.failUnless(isinstance(strp_output, type(re.compile(''))), "re object not returned correctly")
--- 138,146 ----
def test_TypeError(self):
! # Make sure ValueError is raised when match fails
self.assertRaises(ValueError,_strptime.strptime, data_string="%d", format="%A")
def test_returning_RE(self):
! # Make sure that an re can be returned
strp_output = _strptime.strptime(False, "%Y")
self.failUnless(isinstance(strp_output, type(re.compile(''))), "re object not returned correctly")
***************
*** 161,179 ****
def test_year(self):
! """Test that the year is handled properly."""
for directive in ('y', 'Y'):
self.helper(directive, 0)
def test_month(self):
! """Test for month directives."""
for directive in ('B', 'b', 'm'):
self.helper(directive, 1)
def test_day(self):
! """Test for day directives."""
self.helper('d', 2)
def test_hour(self):
! """Test hour directives."""
self.helper('H', 3)
strf_output = time.strftime("%I %p", self.time_tuple)
--- 156,174 ----
def test_year(self):
! # Test that the year is handled properly
for directive in ('y', 'Y'):
self.helper(directive, 0)
def test_month(self):
! # Test for month directives
for directive in ('B', 'b', 'm'):
self.helper(directive, 1)
def test_day(self):
! # Test for day directives
self.helper('d', 2)
def test_hour(self):
! # Test hour directives
self.helper('H', 3)
strf_output = time.strftime("%I %p", self.time_tuple)
***************
*** 182,207 ****
def test_minute(self):
! """Test minute directives."""
self.helper('M', 4)
def test_second(self):
! """Test second directives."""
self.helper('S', 5)
def test_weekday(self):
! """Test weekday directives."""
for directive in ('A', 'a', 'w'):
self.helper(directive,6)
def test_julian(self):
! """Test julian directives."""
self.helper('j', 7)
def test_timezone(self):
! """Test timezone directives.
!
! When gmtime() is used with %Z, entire result of strftime() is empty.
!
! """
time_tuple = time.localtime()
strf_output = time.strftime("%Z") #UTC does not have a timezone
--- 177,199 ----
def test_minute(self):
! # Test minute directives
self.helper('M', 4)
def test_second(self):
! # Test second directives
self.helper('S', 5)
def test_weekday(self):
! # Test weekday directives
for directive in ('A', 'a', 'w'):
self.helper(directive,6)
def test_julian(self):
! # Test julian directives
self.helper('j', 7)
def test_timezone(self):
! # Test timezone directives.
! # When gmtime() is used with %Z, entire result of strftime() is empty.
time_tuple = time.localtime()
strf_output = time.strftime("%Z") #UTC does not have a timezone
***************
*** 210,229 ****
def test_date_time(self):
! """*** Test %c directive. ***"""
for position in range(6):
self.helper('c', position)
def test_date(self):
! """*** Test %x directive. ***"""
for position in range(0,3):
self.helper('x', position)
def test_time(self):
! """*** Test %X directive. ***"""
for position in range(3,6):
self.helper('X', position)
def test_percent(self):
! """Make sure % signs are handled properly."""
strf_output = time.strftime("%m %% %Y", self.time_tuple)
strp_output = _strptime.strptime(strf_output, "%m %% %Y")
--- 202,221 ----
def test_date_time(self):
! # Test %c directive
for position in range(6):
self.helper('c', position)
def test_date(self):
! # Test %x directive
for position in range(0,3):
self.helper('x', position)
def test_time(self):
! # Test %X directive
for position in range(3,6):
self.helper('X', position)
def test_percent(self):
! # Make sure % signs are handled properly
strf_output = time.strftime("%m %% %Y", self.time_tuple)
strp_output = _strptime.strptime(strf_output, "%m %% %Y")
***************
*** 238,247 ****
def test_julianday_result(self):
! """Test julianday."""
result = _strptime.julianday(self.time_tuple[0], self.time_tuple[1], self.time_tuple[2])
self.failUnless(result == self.time_tuple[7], "julianday failed; %s != %s" % (result, self.time_tuple[7]))
def test_julianday_trigger(self):
! """Make sure julianday is called."""
strf_output = time.strftime("%Y-%m-%d", self.time_tuple)
strp_output = _strptime.strptime(strf_output, "%Y-%m-%d")
--- 230,239 ----
def test_julianday_result(self):
! # Test julianday
result = _strptime.julianday(self.time_tuple[0], self.time_tuple[1], self.time_tuple[2])
self.failUnless(result == self.time_tuple[7], "julianday failed; %s != %s" % (result, self.time_tuple[7]))
def test_julianday_trigger(self):
! # Make sure julianday is called
strf_output = time.strftime("%Y-%m-%d", self.time_tuple)
strp_output = _strptime.strptime(strf_output, "%Y-%m-%d")
***************
*** 249,253 ****
def test_gregorian_result(self):
! """Test gregorian."""
result = _strptime.gregorian(self.time_tuple[7], self.time_tuple[0])
comparison = [self.time_tuple[0], self.time_tuple[1], self.time_tuple[2]]
--- 241,245 ----
def test_gregorian_result(self):
! # Test gregorian
result = _strptime.gregorian(self.time_tuple[7], self.time_tuple[0])
comparison = [self.time_tuple[0], self.time_tuple[1], self.time_tuple[2]]
***************
*** 255,259 ****
def test_gregorian_trigger(self):
! """Test that gregorian() is triggered."""
strf_output = time.strftime("%j %Y", self.time_tuple)
strp_output = _strptime.strptime(strf_output, "%j %Y")
--- 247,251 ----
def test_gregorian_trigger(self):
! # Test that gregorian() is triggered
strf_output = time.strftime("%j %Y", self.time_tuple)
strp_output = _strptime.strptime(strf_output, "%j %Y")
***************
*** 261,265 ****
def test_dayofweek_result(self):
! """Test dayofweek."""
result = _strptime.dayofweek(self.time_tuple[0], self.time_tuple[1], self.time_tuple[2])
comparison = self.time_tuple[6]
--- 253,257 ----
def test_dayofweek_result(self):
! # Test dayofweek
result = _strptime.dayofweek(self.time_tuple[0], self.time_tuple[1], self.time_tuple[2])
comparison = self.time_tuple[6]
***************
*** 267,271 ****
def test_dayofweek_trigger(self):
! """Make sure dayofweek() gets triggered."""
strf_output = time.strftime("%Y-%m-%d", self.time_tuple)
strp_output = _strptime.strptime(strf_output, "%Y-%m-%d")
--- 259,263 ----
def test_dayofweek_trigger(self):
! # Make sure dayofweek() gets triggered
strf_output = time.strftime("%Y-%m-%d", self.time_tuple)
strp_output = _strptime.strptime(strf_output, "%Y-%m-%d")
***************
*** 273,279 ****
!
if __name__ == '__main__':
! unittest.main()
--- 265,277 ----
! def test_main():
! suite = unittest.TestSuite()
! suite.addTest(unittest.makeSuite(LocaleTime_Tests))
! suite.addTest(unittest.makeSuite(TimeRETests))
! suite.addTest(unittest.makeSuite(StrptimeTests))
! suite.addTest(unittest.makeSuite(FxnTests))
! test_support.run_suite(suite)
if __name__ == '__main__':
! test_main()