Back to index

python3.2  3.2.2
Public Member Functions
test.test_http_cookiejar.DateTimeTests Class Reference

List of all members.

Public Member Functions

def test_time2isoz
def test_http2time
def test_http2time_formats
def test_http2time_garbage

Detailed Description

Definition at line 18 of file test_http_cookiejar.py.


Member Function Documentation

Definition at line 34 of file test_http_cookiejar.py.

00034 
00035     def test_http2time(self):
00036         def parse_date(text):
00037             return time.gmtime(http2time(text))[:6]
00038 
00039         self.assertEqual(parse_date("01 Jan 2001"), (2001, 1, 1, 0, 0, 0.0))
00040 
00041         # this test will break around year 2070
00042         self.assertEqual(parse_date("03-Feb-20"), (2020, 2, 3, 0, 0, 0.0))
00043 
00044         # this test will break around year 2048
00045         self.assertEqual(parse_date("03-Feb-98"), (1998, 2, 3, 0, 0, 0.0))

Here is the call graph for this function:

Definition at line 46 of file test_http_cookiejar.py.

00046 
00047     def test_http2time_formats(self):
00048         # test http2time for supported dates.  Test cases with 2 digit year
00049         # will probably break in year 2044.
00050         tests = [
00051          'Thu, 03 Feb 1994 00:00:00 GMT',  # proposed new HTTP format
00052          'Thursday, 03-Feb-94 00:00:00 GMT',  # old rfc850 HTTP format
00053          'Thursday, 03-Feb-1994 00:00:00 GMT',  # broken rfc850 HTTP format
00054 
00055          '03 Feb 1994 00:00:00 GMT',  # HTTP format (no weekday)
00056          '03-Feb-94 00:00:00 GMT',  # old rfc850 (no weekday)
00057          '03-Feb-1994 00:00:00 GMT',  # broken rfc850 (no weekday)
00058          '03-Feb-1994 00:00 GMT',  # broken rfc850 (no weekday, no seconds)
00059          '03-Feb-1994 00:00',  # broken rfc850 (no weekday, no seconds, no tz)
00060 
00061          '03-Feb-94',  # old rfc850 HTTP format (no weekday, no time)
00062          '03-Feb-1994',  # broken rfc850 HTTP format (no weekday, no time)
00063          '03 Feb 1994',  # proposed new HTTP format (no weekday, no time)
00064 
00065          # A few tests with extra space at various places
00066          '  03   Feb   1994  0:00  ',
00067          '  03-Feb-1994  ',
00068         ]
00069 
00070         test_t = 760233600  # assume broken POSIX counting of seconds
00071         result = time2isoz(test_t)
00072         expected = "1994-02-03 00:00:00Z"
00073         self.assertEqual(result, expected,
00074                          "%s  =>  '%s' (%s)" % (test_t, result, expected))
00075 
00076         for s in tests:
00077             t = http2time(s)
00078             t2 = http2time(s.lower())
00079             t3 = http2time(s.upper())
00080 
00081             self.assertTrue(t == t2 == t3 == test_t,
00082                          "'%s'  =>  %s, %s, %s (%s)" % (s, t, t2, t3, test_t))

Here is the call graph for this function:

Definition at line 83 of file test_http_cookiejar.py.

00083 
00084     def test_http2time_garbage(self):
00085         for test in [
00086             '',
00087             'Garbage',
00088             'Mandag 16. September 1996',
00089             '01-00-1980',
00090             '01-13-1980',
00091             '00-01-1980',
00092             '32-01-1980',
00093             '01-01-1980 25:00:00',
00094             '01-01-1980 00:61:00',
00095             '01-01-1980 00:00:62',
00096             ]:
00097             self.assertTrue(http2time(test) is None,
00098                          "http2time(%s) is not None\n"
00099                          "http2time(test) %s" % (test, http2time(test))
00100                          )
00101 

Here is the call graph for this function:

Definition at line 20 of file test_http_cookiejar.py.

00020 
00021     def test_time2isoz(self):
00022         base = 1019227000
00023         day = 24*3600
00024         self.assertEqual(time2isoz(base), "2002-04-19 14:36:40Z")
00025         self.assertEqual(time2isoz(base+day), "2002-04-20 14:36:40Z")
00026         self.assertEqual(time2isoz(base+2*day), "2002-04-21 14:36:40Z")
00027         self.assertEqual(time2isoz(base+3*day), "2002-04-22 14:36:40Z")
00028 
00029         az = time2isoz()
00030         bz = time2isoz(500000)
00031         for text in (az, bz):
00032             self.assertTrue(re.search(r"^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$", text),
00033                             "bad time2isoz format: %s %s" % (az, bz))

Here is the call graph for this function:


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