diff options
Diffstat (limited to 'test/test-timeparse.py')
-rwxr-xr-x | test/test-timeparse.py | 32 |
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() |