mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-08 22:36:48 +02:00
add proc-net-dev-mcast parser docs and tests
This commit is contained in:
@ -32,7 +32,7 @@ Schema:
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"index": integer,
|
"index": integer,
|
||||||
"interface_name": string,
|
"interface": string,
|
||||||
"dmi_u": integer,
|
"dmi_u": integer,
|
||||||
"dmi_g": integer,
|
"dmi_g": integer,
|
||||||
"dmi_address": string
|
"dmi_address": string
|
||||||
@ -45,14 +45,14 @@ Examples:
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"index": 2,
|
"index": 2,
|
||||||
"interface_name": "ens33",
|
"interface": "ens33",
|
||||||
"dmi_u": 1,
|
"dmi_u": 1,
|
||||||
"dmi_g": 0,
|
"dmi_g": 0,
|
||||||
"dmi_address": "333300000001"
|
"dmi_address": "333300000001"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"index": 2,
|
"index": 2,
|
||||||
"interface_name": "ens33",
|
"interface": "ens33",
|
||||||
"dmi_u": 1,
|
"dmi_u": 1,
|
||||||
"dmi_g": 0,
|
"dmi_g": 0,
|
||||||
"dmi_address": "01005e000001"
|
"dmi_address": "01005e000001"
|
||||||
@ -64,14 +64,14 @@ Examples:
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"index": "2",
|
"index": "2",
|
||||||
"interface_name": "ens33",
|
"interface": "ens33",
|
||||||
"dmi_u": "1",
|
"dmi_u": "1",
|
||||||
"dmi_g": "0",
|
"dmi_g": "0",
|
||||||
"dmi_address": "333300000001"
|
"dmi_address": "333300000001"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"index": "2",
|
"index": "2",
|
||||||
"interface_name": "ens33",
|
"interface": "ens33",
|
||||||
"dmi_u": "1",
|
"dmi_u": "1",
|
||||||
"dmi_g": "0",
|
"dmi_g": "0",
|
||||||
"dmi_address": "01005e000001"
|
"dmi_address": "01005e000001"
|
||||||
|
@ -27,7 +27,7 @@ Schema:
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"index": integer,
|
"index": integer,
|
||||||
"interface_name": string,
|
"interface": string,
|
||||||
"dmi_u": integer,
|
"dmi_u": integer,
|
||||||
"dmi_g": integer,
|
"dmi_g": integer,
|
||||||
"dmi_address": string
|
"dmi_address": string
|
||||||
@ -40,14 +40,14 @@ Examples:
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"index": 2,
|
"index": 2,
|
||||||
"interface_name": "ens33",
|
"interface": "ens33",
|
||||||
"dmi_u": 1,
|
"dmi_u": 1,
|
||||||
"dmi_g": 0,
|
"dmi_g": 0,
|
||||||
"dmi_address": "333300000001"
|
"dmi_address": "333300000001"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"index": 2,
|
"index": 2,
|
||||||
"interface_name": "ens33",
|
"interface": "ens33",
|
||||||
"dmi_u": 1,
|
"dmi_u": 1,
|
||||||
"dmi_g": 0,
|
"dmi_g": 0,
|
||||||
"dmi_address": "01005e000001"
|
"dmi_address": "01005e000001"
|
||||||
@ -59,14 +59,14 @@ Examples:
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"index": "2",
|
"index": "2",
|
||||||
"interface_name": "ens33",
|
"interface": "ens33",
|
||||||
"dmi_u": "1",
|
"dmi_u": "1",
|
||||||
"dmi_g": "0",
|
"dmi_g": "0",
|
||||||
"dmi_address": "333300000001"
|
"dmi_address": "333300000001"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"index": "2",
|
"index": "2",
|
||||||
"interface_name": "ens33",
|
"interface": "ens33",
|
||||||
"dmi_u": "1",
|
"dmi_u": "1",
|
||||||
"dmi_g": "0",
|
"dmi_g": "0",
|
||||||
"dmi_address": "01005e000001"
|
"dmi_address": "01005e000001"
|
||||||
@ -142,7 +142,7 @@ def parse(
|
|||||||
|
|
||||||
if jc.utils.has_data(data):
|
if jc.utils.has_data(data):
|
||||||
|
|
||||||
header = 'index interface_name dmi_u dmi_g dmi_address\n'
|
header = 'index interface dmi_u dmi_g dmi_address\n'
|
||||||
data = header + data
|
data = header + data
|
||||||
data_splitlines = data.splitlines()
|
data_splitlines = data.splitlines()
|
||||||
raw_output = simple_table_parse(data_splitlines)
|
raw_output = simple_table_parse(data_splitlines)
|
||||||
|
1
tests/fixtures/linux-proc/net_dev_mcast.json
vendored
Normal file
1
tests/fixtures/linux-proc/net_dev_mcast.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"index":2,"interface":"ens33","dmi_u":1,"dmi_g":0,"dmi_address":"333300000001"},{"index":2,"interface":"ens33","dmi_u":1,"dmi_g":0,"dmi_address":"01005e000001"},{"index":2,"interface":"ens33","dmi_u":1,"dmi_g":0,"dmi_address":"0180c2000000"},{"index":2,"interface":"ens33","dmi_u":1,"dmi_g":0,"dmi_address":"0180c2000003"},{"index":2,"interface":"ens33","dmi_u":1,"dmi_g":0,"dmi_address":"0180c200000e"},{"index":2,"interface":"ens33","dmi_u":1,"dmi_g":0,"dmi_address":"3333ffa4e315"}]
|
44
tests/test_proc_net_dev_mcast.py
Normal file
44
tests/test_proc_net_dev_mcast.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
import json
|
||||||
|
from typing import Dict
|
||||||
|
import jc.parsers.proc_net_dev_mcast
|
||||||
|
|
||||||
|
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_mcast': (
|
||||||
|
'fixtures/linux-proc/net_dev_mcast',
|
||||||
|
'fixtures/linux-proc/net_dev_mcast.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_mcast_nodata(self):
|
||||||
|
"""
|
||||||
|
Test 'proc_net_dev_mcast' with no data
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.proc_net_dev_mcast.parse('', quiet=True), [])
|
||||||
|
|
||||||
|
def test_proc_net_dev_mcast(self):
|
||||||
|
"""
|
||||||
|
Test '/proc/net/dev_mcast'
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.proc_net_dev_mcast.parse(self.f_in['proc_net_dev_mcast'], quiet=True),
|
||||||
|
self.f_json['proc_net_dev_mcast'])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Reference in New Issue
Block a user