|
| 1 | +import time |
| 2 | +import unittest |
| 3 | + |
| 4 | +DAYS = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday") |
| 5 | + |
| 6 | +MONTHS = ( |
| 7 | + "January", |
| 8 | + "February", |
| 9 | + "March", |
| 10 | + "April", |
| 11 | + "May", |
| 12 | + "June", |
| 13 | + "July", |
| 14 | + "August", |
| 15 | + "September", |
| 16 | + "October", |
| 17 | + "November", |
| 18 | + "December", |
| 19 | +) |
| 20 | + |
| 21 | +TIME_TUPLE = (2022, 12, 14, 0, 45, 17, 2, 348, 0) |
| 22 | + |
| 23 | + |
| 24 | +class TestStrftime(unittest.TestCase): |
| 25 | + def test_not_formatting(self): |
| 26 | + fmt = "a string with no formatting {}[]() 0123456789 !@#$^&*" |
| 27 | + self.assertEqual(time.strftime(fmt, TIME_TUPLE), fmt) |
| 28 | + |
| 29 | + def test_days(self): |
| 30 | + for i, day in enumerate(DAYS): |
| 31 | + t = (0, 0, 0, 0, 0, 0, i, 0, 0) |
| 32 | + self.assertEqual(time.strftime("%a%A", t), day[:3] + day) |
| 33 | + |
| 34 | + def test_months(self): |
| 35 | + for i, month in enumerate(MONTHS): |
| 36 | + t = (0, i + 1, 0, 0, 0, 0, 0, 0, 0) |
| 37 | + self.assertEqual(time.strftime("%b%B", t), month[:3] + month) |
| 38 | + |
| 39 | + def test_full(self): |
| 40 | + fmt = "%Y-%m-%d %a %b %I:%M:%S %%%P%%" |
| 41 | + expected = "2022-12-14 Wed Dec 00:45:17 %AM%" |
| 42 | + self.assertEqual(time.strftime(fmt, TIME_TUPLE), expected) |
0 commit comments