summaryrefslogtreecommitdiffstats
path: root/test/test-version.py
blob: 8f62d85cf754dda0a32d0fe7541867692f22ec81 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python3
import unittest
from staslib.version import KernelVersion


class VersionUnitTests(unittest.TestCase):
    '''Unit tests for class KernelVersion'''

    version = KernelVersion('5.8.0-63-generic')

    def test_str(self):
        self.assertIsInstance(str(self.version), str)

    def test_repr(self):
        self.assertIsInstance(repr(self.version), str)

    def test_eq(self):
        '''Test equality'''
        self.assertEqual(self.version, '5.8.0-63')
        self.assertNotEqual(self.version, '5.8.0')

    def test_lt(self):
        '''Test lower than'''
        self.assertTrue(self.version < '5.9')
        self.assertFalse(self.version < '5.7')

    def test_le(self):
        '''Test lower equal'''
        self.assertTrue(self.version <= '5.8.0-63')
        self.assertTrue(self.version <= '5.8.1')
        self.assertFalse(self.version <= '5.7')

    def test_gt(self):
        '''Test greater than'''
        self.assertTrue(self.version > '5.8')
        self.assertFalse(self.version > '5.9')

    def test_ge(self):
        '''Test greater equal'''
        self.assertTrue(self.version >= '5.8.0-63')
        self.assertTrue(self.version >= '5.7.0')
        self.assertFalse(self.version >= '5.9')


if __name__ == '__main__':
    unittest.main()