Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_time.py @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | c143e66e5efe |
| children | fdf907708f49 c7638be1e430 |
| rev | line source |
|---|---|
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
40644
diff
changeset
|
1 from test import 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 |
|
54442
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
4 import locale |
|
67350
1e62a0cee092
Issue #8013: time.asctime and time.ctime no longer call system asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67275
diff
changeset
|
5 import sysconfig |
|
69166
2ca1bc677a60
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
67949
diff
changeset
|
6 import sys |
|
67436
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
7 import warnings |
|
17912
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 class TimeTestCase(unittest.TestCase): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
10 |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
11 def setUp(self): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
12 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
|
13 |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
14 def test_data_attributes(self): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
15 time.altzone |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
16 time.daylight |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
17 time.timezone |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
18 time.tzname |
|
4612
4de05cbf5ad1
test of time module. not terribly fancy, but it does touch every
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
19 |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
20 def test_clock(self): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
21 time.clock() |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
22 |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
23 def test_conversions(self): |
|
67436
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
24 self.assertEqual(time.ctime(self.t), |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
25 time.asctime(time.localtime(self.t))) |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
26 self.assertEqual(int(time.mktime(time.localtime(self.t))), |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
27 int(self.t)) |
|
4612
4de05cbf5ad1
test of time module. not terribly fancy, but it does touch every
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
28 |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
29 def test_sleep(self): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
30 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
|
31 |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
32 def test_strftime(self): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
33 tt = time.gmtime(self.t) |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
34 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
|
35 'j', 'm', 'M', 'p', 'S', |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
36 'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
37 format = ' %' + directive |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
38 try: |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
39 time.strftime(format, tt) |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
40 except ValueError: |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
41 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
|
42 |
|
69166
2ca1bc677a60
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
67949
diff
changeset
|
43 # Issue #10762: Guard against invalid/non-supported format string |
|
2ca1bc677a60
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
67949
diff
changeset
|
44 # so that Python don't crash (Windows crashes when the format string |
|
2ca1bc677a60
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
67949
diff
changeset
|
45 # input to [w]strftime is not kosher. |
|
2ca1bc677a60
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
67949
diff
changeset
|
46 if sys.platform.startswith('win'): |
|
2ca1bc677a60
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
67949
diff
changeset
|
47 with self.assertRaises(ValueError): |
|
2ca1bc677a60
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
67949
diff
changeset
|
48 time.strftime('%f') |
|
2ca1bc677a60
Issue #10762: Guard against invalid/non-supported format string '%f' on Windows. Patch Santoso Wijaya.
Senthil Kumaran <orsenthil@gmail.com>
parents:
67949
diff
changeset
|
49 |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
50 def _bounds_checking(self, func=time.strftime): |
|
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 # Make sure that strftime() checks the bounds of the various parts |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
52 #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
|
53 |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
54 # The year field is tested by other test cases above |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
55 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
56 # Check month [1, 12] + zero support |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
57 self.assertRaises(ValueError, func, |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
58 (1900, -1, 1, 0, 0, 0, 0, 1, -1)) |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
59 self.assertRaises(ValueError, func, |
|
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
|
60 (1900, 13, 1, 0, 0, 0, 0, 1, -1)) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
61 # Check day of month [1, 31] + zero support |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
62 self.assertRaises(ValueError, func, |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
63 (1900, 1, -1, 0, 0, 0, 0, 1, -1)) |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
64 self.assertRaises(ValueError, func, |
|
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
|
65 (1900, 1, 32, 0, 0, 0, 0, 1, -1)) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
66 # Check hour [0, 23] |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
67 self.assertRaises(ValueError, func, |
|
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 (1900, 1, 1, -1, 0, 0, 0, 1, -1)) |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
69 self.assertRaises(ValueError, func, |
|
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
|
70 (1900, 1, 1, 24, 0, 0, 0, 1, -1)) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
71 # Check minute [0, 59] |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
72 self.assertRaises(ValueError, func, |
|
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
|
73 (1900, 1, 1, 0, -1, 0, 0, 1, -1)) |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
74 self.assertRaises(ValueError, func, |
|
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
|
75 (1900, 1, 1, 0, 60, 0, 0, 1, -1)) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
76 # Check second [0, 61] |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
77 self.assertRaises(ValueError, func, |
|
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
|
78 (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
|
79 # 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
|
80 # allow two leap seconds (0..61) |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
81 self.assertRaises(ValueError, func, |
|
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
|
82 (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
|
83 # 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
|
84 # 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
|
85 # 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
|
86 # modulo. |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
87 self.assertRaises(ValueError, func, |
|
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
|
88 (1900, 1, 1, 0, 0, 0, -2, 1, -1)) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
89 # Check day of the year [1, 366] + zero support |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
90 self.assertRaises(ValueError, func, |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
91 (1900, 1, 1, 0, 0, 0, 0, -1, -1)) |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
92 self.assertRaises(ValueError, func, |
|
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
|
93 (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
|
94 |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
95 def test_strftime_bounding_check(self): |
|
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
96 self._bounds_checking(lambda tup: time.strftime('', tup)) |
|
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
|
97 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
98 def test_default_values_for_zero(self): |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
99 # Make sure that using all zeros uses the proper default values. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
100 # No test for daylight savings since strftime() does not change output |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
101 # based on its value. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
102 expected = "2000 01 01 00 00 00 1 001" |
|
67436
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
103 with support.check_warnings(): |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
104 result = time.strftime("%Y %m %d %H %M %S %w %j", (0,)*9) |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55593
diff
changeset
|
105 self.assertEqual(expected, result) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
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): |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39575
diff
changeset
|
108 # Should be able to go round-trip from strftime to strptime without |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39575
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', '%'): |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39575
diff
changeset
|
114 format = '%' + directive |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39575
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: |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39575
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: |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39575
diff
changeset
|
119 self.fail("conversion specifier %r failed with '%s' input." % |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39575
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 |
|
52474
45a717450961
Make sure time.strptime only accepts strings (and document the fact like
Brett Cannon <bcannon@gmail.com>
parents:
47201
diff
changeset
|
122 def test_strptime_bytes(self): |
|
45a717450961
Make sure time.strptime only accepts strings (and document the fact like
Brett Cannon <bcannon@gmail.com>
parents:
47201
diff
changeset
|
123 # Make sure only strings are accepted as arguments to strptime. |
|
45a717450961
Make sure time.strptime only accepts strings (and document the fact like
Brett Cannon <bcannon@gmail.com>
parents:
47201
diff
changeset
|
124 self.assertRaises(TypeError, time.strptime, b'2009', "%Y") |
|
45a717450961
Make sure time.strptime only accepts strings (and document the fact like
Brett Cannon <bcannon@gmail.com>
parents:
47201
diff
changeset
|
125 self.assertRaises(TypeError, time.strptime, '2009', b'%Y') |
|
45a717450961
Make sure time.strptime only accepts strings (and document the fact like
Brett Cannon <bcannon@gmail.com>
parents:
47201
diff
changeset
|
126 |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
127 def test_asctime(self): |
|
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
128 time.asctime(time.gmtime(self.t)) |
|
67350
1e62a0cee092
Issue #8013: time.asctime and time.ctime no longer call system asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67275
diff
changeset
|
129 |
|
1e62a0cee092
Issue #8013: time.asctime and time.ctime no longer call system asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67275
diff
changeset
|
130 # Max year is only limited by the size of C int. |
|
67362
efcb14f94e76
Fix test_time under Windows
Antoine Pitrou <solipsis@pitrou.net>
parents:
67353
diff
changeset
|
131 sizeof_int = sysconfig.get_config_var('SIZEOF_INT') or 4 |
|
67350
1e62a0cee092
Issue #8013: time.asctime and time.ctime no longer call system asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67275
diff
changeset
|
132 bigyear = (1 << 8 * sizeof_int - 1) - 1 |
|
1e62a0cee092
Issue #8013: time.asctime and time.ctime no longer call system asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67275
diff
changeset
|
133 asc = time.asctime((bigyear, 6, 1) + (0,)*6) |
|
1e62a0cee092
Issue #8013: time.asctime and time.ctime no longer call system asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67275
diff
changeset
|
134 self.assertEqual(asc[-len(str(bigyear)):], str(bigyear)) |
|
1e62a0cee092
Issue #8013: time.asctime and time.ctime no longer call system asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67275
diff
changeset
|
135 self.assertRaises(OverflowError, time.asctime, (bigyear + 1,) + (0,)*8) |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
136 self.assertRaises(TypeError, time.asctime, 0) |
|
67279
f89e37cd6c65
Merged revisions 87648,87656 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66883
diff
changeset
|
137 self.assertRaises(TypeError, time.asctime, ()) |
|
67424
7e5777e1f0fd
Further simplify gettmarg()
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67390
diff
changeset
|
138 self.assertRaises(TypeError, time.asctime, (0,) * 10) |
|
4612
4de05cbf5ad1
test of time module. not terribly fancy, but it does touch every
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
139 |
|
65036
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
140 def test_asctime_bounding_check(self): |
|
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
141 self._bounds_checking(time.asctime) |
|
597804b41125
Issue #6608: time.asctime is now checking struct tm fields its input
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
56176
diff
changeset
|
142 |
| 67275 | 143 def test_ctime(self): |
|
67350
1e62a0cee092
Issue #8013: time.asctime and time.ctime no longer call system asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67275
diff
changeset
|
144 t = time.mktime((1973, 9, 16, 1, 3, 52, 0, 0, -1)) |
|
1e62a0cee092
Issue #8013: time.asctime and time.ctime no longer call system asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67275
diff
changeset
|
145 self.assertEqual(time.ctime(t), 'Sun Sep 16 01:03:52 1973') |
|
1e62a0cee092
Issue #8013: time.asctime and time.ctime no longer call system asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67275
diff
changeset
|
146 t = time.mktime((2000, 1, 1, 0, 0, 0, 0, 0, -1)) |
|
1e62a0cee092
Issue #8013: time.asctime and time.ctime no longer call system asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67275
diff
changeset
|
147 self.assertEqual(time.ctime(t), 'Sat Jan 1 00:00:00 2000') |
|
67436
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
148 for year in [-100, 100, 1000, 2000, 10000]: |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
149 try: |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
150 testval = time.mktime((year, 1, 10) + (0,)*6) |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
151 except (ValueError, OverflowError): |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
152 # If mktime fails, ctime will fail too. This may happen |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
153 # on some platforms. |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
154 pass |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
155 else: |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
156 self.assertEqual(time.ctime(testval)[20:], str(year)) |
|
4612
4de05cbf5ad1
test of time module. not terribly fancy, but it does touch every
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
157 |
|
66883
7f8cdcfbb08e
Merged revisions 87222 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66340
diff
changeset
|
158 @unittest.skipIf(not hasattr(time, "tzset"), |
|
7f8cdcfbb08e
Merged revisions 87222 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
66340
diff
changeset
|
159 "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
|
160 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
|
161 |
|
28299
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
162 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
|
163 |
|
28774
c9bee11eaa8b
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28579
diff
changeset
|
164 # 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
|
165 # hemisphere. |
|
28774
c9bee11eaa8b
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28579
diff
changeset
|
166 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
|
167 |
|
28579
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
168 # 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
|
169 # 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
|
170 # 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
|
171 # 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
|
172 # systems. |
|
28774
c9bee11eaa8b
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28579
diff
changeset
|
173 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
|
174 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
|
175 utc='UTC+0' |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
176 |
|
28299
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
177 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
|
178 try: |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
179 # 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
|
180 # 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
|
181 # 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
|
182 environ['TZ'] = eastern |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
183 time.tzset() |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
184 environ['TZ'] = utc |
|
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
185 time.tzset() |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
186 self.assertEqual( |
|
28579
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
187 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
|
188 ) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
189 self.assertEqual(time.daylight, 0) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
190 self.assertEqual(time.timezone, 0) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
191 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
|
192 |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
193 # 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
|
194 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
|
195 time.tzset() |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
196 self.assertNotEqual(time.gmtime(xmas2002), time.localtime(xmas2002)) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
197 self.assertEqual(time.tzname, ('EST', 'EDT')) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
198 self.assertEqual(len(time.tzname), 2) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
199 self.assertEqual(time.daylight, 1) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
200 self.assertEqual(time.timezone, 18000) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
201 self.assertEqual(time.altzone, 14400) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
202 self.assertEqual(time.localtime(xmas2002).tm_isdst, 0) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
203 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
|
204 |
|
28579
981032e64736
SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Neal Norwitz <nnorwitz@gmail.com>
parents:
28300
diff
changeset
|
205 # 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
|
206 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
|
207 time.tzset() |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
208 self.assertNotEqual(time.gmtime(xmas2002), time.localtime(xmas2002)) |
|
73886
c143e66e5efe
Issue #11886: workaround an OS bug (time zone data) in test_time
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69167
diff
changeset
|
209 |
|
c143e66e5efe
Issue #11886: workaround an OS bug (time zone data) in test_time
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69167
diff
changeset
|
210 # Issue #11886: Australian Eastern Standard Time (UTC+10) is called |
|
c143e66e5efe
Issue #11886: workaround an OS bug (time zone data) in test_time
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69167
diff
changeset
|
211 # "EST" (as Eastern Standard Time, UTC-5) instead of "AEST" on some |
|
c143e66e5efe
Issue #11886: workaround an OS bug (time zone data) in test_time
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69167
diff
changeset
|
212 # operating systems (e.g. FreeBSD), which is wrong. See for example |
|
c143e66e5efe
Issue #11886: workaround an OS bug (time zone data) in test_time
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69167
diff
changeset
|
213 # this bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=93810 |
|
c143e66e5efe
Issue #11886: workaround an OS bug (time zone data) in test_time
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69167
diff
changeset
|
214 self.assertIn(time.tzname[0], ('AEST' 'EST'), time.tzname[0]) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
215 self.assertTrue(time.tzname[1] == 'AEDT', str(time.tzname[1])) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
216 self.assertEqual(len(time.tzname), 2) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
217 self.assertEqual(time.daylight, 1) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
218 self.assertEqual(time.timezone, -36000) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
219 self.assertEqual(time.altzone, -39600) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54443
diff
changeset
|
220 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
|
221 |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
222 finally: |
|
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
223 # 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
|
224 # 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
|
225 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
|
226 environ['TZ'] = org_TZ |
|
39575
63237fcefd99
Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
227 elif 'TZ' in environ: |
|
28299
14316df1c298
- New function time.tzset() provides access to the C library tzet()
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
228 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
|
229 time.tzset() |
|
28774
c9bee11eaa8b
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28579
diff
changeset
|
230 |
|
32388
5cf507b64f31
Bug 975996: Add _PyTime_DoubleToTimet to C API
Tim Peters <tim.peters@gmail.com>
parents:
31608
diff
changeset
|
231 def test_insane_timestamps(self): |
|
5cf507b64f31
Bug 975996: Add _PyTime_DoubleToTimet to C API
Tim Peters <tim.peters@gmail.com>
parents:
31608
diff
changeset
|
232 # 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
|
233 # 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
|
234 # 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
|
235 # results!). |
|
5cf507b64f31
Bug 975996: Add _PyTime_DoubleToTimet to C API
Tim Peters <tim.peters@gmail.com>
parents:
31608
diff
changeset
|
236 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
|
237 for unreasonable in -1e200, 1e200: |
|
5cf507b64f31
Bug 975996: Add _PyTime_DoubleToTimet to C API
Tim Peters <tim.peters@gmail.com>
parents:
31608
diff
changeset
|
238 self.assertRaises(ValueError, func, unreasonable) |
|
17912
421b1d660495
Convert time module tests to PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15540
diff
changeset
|
239 |
|
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
|
240 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
|
241 # 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
|
242 # 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
|
243 # 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
|
244 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
|
245 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
|
246 |
|
582eb51b8492
allow ctime(), gmtime(), and localtime() to take None as equivalent to an omitted arg
Fred Drake <fdrake@acm.org>
parents:
32388
diff
changeset
|
247 def test_gmtime_without_arg(self): |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
248 gt0 = time.gmtime() |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
249 gt1 = time.gmtime(None) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
250 t0 = time.mktime(gt0) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
251 t1 = time.mktime(gt1) |
|
67436
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
252 self.assertAlmostEqual(t1, t0, delta=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
|
253 |
|
582eb51b8492
allow ctime(), gmtime(), and localtime() to take None as equivalent to an omitted arg
Fred Drake <fdrake@acm.org>
parents:
32388
diff
changeset
|
254 def test_localtime_without_arg(self): |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
255 lt0 = time.localtime() |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
256 lt1 = time.localtime(None) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
257 t0 = time.mktime(lt0) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
32939
diff
changeset
|
258 t1 = time.mktime(lt1) |
|
67436
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
259 self.assertAlmostEqual(t1, t0, delta=0.2) |
|
67946
2ee2c76082c8
Merged revisions 87919 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67305
diff
changeset
|
260 |
|
54442
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
261 class TestLocale(unittest.TestCase): |
|
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
262 def setUp(self): |
|
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
263 self.oldloc = locale.setlocale(locale.LC_ALL) |
|
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
264 |
|
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
265 def tearDown(self): |
|
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
266 locale.setlocale(locale.LC_ALL, self.oldloc) |
|
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
267 |
| 54443 | 268 def test_bug_3061(self): |
|
54442
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
269 try: |
|
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
270 tmp = locale.setlocale(locale.LC_ALL, "fr_FR") |
|
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
271 except locale.Error: |
|
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
272 # skip this test |
|
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
273 return |
|
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
274 # This should not cause an exception |
|
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
275 time.strftime("%B", (2009,2,1,0,0,0,0,0,0)) |
|
69cd80f8e133
Issue #5562: Use wcsftime for time.strftime where available.
Martin v. Löwis <martin@v.loewis.de>
parents:
52474
diff
changeset
|
276 |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
277 |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
278 class _BaseYearTest(unittest.TestCase): |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
279 accept2dyear = None |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
280 |
|
67390
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
281 def setUp(self): |
|
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
282 self.saved_accept2dyear = time.accept2dyear |
|
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
283 time.accept2dyear = self.accept2dyear |
|
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
284 |
|
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
285 def tearDown(self): |
|
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
286 time.accept2dyear = self.saved_accept2dyear |
|
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
287 |
|
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
288 def yearstr(self, y): |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
289 raise NotImplementedError() |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
290 |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
291 class _TestAsctimeYear: |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
292 def yearstr(self, y): |
|
67436
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
293 return time.asctime((y,) + (0,) * 8).split()[-1] |
|
67390
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
294 |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
295 def test_large_year(self): |
|
67453
253d91e4f672
Issue #1777412: test large years value for strftime('%Y')
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67452
diff
changeset
|
296 # Check that it doesn't crash for year > 9999 |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
297 self.assertEqual(self.yearstr(12345), '12345') |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
298 self.assertEqual(self.yearstr(123456789), '123456789') |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
299 |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
300 class _TestStrftimeYear: |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
301 def yearstr(self, y): |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
302 return time.strftime('%Y', (y,) + (0,) * 8).split()[-1] |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
303 |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
304 def test_large_year(self): |
|
67453
253d91e4f672
Issue #1777412: test large years value for strftime('%Y')
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67452
diff
changeset
|
305 # Check that it doesn't crash for year > 9999 |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
306 try: |
|
67453
253d91e4f672
Issue #1777412: test large years value for strftime('%Y')
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67452
diff
changeset
|
307 text = self.yearstr(12345) |
|
253d91e4f672
Issue #1777412: test large years value for strftime('%Y')
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67452
diff
changeset
|
308 except ValueError: |
|
67454
3b79ec83ce21
Issue #1777412: fix test_time for Mac OS X and OpenIndiana
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67453
diff
changeset
|
309 # strftime() is limited to [1; 9999] with Visual Studio |
|
67455
e480604767c4
Issue #1777412: Remove all limits on tm_year from time.strftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67454
diff
changeset
|
310 return |
|
68781
d56eb817b181
Issue #10864 has been fixed: remove the workaround
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
311 self.assertEqual(text, '12345') |
|
d56eb817b181
Issue #10864 has been fixed: remove the workaround
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
312 self.assertEqual(self.yearstr(123456789), '123456789') |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
313 |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
314 class _Test2dYear(_BaseYearTest): |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
315 accept2dyear = 1 |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
316 |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
317 def test_year(self): |
|
67436
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
318 with support.check_warnings(): |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
319 self.assertEqual(self.yearstr(0), '2000') |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
320 self.assertEqual(self.yearstr(69), '1969') |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
321 self.assertEqual(self.yearstr(68), '2068') |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
322 self.assertEqual(self.yearstr(99), '1999') |
|
67390
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
323 |
|
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
324 def test_invalid(self): |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
325 self.assertRaises(ValueError, self.yearstr, -1) |
|
67390
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
326 self.assertRaises(ValueError, self.yearstr, 100) |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
327 self.assertRaises(ValueError, self.yearstr, 999) |
|
67390
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
328 |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
329 class _Test4dYear(_BaseYearTest): |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
330 accept2dyear = 0 |
|
67390
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
331 |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
332 def test_year(self): |
|
67454
3b79ec83ce21
Issue #1777412: fix test_time for Mac OS X and OpenIndiana
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67453
diff
changeset
|
333 self.assertIn(self.yearstr(1), ('1', '0001')) |
|
3b79ec83ce21
Issue #1777412: fix test_time for Mac OS X and OpenIndiana
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67453
diff
changeset
|
334 self.assertIn(self.yearstr(68), ('68', '0068')) |
|
3b79ec83ce21
Issue #1777412: fix test_time for Mac OS X and OpenIndiana
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67453
diff
changeset
|
335 self.assertIn(self.yearstr(69), ('69', '0069')) |
|
3b79ec83ce21
Issue #1777412: fix test_time for Mac OS X and OpenIndiana
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67453
diff
changeset
|
336 self.assertIn(self.yearstr(99), ('99', '0099')) |
|
3b79ec83ce21
Issue #1777412: fix test_time for Mac OS X and OpenIndiana
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67453
diff
changeset
|
337 self.assertIn(self.yearstr(999), ('999', '0999')) |
|
67436
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
338 self.assertEqual(self.yearstr(9999), '9999') |
|
12074f3ab809
Issue #10827: Changed the rules for 2-digit years. The time.asctime
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67424
diff
changeset
|
339 |
|
67455
e480604767c4
Issue #1777412: Remove all limits on tm_year from time.strftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67454
diff
changeset
|
340 def test_negative(self): |
|
e480604767c4
Issue #1777412: Remove all limits on tm_year from time.strftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67454
diff
changeset
|
341 try: |
|
e480604767c4
Issue #1777412: Remove all limits on tm_year from time.strftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67454
diff
changeset
|
342 text = self.yearstr(-1) |
|
e480604767c4
Issue #1777412: Remove all limits on tm_year from time.strftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67454
diff
changeset
|
343 except ValueError: |
|
e480604767c4
Issue #1777412: Remove all limits on tm_year from time.strftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67454
diff
changeset
|
344 # strftime() is limited to [1; 9999] with Visual Studio |
|
e480604767c4
Issue #1777412: Remove all limits on tm_year from time.strftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67454
diff
changeset
|
345 return |
|
e480604767c4
Issue #1777412: Remove all limits on tm_year from time.strftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67454
diff
changeset
|
346 self.assertIn(text, ('-1', '-001')) |
|
e480604767c4
Issue #1777412: Remove all limits on tm_year from time.strftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67454
diff
changeset
|
347 |
|
e480604767c4
Issue #1777412: Remove all limits on tm_year from time.strftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67454
diff
changeset
|
348 self.assertEqual(self.yearstr(-1234), '-1234') |
|
e480604767c4
Issue #1777412: Remove all limits on tm_year from time.strftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67454
diff
changeset
|
349 self.assertEqual(self.yearstr(-123456), '-123456') |
|
e480604767c4
Issue #1777412: Remove all limits on tm_year from time.strftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67454
diff
changeset
|
350 |
|
67522
d70522cc9d4f
Issue #1726687: time.mktime() will now correctly compute value one
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67455
diff
changeset
|
351 |
|
d70522cc9d4f
Issue #1726687: time.mktime() will now correctly compute value one
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67455
diff
changeset
|
352 def test_mktime(self): |
|
d70522cc9d4f
Issue #1726687: time.mktime() will now correctly compute value one
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67455
diff
changeset
|
353 # Issue #1726687 |
|
d70522cc9d4f
Issue #1726687: time.mktime() will now correctly compute value one
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67455
diff
changeset
|
354 for t in (-2, -1, 0, 1): |
|
d70522cc9d4f
Issue #1726687: time.mktime() will now correctly compute value one
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67455
diff
changeset
|
355 try: |
|
d70522cc9d4f
Issue #1726687: time.mktime() will now correctly compute value one
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67455
diff
changeset
|
356 tt = time.localtime(t) |
|
d70522cc9d4f
Issue #1726687: time.mktime() will now correctly compute value one
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67455
diff
changeset
|
357 except (OverflowError, ValueError): |
|
d70522cc9d4f
Issue #1726687: time.mktime() will now correctly compute value one
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67455
diff
changeset
|
358 pass |
|
67524
c0f3ac19392b
This should fix mktime test on Windows
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67523
diff
changeset
|
359 else: |
|
c0f3ac19392b
This should fix mktime test on Windows
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67523
diff
changeset
|
360 self.assertEqual(time.mktime(tt), t) |
|
67523
ad0eb57eb2b5
Make mktime test more robust.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67522
diff
changeset
|
361 # It may not be possible to reliably make mktime return error |
|
ad0eb57eb2b5
Make mktime test more robust.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67522
diff
changeset
|
362 # on all platfom. This will make sure that no other exception |
|
ad0eb57eb2b5
Make mktime test more robust.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67522
diff
changeset
|
363 # than OverflowError is raised for an extreme value. |
|
ad0eb57eb2b5
Make mktime test more robust.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67522
diff
changeset
|
364 try: |
|
ad0eb57eb2b5
Make mktime test more robust.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67522
diff
changeset
|
365 time.mktime((-1, 1, 1, 0, 0, 0, -1, -1, -1)) |
|
ad0eb57eb2b5
Make mktime test more robust.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67522
diff
changeset
|
366 except OverflowError: |
|
ad0eb57eb2b5
Make mktime test more robust.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67522
diff
changeset
|
367 pass |
|
67522
d70522cc9d4f
Issue #1726687: time.mktime() will now correctly compute value one
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67455
diff
changeset
|
368 |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
369 class TestAsctimeAccept2dYear(_TestAsctimeYear, _Test2dYear): |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
370 pass |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
371 |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
372 class TestStrftimeAccept2dYear(_TestStrftimeYear, _Test2dYear): |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
373 pass |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
374 |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
375 class TestAsctime4dyear(_TestAsctimeYear, _Test4dYear): |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
376 pass |
|
67390
92f61a692e39
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67373
diff
changeset
|
377 |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
378 class TestStrftime4dyear(_TestStrftimeYear, _Test4dYear): |
|
67455
e480604767c4
Issue #1777412: Remove all limits on tm_year from time.strftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67454
diff
changeset
|
379 pass |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
380 |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
381 class Test2dyearBool(_TestAsctimeYear, _Test2dYear): |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
382 accept2dyear = True |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
383 |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
384 class Test4dyearBool(_TestAsctimeYear, _Test4dYear): |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
385 accept2dyear = False |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
386 |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
387 class TestAccept2YearBad(_TestAsctimeYear, _BaseYearTest): |
|
67451
c6b8c5b564a8
Fixed error handling branches. Thanks
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67436
diff
changeset
|
388 class X: |
|
c6b8c5b564a8
Fixed error handling branches. Thanks
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67436
diff
changeset
|
389 def __bool__(self): |
|
c6b8c5b564a8
Fixed error handling branches. Thanks
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67436
diff
changeset
|
390 raise RuntimeError('boo') |
|
c6b8c5b564a8
Fixed error handling branches. Thanks
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67436
diff
changeset
|
391 accept2dyear = X() |
|
c6b8c5b564a8
Fixed error handling branches. Thanks
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67436
diff
changeset
|
392 def test_2dyear(self): |
|
c6b8c5b564a8
Fixed error handling branches. Thanks
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67436
diff
changeset
|
393 pass |
|
c6b8c5b564a8
Fixed error handling branches. Thanks
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67436
diff
changeset
|
394 def test_invalid(self): |
|
c6b8c5b564a8
Fixed error handling branches. Thanks
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67436
diff
changeset
|
395 self.assertRaises(RuntimeError, self.yearstr, 200) |
|
c6b8c5b564a8
Fixed error handling branches. Thanks
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67436
diff
changeset
|
396 |
|
c6b8c5b564a8
Fixed error handling branches. Thanks
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67436
diff
changeset
|
397 |
|
20013
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17912
diff
changeset
|
398 def test_main(): |
|
67452
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
399 support.run_unittest( |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
400 TimeTestCase, |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
401 TestLocale, |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
402 TestAsctimeAccept2dYear, |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
403 TestStrftimeAccept2dYear, |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
404 TestAsctime4dyear, |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
405 TestStrftime4dyear, |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
406 Test2dyearBool, |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
407 Test4dyearBool, |
|
8757cd659291
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67451
diff
changeset
|
408 TestAccept2YearBad) |
|
20013
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17912
diff
changeset
|
409 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17912
diff
changeset
|
410 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
|
411 test_main() |
