mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2026-06-19 22:28:17 +02:00
add proc-net-dev parser
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
[{"interface":"lo","r_bytes":13222,"r_packets":152,"r_errs":0,"r_drop":0,"r_fifo":0,"r_frame":0,"r_compressed":0,"r_multicast":0,"t_bytes":13222,"t_packets":152,"t_errs":0,"t_drop":0,"t_fifo":0,"t_colls":0,"t_carrier":0,"t_compressed":0},{"interface":"ens33","r_bytes":60600053,"r_packets":109378,"r_errs":0,"r_drop":0,"r_fifo":0,"r_frame":0,"r_compressed":0,"r_multicast":0,"t_bytes":44256546,"t_packets":121425,"t_errs":0,"t_drop":0,"t_fifo":0,"t_colls":0,"t_carrier":0,"t_compressed":0}]
|
||||
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
import unittest
|
||||
import json
|
||||
from typing import Dict
|
||||
import jc.parsers.proc_net_dev
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
f_in: Dict = {}
|
||||
f_json: Dict = {}
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
fixtures = {
|
||||
'proc_net_dev': (
|
||||
'fixtures/linux-proc/net_dev',
|
||||
'fixtures/linux-proc/net_dev.json')
|
||||
}
|
||||
|
||||
for file, filepaths in fixtures.items():
|
||||
with open(os.path.join(THIS_DIR, filepaths[0]), 'r', encoding='utf-8') as a, \
|
||||
open(os.path.join(THIS_DIR, filepaths[1]), 'r', encoding='utf-8') as b:
|
||||
cls.f_in[file] = a.read()
|
||||
cls.f_json[file] = json.loads(b.read())
|
||||
|
||||
|
||||
def test_proc_net_dev_nodata(self):
|
||||
"""
|
||||
Test 'proc_net_dev' with no data
|
||||
"""
|
||||
self.assertEqual(jc.parsers.proc_net_dev.parse('', quiet=True), [])
|
||||
|
||||
def test_proc_net_dev(self):
|
||||
"""
|
||||
Test '/proc/net/dev'
|
||||
"""
|
||||
self.assertEqual(jc.parsers.proc_net_dev.parse(self.f_in['proc_net_dev'], quiet=True),
|
||||
self.f_json['proc_net_dev'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user