Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjonbrazil committed Oct 25, 2023
1 parent 88649a4 commit 13a8022
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/fixtures/generic/vmstat-extra-wide-streaming.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"runnable_procs":0,"uninterruptible_sleeping_procs":0,"virtual_mem_used":0,"free_mem":2430264,"buffer_mem":1011084,"cache_mem":22658240,"inactive_mem":null,"active_mem":null,"swap_in":0,"swap_out":0,"blocks_in":4,"blocks_out":6,"interrupts":3,"context_switches":5,"user_time":3,"system_time":1,"idle_time":96,"io_wait_time":0,"stolen_time":0,"timestamp":null,"timezone":null}]
1 change: 1 addition & 0 deletions tests/fixtures/generic/vmstat-extra-wide.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"runnable_procs":0,"uninterruptible_sleeping_procs":0,"virtual_mem_used":0,"free_mem":2430264,"buffer_mem":1011084,"cache_mem":22658240,"inactive_mem":null,"active_mem":null,"swap_in":0,"swap_out":0,"blocks_in":4,"blocks_out":6,"interrupts":3,"context_switches":5,"user_time":3,"system_time":1,"idle_time":96,"io_wait_time":0,"stolen_time":0,"timestamp":null,"timezone":null}]
4 changes: 4 additions & 0 deletions tests/fixtures/generic/vmstat-extra-wide.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--procs-- -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 2430264 1011084 22658240 0 0 4 6 3 5 3 1 96 0 0

12 changes: 12 additions & 0 deletions tests/test_vmstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/vmstat-1-long.out'), 'r', encoding='utf-8') as f:
ubuntu_18_04_vmstat_1_long = f.read()

with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/vmstat-extra-wide.out'), 'r', encoding='utf-8') as f:
generic_vmstat_extra_wide = f.read()

# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat.json'), 'r', encoding='utf-8') as f:
centos_7_7_vmstat_json = json.loads(f.read())
Expand All @@ -65,6 +68,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/vmstat-1-long.json'), 'r', encoding='utf-8') as f:
ubuntu_18_04_vmstat_1_long_json = json.loads(f.read())

with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/vmstat-extra-wide.json'), 'r', encoding='utf-8') as f:
generic_vmstat_extra_wide_json = json.loads(f.read())


def test_vmstat_nodata(self):
"""
Expand Down Expand Up @@ -120,6 +126,12 @@ def test_vmstat_1_long(self):
"""
self.assertEqual(jc.parsers.vmstat.parse(self.ubuntu_18_04_vmstat_1_long, quiet=True), self.ubuntu_18_04_vmstat_1_long_json)

def test_vmstat_extra_wide(self):
"""
Test 'vmstat -w' with wider output
"""
self.assertEqual(jc.parsers.vmstat.parse(self.generic_vmstat_extra_wide, quiet=True), self.generic_vmstat_extra_wide_json)


if __name__ == '__main__':
unittest.main()
12 changes: 12 additions & 0 deletions tests/test_vmstat_s.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/vmstat-1-long.out'), 'r', encoding='utf-8') as f:
ubuntu_18_04_vmstat_1_long = f.read()

with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/vmstat-extra-wide.out'), 'r', encoding='utf-8') as f:
generic_vmstat_extra_wide = f.read()

# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat-streaming.json'), 'r', encoding='utf-8') as f:
centos_7_7_vmstat_streaming_json = json.loads(f.read())
Expand All @@ -70,6 +73,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/vmstat-1-long-streaming.json'), 'r', encoding='utf-8') as f:
ubuntu_18_04_vmstat_1_long_streaming_json = json.loads(f.read())

with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/vmstat-extra-wide-streaming.json'), 'r', encoding='utf-8') as f:
generic_vmstat_extra_wide_streaming_json = json.loads(f.read())


def test_vmstat_s_nodata(self):
"""
Expand Down Expand Up @@ -131,6 +137,12 @@ def test_vmstat_s_1_long_ubuntu_18_04(self):
"""
self.assertEqual(list(jc.parsers.vmstat_s.parse(self.ubuntu_18_04_vmstat_1_long.splitlines(), quiet=True)), self.ubuntu_18_04_vmstat_1_long_streaming_json)

def test_vmstat_extra_wide(self):
"""
Test 'vmstat -w' with extra wide output
"""
self.assertEqual(list(jc.parsers.vmstat_s.parse(self.generic_vmstat_extra_wide.splitlines(), quiet=True)), self.generic_vmstat_extra_wide_streaming_json)


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

0 comments on commit 13a8022

Please sign in to comment.