Skip to content

Commit 8d653e9

Browse files
committed
time: Add unit test for time.strftime.
Signed-off-by: Damien George <damien@micropython.org>
1 parent 8456a2a commit 8d653e9

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

python-stdlib/time/test_time.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy