From ee94a038a61d60db72046d5bcceec58009decb39 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 29 Oct 2019 08:58:52 -0700 Subject: [PATCH] add tests --- tests/test_uname.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ tests/test_uptime.py | 41 ++++++++++++++++++++++++++++++++++++++++ tests/test_w.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 tests/test_uname.py create mode 100644 tests/test_uptime.py create mode 100644 tests/test_w.py diff --git a/tests/test_uname.py b/tests/test_uname.py new file mode 100644 index 00000000..56375440 --- /dev/null +++ b/tests/test_uname.py @@ -0,0 +1,45 @@ +import os +import unittest +import jc.parsers.uname + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + + def setUp(self): + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/uname-a.out'), 'r') as f: + self.centos_7_7_uname_a = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/uname-a.out'), 'r') as f: + self.ubuntu_18_4_uname_a = f.read() + + def test_uname_centos_7_7(self): + """ + Test 'uname -a' on Centos 7.7 + """ + self.assertEqual(jc.parsers.uname.parse(self.centos_7_7_uname_a), {'kernel_name': 'Linux', + 'node_name': 'localhost.localdomain', + 'kernel_release': '3.10.0-1062.1.2.el7.x86_64', + 'operating_system': 'GNU/Linux', + 'hardware_platform': 'x86_64', + 'processor': 'x86_64', + 'machine': 'x86_64', + 'kernel_version': '#1 SMP Mon Sep 30 14:19:46 UTC 2019'}) + + def test_uname_ubuntu_18_4(self): + """ + Test 'uname -a' on Ubuntu 18.4 + """ + self.assertEqual(jc.parsers.uname.parse(self.ubuntu_18_4_uname_a), {'kernel_name': 'Linux', + 'node_name': 'kbrazil-ubuntu', + 'kernel_release': '4.15.0-65-generic', + 'operating_system': 'GNU/Linux', + 'hardware_platform': 'x86_64', + 'processor': 'x86_64', + 'machine': 'x86_64', + 'kernel_version': '#74-Ubuntu SMP Tue Sep 17 17:06:04 UTC 2019'}) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_uptime.py b/tests/test_uptime.py new file mode 100644 index 00000000..9d013736 --- /dev/null +++ b/tests/test_uptime.py @@ -0,0 +1,41 @@ +import os +import unittest +import jc.parsers.uptime + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + + def setUp(self): + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/uptime.out'), 'r') as f: + self.centos_7_7_uptime = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/uptime.out'), 'r') as f: + self.ubuntu_18_4_uptime = f.read() + + def test_uptime_centos_7_7(self): + """ + Test 'uptime' on Centos 7.7 + """ + self.assertEqual(jc.parsers.uptime.parse(self.centos_7_7_uptime), {'time': '10:25:20', + 'uptime': '16:03', + 'users': '2', + 'load_1m': '0.00', + 'load_5m': '0.01', + 'load_15m': '0.05'}) + + def test_uptime_ubuntu_18_4(self): + """ + Test 'uptime' on Ubuntu 18.4 + """ + self.assertEqual(jc.parsers.uptime.parse(self.ubuntu_18_4_uptime), {'time': '19:43:06', + 'uptime': '2 days, 19:32', + 'users': '2', + 'load_1m': '0.00', + 'load_5m': '0.00', + 'load_15m': '0.00'}) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_w.py b/tests/test_w.py new file mode 100644 index 00000000..50c39356 --- /dev/null +++ b/tests/test_w.py @@ -0,0 +1,45 @@ +import os +import unittest +import jc.parsers.w + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + + def setUp(self): + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/w.out'), 'r') as f: + self.centos_7_7_w = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/w.out'), 'r') as f: + self.ubuntu_18_4_w = f.read() + + def test_w_centos_7_7(self): + """ + Test 'w' on Centos 7.7 + """ + self.assertEqual(jc.parsers.w.parse(self.centos_7_7_w)[1], {'user': 'kbrazil', + 'tty': 'pts/0', + 'from': '192.168.71.1', + 'login_at': '09:53', + 'idle': '8.00s', + 'jcpu': '0.10s', + 'pcpu': '0.00s', + 'what': 'w'}) + + def test_w_ubuntu_18_4(self): + """ + Test 'w' on Ubuntu 18.4 + """ + self.assertEqual(jc.parsers.w.parse(self.ubuntu_18_4_w)[1], {'user': 'kbrazil', + 'tty': 'pts/0', + 'from': '192.168.71.1', + 'login_at': 'Thu22', + 'idle': '10.00s', + 'jcpu': '0.17s', + 'pcpu': '0.00s', + 'what': 'w'}) + + +if __name__ == '__main__': + unittest.main()