Skip to content

Commit 16a8b6f

Browse files
committed
testsuite: add unit tests for the UtilDatetime class
Problem: There are no unit tests for the UtilDatetime class, which makes verification of the behavior of this class difficult. Add a small set of unit tests to t/python/t0024-util.py to ensure basic proper behavior of the various formatting options for UtilDatetime objects.
1 parent 14cec6d commit 16a8b6f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

t/python/t0024-util.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from pycotap import TAPTestRunner
1616

1717
from datetime import datetime, timedelta
18-
from flux.util import parse_datetime
18+
from flux.util import parse_datetime, UtilDatetime
1919

2020

2121
def ts(year, month, day, hour=0, minute=0, sec=0, us=0):
@@ -70,6 +70,25 @@ def test_nlp(self):
7070
self.assertEqual(self.parse("noon tomorrow"), ts(2021, 6, 11, 12))
7171
self.assertEqual(self.parse("last wed"), ts(2021, 6, 9))
7272

73+
class TestUtilDatetime(unittest.TestCase):
74+
@classmethod
75+
def setUpClass(self):
76+
self.zero = UtilDatetime.fromtimestamp(0.)
77+
self.ts = UtilDatetime(2021, 6, 10, 8, 0, 0)
78+
79+
def test_zero(self):
80+
self.assertEqual(f"{self.zero}", "")
81+
self.assertEqual(f"{self.zero:::h}", "-")
82+
self.assertEqual(f"{self.zero:%FT%T::<6}", " ")
83+
self.assertEqual(f"{self.zero:%FT%T::<6h}", "- ")
84+
85+
def test_fmt(self):
86+
self.assertEqual(f"{self.ts}", "2021-06-10T08:00:00")
87+
self.assertEqual(f"{self.ts:::h}", "2021-06-10T08:00:00")
88+
self.assertEqual(f"{self.ts:%b%d %R}", "Jun10 08:00")
89+
self.assertEqual(f"{self.ts:%b%d %R::h}", "Jun10 08:00")
90+
self.assertEqual(f"{self.ts:%b%d %R::>12}", " Jun10 08:00")
91+
self.assertEqual(f"{self.ts:%b%d %R::>12h}", " Jun10 08:00")
7392

7493
if __name__ == "__main__":
7594
unittest.main(testRunner=TAPTestRunner())

0 commit comments

Comments
 (0)