1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

add tests

This commit is contained in:
Kelly Brazil
2019-10-29 08:58:52 -07:00
parent 1d658f7a9f
commit ee94a038a6
3 changed files with 131 additions and 0 deletions

45
tests/test_uname.py Normal file
View File

@ -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()

41
tests/test_uptime.py Normal file
View File

@ -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()

45
tests/test_w.py Normal file
View File

@ -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()