File: test_unit.py

package info (click to toggle)
monitoring-plugins-systemd 2.3.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 556 kB
  • sloc: python: 1,157; sh: 863; makefile: 25
file content (48 lines) | stat: -rw-r--r-- 1,553 bytes parent folder | download
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
47
48
import unittest
import check_systemd
from check_systemd import TableParser


class TestUnit(unittest.TestCase):

    def test_function_format_timespan_to_seconds(self):
        _to_sec = check_systemd.format_timespan_to_seconds
        self.assertEqual(_to_sec('1s'), 1)
        self.assertEqual(_to_sec('1s ago'), 1)
        self.assertEqual(_to_sec('11s'), 11)
        self.assertEqual(_to_sec('1min 1s'), 61)
        self.assertEqual(_to_sec('1min 1.123s'), 61.123)
        self.assertEqual(_to_sec('1min 2.15s'), 62.15)
        self.assertEqual(_to_sec('34min 46.292s'), 2086.292)
        self.assertEqual(_to_sec('2 months 8 days'), 5875200)


class TestTableParser(unittest.TestCase):

    def setUp(self):
        self.heading = 'UNIT LOAD     ACTIVE   SUB DESCRIPTION'
        self.row = 'unit+load+1234active   sub+description'
        self.parser = TableParser(self.heading)

    def assert_column(self, column_title, result):
        self.assertEqual(self.parser.get_column_text(self.row, column_title),
                         result)

    def test_get_column_text_unit(self):
        self.assert_column('UNIT', 'unit+')

    def test_get_column_text_load(self):
        self.assert_column('LOAD', 'load+1234')

    def test_get_column_text_active(self):
        self.assert_column('ACTIVE', 'active')

    def test_get_column_text_sub(self):
        self.assert_column('SUB', 'sub+')

    def test_get_column_text_description(self):
        self.assert_column('DESCRIPTION', 'description')


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