summaryrefslogtreecommitdiffstats
path: root/test/test-timeparse.py
diff options
context:
space:
mode:
authorBenjamin Drung <bdrung@debian.org>2023-06-10 08:55:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-10 09:21:49 +0000
commit88837172f69eabc408ae3945d82e0270b8e07440 (patch)
treed6b7fa06694f45d25f54f6ea9ded93c981e51f6f /test/test-timeparse.py
parentInitial commit. (diff)
downloadnvme-stas-88837172f69eabc408ae3945d82e0270b8e07440.tar.xz
nvme-stas-88837172f69eabc408ae3945d82e0270b8e07440.zip
Adding upstream version 2.2.1.upstream/2.2.1
Signed-off-by: Benjamin Drung <bdrung@debian.org>
Diffstat (limited to 'test/test-timeparse.py')
-rwxr-xr-xtest/test-timeparse.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/test-timeparse.py b/test/test-timeparse.py
new file mode 100755
index 0000000..1abf1b0
--- /dev/null
+++ b/test/test-timeparse.py
@@ -0,0 +1,32 @@
+#!/usr/bin/python3
+import unittest
+from staslib import timeparse
+
+
+class StasTimeparseUnitTest(unittest.TestCase):
+ '''Time parse unit tests'''
+
+ def test_timeparse(self):
+ '''Check that timeparse() converts time spans properly'''
+ self.assertEqual(timeparse.timeparse('1'), 1)
+ self.assertEqual(timeparse.timeparse('1s'), 1)
+ self.assertEqual(timeparse.timeparse('1 sec'), 1)
+ self.assertEqual(timeparse.timeparse('1 second'), 1)
+ self.assertEqual(timeparse.timeparse('1 seconds'), 1)
+ self.assertEqual(timeparse.timeparse('1:01'), 61)
+ self.assertEqual(timeparse.timeparse('1 day'), 24 * 60 * 60)
+ self.assertEqual(timeparse.timeparse('1 hour'), 60 * 60)
+ self.assertEqual(timeparse.timeparse('1 min'), 60)
+ self.assertEqual(timeparse.timeparse('0.5'), 0.5)
+ self.assertEqual(timeparse.timeparse('-1'), -1)
+ self.assertEqual(timeparse.timeparse(':22'), 22)
+ self.assertEqual(timeparse.timeparse('1 minute, 24 secs'), 84)
+ self.assertEqual(timeparse.timeparse('1.2 minutes'), 72)
+ self.assertEqual(timeparse.timeparse('1.2 seconds'), 1.2)
+ self.assertEqual(timeparse.timeparse('- 1 minute'), -60)
+ self.assertEqual(timeparse.timeparse('+ 1 minute'), 60)
+ self.assertIsNone(timeparse.timeparse('blah'))
+
+
+if __name__ == '__main__':
+ unittest.main()