Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_time.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 2bca2cee79a1 |
| children | 8c2635afbfe1 |
| rev | line source |
|---|---|
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
24322
diff
changeset
|
1 from test import test_support |
|
4612
4de05cbf5ad1
test of time module. not terribly fancy, but it does touch every
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
2 import time |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
3 import unittest |
|
69169
1320f29bcf98
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
68256
diff
changeset
|
4 import sys |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
5 |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
6 |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
7 class TimeTestCase(unittest.TestCase): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
8 |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
9 def setUp(self): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
10 self.t = time.time() |
|
4612
4de05cbf5ad1
test of time module. not terribly fancy, but it does touch every
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
11 |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
12 def test_data_attributes(self): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
13 time.altzone |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
14 time.daylight |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
15 time.timezone |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
16 time.tzname |
|
4612
4de05cbf5ad1
test of time module. not terribly fancy, but it does touch every
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
17 |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
18 def test_clock(self): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
19 time.clock() |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
20 |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
21 def test_conversions(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
22 self.assertTrue(time.ctime(self.t) |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
23 == time.asctime(time.localtime(self.t))) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
24 self.assertTrue(long(time.mktime(time.localtime(self.t))) |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
25 == long(self.t)) |
|
4612
4de05cbf5ad1
test of time module. not terribly fancy, but it does touch every
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
26 |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
27 def test_sleep(self): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
28 time.sleep(1.2) |
|
4612
4de05cbf5ad1
test of time module. not terribly fancy, but it does touch every
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
29 |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
30 def test_strftime(self): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
31 tt = time.gmtime(self.t) |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
32 for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I', |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
33 'j', 'm', 'M', 'p', 'S', |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
34 'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
35 format = ' %' + directive |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
36 try: |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
37 time.strftime(format, tt) |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
38 except ValueError: |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
39 self.fail('conversion specifier: %r failed.' % format) |
|
4612
4de05cbf5ad1
test of time module. not terribly fancy, but it does touch every
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
40 |
|
69169
1320f29bcf98
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
68256
diff
changeset
|
41 # Issue #10762: Guard against invalid/non-supported format string |
|
1320f29bcf98
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
68256
diff
changeset
|
42 # so that Python don't crash (Windows crashes when the format string |
|
1320f29bcf98
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
68256
diff
changeset
|
43 # input to [w]strftime is not kosher. |
|
1320f29bcf98
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
68256
diff
changeset
|
44 if sys.platform.startswith('win'): |
|
1320f29bcf98
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
68256
diff
changeset
|
45 with self.assertRaises(ValueError): |
|
1320f29bcf98
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
68256
diff
changeset
|
46 time.strftime('%f') |
|
1320f29bcf98
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
68256
diff
changeset
|
47 |
|
31608
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
48 def test_strftime_bounds_checking(self): |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
49 # Make sure that strftime() checks the bounds of the various parts |
|
39114
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
50 #of the time tuple (0 is valid for *all* values). |
|
31608
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
51 |
|
39114
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
52 # Check year [1900, max(int)] |
|
31608
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
53 self.assertRaises(ValueError, time.strftime, '', |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
54 (1899, 1, 1, 0, 0, 0, 0, 1, -1)) |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
55 if time.accept2dyear: |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
56 self.assertRaises(ValueError, time.strftime, '', |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
57 (-1, 1, 1, 0, 0, 0, 0, 1, -1)) |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
58 self.assertRaises(ValueError, time.strftime, '', |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
59 (100, 1, 1, 0, 0, 0, 0, 1, -1)) |
|
39114
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
60 # Check month [1, 12] + zero support |
|
31608
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
61 self.assertRaises(ValueError, time.strftime, '', |
|
39114
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
62 (1900, -1, 1, 0, 0, 0, 0, 1, -1)) |
|
31608
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
63 self.assertRaises(ValueError, time.strftime, '', |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
64 (1900, 13, 1, 0, 0, 0, 0, 1, -1)) |
|
39114
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
65 # Check day of month [1, 31] + zero support |
|
31608
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
66 self.assertRaises(ValueError, time.strftime, '', |
|
39114
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
67 (1900, 1, -1, 0, 0, 0, 0, 1, -1)) |
|
31608
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
68 self.assertRaises(ValueError, time.strftime, '', |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
69 (1900, 1, 32, 0, 0, 0, 0, 1, -1)) |
|
39114
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
70 # Check hour [0, 23] |
|
31608
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
71 self.assertRaises(ValueError, time.strftime, '', |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
72 (1900, 1, 1, -1, 0, 0, 0, 1, -1)) |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
73 self.assertRaises(ValueError, time.strftime, '', |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
74 (1900, 1, 1, 24, 0, 0, 0, 1, -1)) |
|
39114
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
75 # Check minute [0, 59] |
|
31608
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
76 self.assertRaises(ValueError, time.strftime, '', |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
77 (1900, 1, 1, 0, -1, 0, 0, 1, -1)) |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
78 self.assertRaises(ValueError, time.strftime, '', |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
79 (1900, 1, 1, 0, 60, 0, 0, 1, -1)) |
|
39114
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
80 # Check second [0, 61] |
|
31608
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
81 self.assertRaises(ValueError, time.strftime, '', |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
82 (1900, 1, 1, 0, 0, -1, 0, 1, -1)) |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
83 # C99 only requires allowing for one leap second, but Python's docs say |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
84 # allow two leap seconds (0..61) |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
85 self.assertRaises(ValueError, time.strftime, '', |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
86 (1900, 1, 1, 0, 0, 62, 0, 1, -1)) |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
87 # No check for upper-bound day of week; |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
88 # value forced into range by a ``% 7`` calculation. |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
89 # Start check at -2 since gettmarg() increments value before taking |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
90 # modulo. |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
91 self.assertRaises(ValueError, time.strftime, '', |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
92 (1900, 1, 1, 0, 0, 0, -2, 1, -1)) |
|
39114
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
93 # Check day of the year [1, 366] + zero support |
|
31608
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
94 self.assertRaises(ValueError, time.strftime, '', |
|
39114
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
95 (1900, 1, 1, 0, 0, 0, 0, -1, -1)) |
|
31608
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
96 self.assertRaises(ValueError, time.strftime, '', |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
97 (1900, 1, 1, 0, 0, 0, 0, 367, -1)) |
|
ae8dbf500172
Have strftime() check its time tuple argument to make sure the tuple's values
Brett Cannon <bcannon@gmail.com>
parents:
28774
diff
changeset
|
98 |
|
39114
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
99 def test_default_values_for_zero(self): |
|
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
100 # Make sure that using all zeros uses the proper default values. |
|
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
101 # No test for daylight savings since strftime() does not change output |
|
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
102 # based on its value. |
|
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
103 expected = "2000 01 01 00 00 00 1 001" |
|
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
104 result = time.strftime("%Y %m %d %H %M %S %w %j", (0,)*9) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
56175
diff
changeset
|
105 self.assertEqual(expected, result) |
|
39114
979e390e2bb4
Fix bug #1520914. Starting in 2.4, time.strftime() began to check the bounds
Brett Cannon <bcannon@gmail.com>
parents:
38836
diff
changeset
|
106 |
|
24322
afe479a6235e
Pure Python strptime implementation by Brett Cannon. See SF patch 474274.
Guido van Rossum <guido@python.org>
parents:
23085
diff
changeset
|
107 def test_strptime(self): |
|
39878
7f6ddf555c12
Make output on test_strptime() be more verbose in face of failure. This is in
Brett Cannon <bcannon@gmail.com>
parents:
39114
diff
changeset
|
108 # Should be able to go round-trip from strftime to strptime without |
|
7f6ddf555c12
Make output on test_strptime() be more verbose in face of failure. This is in
Brett Cannon <bcannon@gmail.com>
parents:
39114
diff
changeset
|
109 # throwing an exception. |
|
24322
afe479a6235e
Pure Python strptime implementation by Brett Cannon. See SF patch 474274.
Guido van Rossum <guido@python.org>
parents:
23085
diff
changeset
|
110 tt = time.gmtime(self.t) |
|
afe479a6235e
Pure Python strptime implementation by Brett Cannon. See SF patch 474274.
Guido van Rossum <guido@python.org>
parents:
23085
diff
changeset
|
111 for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I', |
|
afe479a6235e
Pure Python strptime implementation by Brett Cannon. See SF patch 474274.
Guido van Rossum <guido@python.org>
parents:
23085
diff
changeset
|
112 'j', 'm', 'M', 'p', 'S', |
|
afe479a6235e
Pure Python strptime implementation by Brett Cannon. See SF patch 474274.
Guido van Rossum <guido@python.org>
parents:
23085
diff
changeset
|
113 'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'): |
|
39878
7f6ddf555c12
Make output on test_strptime() be more verbose in face of failure. This is in
Brett Cannon <bcannon@gmail.com>
parents:
39114
diff
changeset
|
114 format = '%' + directive |
|
7f6ddf555c12
Make output on test_strptime() be more verbose in face of failure. This is in
Brett Cannon <bcannon@gmail.com>
parents:
39114
diff
changeset
|
115 strf_output = time.strftime(format, tt) |
|
24322
afe479a6235e
Pure Python strptime implementation by Brett Cannon. See SF patch 474274.
Guido van Rossum <guido@python.org>
parents:
23085
diff
changeset
|
116 try: |
|
39878
7f6ddf555c12
Make output on test_strptime() be more verbose in face of failure. This is in
Brett Cannon <bcannon@gmail.com>
parents:
39114
diff
changeset
|
117 time.strptime(strf_output, format) |
|
24322
afe479a6235e
Pure Python strptime implementation by Brett Cannon. See SF patch 474274.
Guido van Rossum <guido@python.org>
parents:
23085
diff
changeset
|
118 except ValueError: |
|
39878
7f6ddf555c12
Make output on test_strptime() be more verbose in face of failure. This is in
Brett Cannon <bcannon@gmail.com>
parents:
39114
diff
changeset
|
119 self.fail("conversion specifier %r failed with '%s' input." % |
|
7f6ddf555c12
Make output on test_strptime() be more verbose in face of failure. This is in
Brett Cannon <bcannon@gmail.com>
parents:
39114
diff
changeset
|
120 (format, strf_output)) |
|
24322
afe479a6235e
Pure Python strptime implementation by Brett Cannon. See SF patch 474274.
Guido van Rossum <guido@python.org>
parents:
23085
diff
changeset
|
121 |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
122 def test_asctime(self): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
123 time.asctime(time.gmtime(self.t)) |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
124 self.assertRaises(TypeError, time.asctime, 0) |
|
67281
e28868cf9825
Merged revisions 87663 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
39878
diff
changeset
|
125 self.assertRaises(TypeError, time.asctime, ()) |
|
e28868cf9825
Merged revisions 87663 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
39878
diff
changeset
|
126 # XXX: Posix compiant asctime should refuse to convert |
|
e28868cf9825
Merged revisions 87663 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
39878
diff
changeset
|
127 # year > 9999, but Linux implementation does not. |
|
e28868cf9825
Merged revisions 87663 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
39878
diff
changeset
|
128 # self.assertRaises(ValueError, time.asctime, |
|
e28868cf9825
Merged revisions 87663 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
39878
diff
changeset
|
129 # (12345, 1, 0, 0, 0, 0, 0, 0, 0)) |
|
e28868cf9825
Merged revisions 87663 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
39878
diff
changeset
|
130 # XXX: For now, just make sure we don't have a crash: |
|
e28868cf9825
Merged revisions 87663 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
39878
diff
changeset
|
131 try: |
|
67307
245359382b0f
Issue 10814: time.asctime test will now use a valid day with out of range year.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67280
diff
changeset
|
132 time.asctime((12345, 1, 1, 0, 0, 0, 0, 1, 0)) |
|
67281
e28868cf9825
Merged revisions 87663 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
39878
diff
changeset
|
133 except ValueError: |
|
e28868cf9825
Merged revisions 87663 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
39878
diff
changeset
|
134 pass |
|
4612
4de05cbf5ad1
test of time module. not terribly fancy, but it does touch every
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
135 |
|
66884
ac8da5578493
Merged revisions 87222 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
136 @unittest.skipIf(not hasattr(time, "tzset"), |
|
ac8da5578493
Merged revisions 87222 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66348
diff
changeset
|
137 "time module has no attribute tzset") |
|
28299
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
138 def test_tzset(self): |
|
28300
9602c664ed7a
If time.tzset doesn't exist, don't test it.
Guido van Rossum <guido@python.org>
parents:
28299
diff
changeset
|
139 |
|
28299
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
140 from os import environ |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
141 |
|
28774
c9bee11eaa8b
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28579
diff
changeset
|
142 # Epoch time of midnight Dec 25th 2002. Never DST in northern |
|
28299
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
143 # hemisphere. |
|
28774
c9bee11eaa8b
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28579
diff
changeset
|
144 xmas2002 = 1040774400.0 |
|
28299
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
145 |
|
28579
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
146 # These formats are correct for 2002, and possibly future years |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
147 # This format is the 'standard' as documented at: |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
148 # http://www.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap08.html |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
149 # They are also documented in the tzset(3) man page on most Unix |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
150 # systems. |
|
28774
c9bee11eaa8b
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28579
diff
changeset
|
151 eastern = 'EST+05EDT,M4.1.0,M10.5.0' |
|
28579
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
152 victoria = 'AEST-10AEDT-11,M10.5.0,M3.5.0' |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
153 utc='UTC+0' |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
154 |
|
28299
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
155 org_TZ = environ.get('TZ',None) |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
156 try: |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
157 # Make sure we can switch to UTC time and results are correct |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
158 # Note that unknown timezones default to UTC. |
|
28579
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
159 # Note that altzone is undefined in UTC, as there is no DST |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
160 environ['TZ'] = eastern |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
161 time.tzset() |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
162 environ['TZ'] = utc |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
163 time.tzset() |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
164 self.assertEqual( |
|
28579
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
165 time.gmtime(xmas2002), time.localtime(xmas2002) |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
166 ) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
167 self.assertEqual(time.daylight, 0) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
168 self.assertEqual(time.timezone, 0) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
169 self.assertEqual(time.localtime(xmas2002).tm_isdst, 0) |
|
28299
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
170 |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
171 # Make sure we can switch to US/Eastern |
|
28579
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
172 environ['TZ'] = eastern |
|
28299
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
173 time.tzset() |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
174 self.assertNotEqual(time.gmtime(xmas2002), time.localtime(xmas2002)) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
175 self.assertEqual(time.tzname, ('EST', 'EDT')) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
176 self.assertEqual(len(time.tzname), 2) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
177 self.assertEqual(time.daylight, 1) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
178 self.assertEqual(time.timezone, 18000) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
179 self.assertEqual(time.altzone, 14400) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
180 self.assertEqual(time.localtime(xmas2002).tm_isdst, 0) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
181 self.assertEqual(len(time.tzname), 2) |
|
28299
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
182 |
|
28579
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
183 # Now go to the southern hemisphere. |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
184 environ['TZ'] = victoria |
|
28299
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
185 time.tzset() |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
186 self.assertNotEqual(time.gmtime(xmas2002), time.localtime(xmas2002)) |
|
73888
2bca2cee79a1
Issue #11886: workaround an OS bug (time zone data) in test_time
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69169
diff
changeset
|
187 |
|
2bca2cee79a1
Issue #11886: workaround an OS bug (time zone data) in test_time
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69169
diff
changeset
|
188 # Issue #11886: Australian Eastern Standard Time (UTC+10) is called |
|
2bca2cee79a1
Issue #11886: workaround an OS bug (time zone data) in test_time
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69169
diff
changeset
|
189 # "EST" (as Eastern Standard Time, UTC-5) instead of "AEST" on some |
|
2bca2cee79a1
Issue #11886: workaround an OS bug (time zone data) in test_time
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69169
diff
changeset
|
190 # operating systems (e.g. FreeBSD), which is wrong. See for example |
|
2bca2cee79a1
Issue #11886: workaround an OS bug (time zone data) in test_time
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69169
diff
changeset
|
191 # this bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=93810 |
|
2bca2cee79a1
Issue #11886: workaround an OS bug (time zone data) in test_time
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69169
diff
changeset
|
192 self.assertIn(time.tzname[0], ('AEST' 'EST'), time.tzname[0]) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
193 self.assertTrue(time.tzname[1] == 'AEDT', str(time.tzname[1])) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
194 self.assertEqual(len(time.tzname), 2) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
195 self.assertEqual(time.daylight, 1) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
196 self.assertEqual(time.timezone, -36000) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
197 self.assertEqual(time.altzone, -39600) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
198 self.assertEqual(time.localtime(xmas2002).tm_isdst, 1) |
|
28299
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
199 |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
200 finally: |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
201 # Repair TZ environment variable in case any other tests |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
202 # rely on it. |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
203 if org_TZ is not None: |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
204 environ['TZ'] = org_TZ |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
205 elif environ.has_key('TZ'): |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
206 del environ['TZ'] |
|
28579
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
207 time.tzset() |
|
28774
c9bee11eaa8b
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28579
diff
changeset
|
208 |
|
32388
5cf507b64f31
Bug 975996: Add _PyTime_DoubleToTimet to C API
Tim Peters <tim.peters@gmail.com>
parents:
31608
diff
changeset
|
209 def test_insane_timestamps(self): |
|
5cf507b64f31
Bug 975996: Add _PyTime_DoubleToTimet to C API
Tim Peters <tim.peters@gmail.com>
parents:
31608
diff
changeset
|
210 # It's possible that some platform maps time_t to double, |
|
5cf507b64f31
Bug 975996: Add _PyTime_DoubleToTimet to C API
Tim Peters <tim.peters@gmail.com>
parents:
31608
diff
changeset
|
211 # and that this test will fail there. This test should |
|
5cf507b64f31
Bug 975996: Add _PyTime_DoubleToTimet to C API
Tim Peters <tim.peters@gmail.com>
parents:
31608
diff
changeset
|
212 # exempt such platforms (provided they return reasonable |
|
5cf507b64f31
Bug 975996: Add _PyTime_DoubleToTimet to C API
Tim Peters <tim.peters@gmail.com>
parents:
31608
diff
changeset
|
213 # results!). |
|
5cf507b64f31
Bug 975996: Add _PyTime_DoubleToTimet to C API
Tim Peters <tim.peters@gmail.com>
parents:
31608
diff
changeset
|
214 for func in time.ctime, time.gmtime, time.localtime: |
|
5cf507b64f31
Bug 975996: Add _PyTime_DoubleToTimet to C API
Tim Peters <tim.peters@gmail.com>
parents:
31608
diff
changeset
|
215 for unreasonable in -1e200, 1e200: |
|
5cf507b64f31
Bug 975996: Add _PyTime_DoubleToTimet to C API
Tim Peters <tim.peters@gmail.com>
parents:
31608
diff
changeset
|
216 self.assertRaises(ValueError, func, unreasonable) |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
217 |
|
32939
582eb51b8492
allow ctime(), gmtime(), and localtime() to take None as equivalent to an omitted arg
Fred Drake <fdrake@acm.org>
parents:
32388
diff
changeset
|
218 def test_ctime_without_arg(self): |
|
582eb51b8492
allow ctime(), gmtime(), and localtime() to take None as equivalent to an omitted arg
Fred Drake <fdrake@acm.org>
parents:
32388
diff
changeset
|
219 # Not sure how to check the values, since the clock could tick |
|
582eb51b8492
allow ctime(), gmtime(), and localtime() to take None as equivalent to an omitted arg
Fred Drake <fdrake@acm.org>
parents:
32388
diff
changeset
|
220 # at any time. Make sure these are at least accepted and |
|
582eb51b8492
allow ctime(), gmtime(), and localtime() to take None as equivalent to an omitted arg
Fred Drake <fdrake@acm.org>
parents:
32388
diff
changeset
|
221 # don't raise errors. |
|
582eb51b8492
allow ctime(), gmtime(), and localtime() to take None as equivalent to an omitted arg
Fred Drake <fdrake@acm.org>
parents:
32388
diff
changeset
|
222 time.ctime() |
|
582eb51b8492
allow ctime(), gmtime(), and localtime() to take None as equivalent to an omitted arg
Fred Drake <fdrake@acm.org>
parents:
32388
diff
changeset
|
223 time.ctime(None) |
|
582eb51b8492
allow ctime(), gmtime(), and localtime() to take None as equivalent to an omitted arg
Fred Drake <fdrake@acm.org>
parents:
32388
diff
changeset
|
224 |
|
582eb51b8492
allow ctime(), gmtime(), and localtime() to take None as equivalent to an omitted arg
Fred Drake <fdrake@acm.org>
parents:
32388
diff
changeset
|
225 def test_gmtime_without_arg(self): |
|
38836
77b01c933308
Try to narrow window of failure on slow/busy boxes (ppc64 buildbot)
Neal Norwitz <nnorwitz@gmail.com>
parents:
32939
diff
changeset
|
226 gt0 = time.gmtime() |
|
77b01c933308
Try to narrow window of failure on slow/busy boxes (ppc64 buildbot)
Neal Norwitz <nnorwitz@gmail.com>
parents:
32939
diff
changeset
|
227 gt1 = time.gmtime(None) |
|
77b01c933308
Try to narrow window of failure on slow/busy boxes (ppc64 buildbot)
Neal Norwitz <nnorwitz@gmail.com>
parents:
32939
diff
changeset
|
228 t0 = time.mktime(gt0) |
|
77b01c933308
Try to narrow window of failure on slow/busy boxes (ppc64 buildbot)
Neal Norwitz <nnorwitz@gmail.com>
parents:
32939
diff
changeset
|
229 t1 = time.mktime(gt1) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
230 self.assertTrue(0 <= (t1-t0) < 0.2) |
|
32939
582eb51b8492
allow ctime(), gmtime(), and localtime() to take None as equivalent to an omitted arg
Fred Drake <fdrake@acm.org>
parents:
32388
diff
changeset
|
231 |
|
582eb51b8492
allow ctime(), gmtime(), and localtime() to take None as equivalent to an omitted arg
Fred Drake <fdrake@acm.org>
parents:
32388
diff
changeset
|
232 def test_localtime_without_arg(self): |
|
38836
77b01c933308
Try to narrow window of failure on slow/busy boxes (ppc64 buildbot)
Neal Norwitz <nnorwitz@gmail.com>
parents:
32939
diff
changeset
|
233 lt0 = time.localtime() |
|
77b01c933308
Try to narrow window of failure on slow/busy boxes (ppc64 buildbot)
Neal Norwitz <nnorwitz@gmail.com>
parents:
32939
diff
changeset
|
234 lt1 = time.localtime(None) |
|
77b01c933308
Try to narrow window of failure on slow/busy boxes (ppc64 buildbot)
Neal Norwitz <nnorwitz@gmail.com>
parents:
32939
diff
changeset
|
235 t0 = time.mktime(lt0) |
|
77b01c933308
Try to narrow window of failure on slow/busy boxes (ppc64 buildbot)
Neal Norwitz <nnorwitz@gmail.com>
parents:
32939
diff
changeset
|
236 t1 = time.mktime(lt1) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
39878
diff
changeset
|
237 self.assertTrue(0 <= (t1-t0) < 0.2) |
|
32939
582eb51b8492
allow ctime(), gmtime(), and localtime() to take None as equivalent to an omitted arg
Fred Drake <fdrake@acm.org>
parents:
32388
diff
changeset
|
238 |
|
67948
7a89f4a73d1a
Merged revisions 87919 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67307
diff
changeset
|
239 def test_mktime(self): |
|
7a89f4a73d1a
Merged revisions 87919 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67307
diff
changeset
|
240 # Issue #1726687 |
|
7a89f4a73d1a
Merged revisions 87919 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67307
diff
changeset
|
241 for t in (-2, -1, 0, 1): |
|
7a89f4a73d1a
Merged revisions 87919 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67307
diff
changeset
|
242 try: |
|
7a89f4a73d1a
Merged revisions 87919 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67307
diff
changeset
|
243 tt = time.localtime(t) |
|
7a89f4a73d1a
Merged revisions 87919 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67307
diff
changeset
|
244 except (OverflowError, ValueError): |
|
7a89f4a73d1a
Merged revisions 87919 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67307
diff
changeset
|
245 pass |
|
67950
907f3879235a
Merged revisions 87921 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67948
diff
changeset
|
246 else: |
|
907f3879235a
Merged revisions 87921 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67948
diff
changeset
|
247 self.assertEqual(time.mktime(tt), t) |
|
67948
7a89f4a73d1a
Merged revisions 87919 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67307
diff
changeset
|
248 |
|
32939
582eb51b8492
allow ctime(), gmtime(), and localtime() to take None as equivalent to an omitted arg
Fred Drake <fdrake@acm.org>
parents:
32388
diff
changeset
|
249 |
|
20013
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17912
diff
changeset
|
250 def test_main(): |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17912
diff
changeset
|
251 test_support.run_unittest(TimeTestCase) |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17912
diff
changeset
|
252 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17912
diff
changeset
|
253 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17912
diff
changeset
|
254 if __name__ == "__main__": |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17912
diff
changeset
|
255 test_main() |
