summaryrefslogtreecommitdiffstats
path: root/test/test-timeparse.py
blob: 1abf1b06e370708cc23e017c6380981d84081421 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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()