summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2011-01-05 23:00:47 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2011-01-05 23:00:47 (GMT)
commita6867258593a3b939042e47da26919be20e7e7f0 (patch)
treee6ca0b9aabaf1b866d5c812f324e57b3147a95f7 /Lib/test
parente40808a935352ed4c8e5f6f554d8e2124f44c645 (diff)
downloadcpython-a6867258593a3b939042e47da26919be20e7e7f0.zip
cpython-a6867258593a3b939042e47da26919be20e7e7f0.tar.gz
cpython-a6867258593a3b939042e47da26919be20e7e7f0.tar.bz2
- time.accept2dyear = True is now equivalent to time.accept2dyear = 1
- removed unnecessary struct_time to tuple conversion - added more unit tests (See issue #10827 for discussion.)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_time.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index d6de54b..af0a960 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -263,8 +263,48 @@ class TestLocale(unittest.TestCase):
# This should not cause an exception
time.strftime("%B", (2009,2,1,0,0,0,0,0,0))
+class TestAccept2Year(unittest.TestCase):
+ accept2dyear = 1
+ def setUp(self):
+ self.saved_accept2dyear = time.accept2dyear
+ time.accept2dyear = self.accept2dyear
+
+ def tearDown(self):
+ time.accept2dyear = self.saved_accept2dyear
+
+ def yearstr(self, y):
+ return time.strftime('%Y', (y,) + (0,) * 8)
+
+ def test_2dyear(self):
+ self.assertEqual(self.yearstr(0), '2000')
+ self.assertEqual(self.yearstr(69), '1969')
+ self.assertEqual(self.yearstr(68), '2068')
+ self.assertEqual(self.yearstr(99), '1999')
+
+ def test_invalid(self):
+ self.assertRaises(ValueError, self.yearstr, 1899)
+ self.assertRaises(ValueError, self.yearstr, 100)
+ self.assertRaises(ValueError, self.yearstr, -1)
+
+class TestAccept2YearBool(TestAccept2Year):
+ accept2dyear = True
+
+class TestDontAccept2Year(TestAccept2Year):
+ accept2dyear = 0
+ def test_2dyear(self):
+ self.assertRaises(ValueError, self.yearstr, 0)
+ self.assertRaises(ValueError, self.yearstr, 69)
+ self.assertRaises(ValueError, self.yearstr, 68)
+ self.assertRaises(ValueError, self.yearstr, 99)
+
+class TestDontAccept2YearBool(TestDontAccept2Year):
+ accept2dyear = False
+
+
def test_main():
- support.run_unittest(TimeTestCase, TestLocale)
+ support.run_unittest(TimeTestCase, TestLocale,
+ TestAccept2Year, TestAccept2YearBool,
+ TestDontAccept2Year, TestDontAccept2YearBool)
if __name__ == "__main__":
test_main()