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

add mpstat_s tests

This commit is contained in:
Kelly Brazil
2022-03-13 12:25:50 -07:00
parent c693c868ca
commit b257ce8c2f
4 changed files with 65 additions and 0 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[{"cpu":"all","percent_usr":0.22,"percent_nice":0.0,"percent_sys":0.37,"percent_iowait":0.01,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.4,"type":"cpu","time":"03:15:06 PM"},{"cpu":"0","percent_usr":0.22,"percent_nice":0.0,"percent_sys":0.37,"percent_iowait":0.01,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.4,"type":"cpu","time":"03:15:06 PM"},{"cpu":"all","intr_s":37.61,"type":"interrupts","time":"03:15:06 PM"},{"cpu":"0","intr_s":33.15,"type":"interrupts","time":"03:15:06 PM"},{"cpu":"0","0_s":0.02,"1_s":0.02,"4_s":0.01,"8_s":0.0,"9_s":0.0,"12_s":0.01,"14_s":0.0,"15_s":1.0,"16_s":0.75,"17_s":1.14,"18_s":0.03,"19_s":0.69,"24_s":0.0,"25_s":0.0,"26_s":0.0,"27_s":0.0,"28_s":0.0,"29_s":0.0,"30_s":0.0,"31_s":0.0,"32_s":0.0,"33_s":0.0,"34_s":0.0,"35_s":0.0,"36_s":0.0,"37_s":0.0,"38_s":0.0,"39_s":0.0,"40_s":0.0,"41_s":0.0,"42_s":0.0,"43_s":0.0,"44_s":0.0,"45_s":0.0,"46_s":0.0,"47_s":0.0,"48_s":0.0,"49_s":0.0,"50_s":0.0,"51_s":0.0,"52_s":0.0,"53_s":0.0,"54_s":0.0,"55_s":0.0,"56_s":0.0,"57_s":0.0,"nmi_s":0.0,"loc_s":32.69,"spu_s":0.0,"pmi_s":0.0,"iwi_s":1.24,"rtr_s":0.0,"res_s":0.0,"cal_s":0.0,"tlb_s":0.0,"trm_s":0.0,"thr_s":0.0,"dfr_s":0.0,"mce_s":0.0,"mcp_s":0.0,"err_s":0.0,"mis_s":0.0,"pin_s":0.0,"npi_s":0.0,"piw_s":0.0,"type":"interrupts","time":"03:15:06 PM"},{"cpu":"0","hi_s":0.0,"timer_s":21.26,"net_tx_s":0.2,"net_rx_s":0.69,"block_s":1.58,"block_iopoll_s":0.0,"tasklet_s":0.03,"sched_s":0.0,"hrtimer_s":0.0,"rcu_s":9.39,"type":"interrupts","time":"03:15:06 PM"}]

View File

@ -0,0 +1 @@
[{"cpu":"all","percent_usr":0.23,"percent_nice":0.0,"percent_sys":0.37,"percent_iowait":0.01,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.39,"type":"cpu","time":"03:14:20 PM"}]

62
tests/test_mpstat_s.py Normal file
View File

@ -0,0 +1,62 @@
import os
import json
import unittest
import jc.parsers.mpstat_s
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
# To create streaming output use:
# $ cat mpstat.out | jc --mpstat-s | jello -c > mpstat-streaming.json
class MyTests(unittest.TestCase):
def setUp(self):
pass
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mpstat.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_mpstat = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mpstat-A.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_mpstat_A = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mpstat-A-2-5.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_mpstat_A_2_5 = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mpstat-streaming.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_mpstat_streaming_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mpstat-A-streaming.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_mpstat_A_streaming_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mpstat-A-2-5-streaming.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_mpstat_A_2_5_streaming_json = json.loads(f.read())
def test_mpstat_s_nodata(self):
"""
Test 'mpstat' with no data
"""
self.assertEqual(list(jc.parsers.mpstat_s.parse([], quiet=True)), [])
def test_mpstat_s_centos_7_7(self):
"""
Test 'mpstat' on Centos 7.7
"""
self.assertEqual(list(jc.parsers.mpstat_s.parse(self.centos_7_7_mpstat.splitlines(), quiet=True)), self.centos_7_7_mpstat_streaming_json)
def test_mpstat_s_A_centos_7_7(self):
"""
Test 'mpstat -A' on Centos 7.7
"""
self.assertEqual(list(jc.parsers.mpstat_s.parse(self.centos_7_7_mpstat_A.splitlines(), quiet=True)), self.centos_7_7_mpstat_A_streaming_json)
def test_mpstat_s_A_2_5_centos_7_7(self):
"""
Test 'mpstat -A 2 5' on Centos 7.7
"""
self.assertEqual(list(jc.parsers.mpstat_s.parse(self.centos_7_7_mpstat_A_2_5.splitlines(), quiet=True)), self.centos_7_7_mpstat_A_2_5_streaming_json)
if __name__ == '__main__':
unittest.main()