mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
lspci docs and tests
This commit is contained in:
@ -27,19 +27,98 @@ Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"lspci": string,
|
||||
"bar": boolean,
|
||||
"baz": integer
|
||||
"slot": string,
|
||||
"domain": string,
|
||||
"domain_int": integer,
|
||||
"bus": string,
|
||||
"bus_int": integer,
|
||||
"dev": string,
|
||||
"dev_int": integer,
|
||||
"function": string,
|
||||
"function_int": integer,
|
||||
"class": string,
|
||||
"class_id": string,
|
||||
"class_id_int": integer,
|
||||
"vendor": string,
|
||||
"vendor_id": string,
|
||||
"vendor_id_int": integer,
|
||||
"device": string,
|
||||
"device_id": string,
|
||||
"device_id_int": integer,
|
||||
"svendor": string,
|
||||
"svendor_id": string,
|
||||
"svendor_id_int": integer,
|
||||
"sdevice": string,
|
||||
"sdevice_id": string,
|
||||
"sdevice_id_int": integer,
|
||||
"rev": string,
|
||||
"physlot": string,
|
||||
"physlot_int": integer,
|
||||
"progif": string,
|
||||
"progif_int": integer
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
$ lspci | jc --lspci -p
|
||||
[]
|
||||
$ lspci -nnmmv | jc --lspci -p
|
||||
[
|
||||
{
|
||||
"slot": "ff:02:05.0",
|
||||
"domain": "ff",
|
||||
"domain_int": 255,
|
||||
"bus": "02",
|
||||
"bus_int": 2,
|
||||
"dev": "05",
|
||||
"dev_int": 5,
|
||||
"function": "0",
|
||||
"function_int": 0,
|
||||
"class": "SATA controller",
|
||||
"class_id": "0106",
|
||||
"class_id_int": 262,
|
||||
"vendor": "VMware",
|
||||
"vendor_id": "15ad",
|
||||
"vendor_id_int": 5549,
|
||||
"device": "SATA AHCI controller",
|
||||
"device_id": "07e0",
|
||||
"device_id_int": 2016,
|
||||
"svendor": "VMware",
|
||||
"svendor_id": "15ad",
|
||||
"svendor_id_int": 5549,
|
||||
"sdevice": "SATA AHCI controller",
|
||||
"sdevice_id": "07e0",
|
||||
"sdevice_id_int": 2016,
|
||||
"physlot": "37",
|
||||
"physlot_int": 55,
|
||||
"progif": "01",
|
||||
"progif_int": 1
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ lspci | jc --lspci -p -r
|
||||
[]
|
||||
$ lspci -nnmmv | jc --lspci -p -r
|
||||
[
|
||||
{
|
||||
"slot": "ff:02:05.0",
|
||||
"domain": "ff",
|
||||
"bus": "02",
|
||||
"dev": "05",
|
||||
"function": "0",
|
||||
"class": "SATA controller",
|
||||
"class_id": "0106",
|
||||
"vendor": "VMware",
|
||||
"vendor_id": "15ad",
|
||||
"device": "SATA AHCI controller",
|
||||
"device_id": "07e0",
|
||||
"svendor": "VMware",
|
||||
"svendor_id": "15ad",
|
||||
"sdevice": "SATA AHCI controller",
|
||||
"sdevice_id": "07e0",
|
||||
"physlot": "37",
|
||||
"progif": "01"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
<a id="jc.parsers.lspci.parse"></a>
|
||||
|
||||
|
@ -22,19 +22,98 @@ Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"lspci": string,
|
||||
"bar": boolean,
|
||||
"baz": integer
|
||||
"slot": string,
|
||||
"domain": string,
|
||||
"domain_int": integer,
|
||||
"bus": string,
|
||||
"bus_int": integer,
|
||||
"dev": string,
|
||||
"dev_int": integer,
|
||||
"function": string,
|
||||
"function_int": integer,
|
||||
"class": string,
|
||||
"class_id": string,
|
||||
"class_id_int": integer,
|
||||
"vendor": string,
|
||||
"vendor_id": string,
|
||||
"vendor_id_int": integer,
|
||||
"device": string,
|
||||
"device_id": string,
|
||||
"device_id_int": integer,
|
||||
"svendor": string,
|
||||
"svendor_id": string,
|
||||
"svendor_id_int": integer,
|
||||
"sdevice": string,
|
||||
"sdevice_id": string,
|
||||
"sdevice_id_int": integer,
|
||||
"rev": string,
|
||||
"physlot": string,
|
||||
"physlot_int": integer,
|
||||
"progif": string,
|
||||
"progif_int": integer
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
$ lspci | jc --lspci -p
|
||||
[]
|
||||
$ lspci -nnmmv | jc --lspci -p
|
||||
[
|
||||
{
|
||||
"slot": "ff:02:05.0",
|
||||
"domain": "ff",
|
||||
"domain_int": 255,
|
||||
"bus": "02",
|
||||
"bus_int": 2,
|
||||
"dev": "05",
|
||||
"dev_int": 5,
|
||||
"function": "0",
|
||||
"function_int": 0,
|
||||
"class": "SATA controller",
|
||||
"class_id": "0106",
|
||||
"class_id_int": 262,
|
||||
"vendor": "VMware",
|
||||
"vendor_id": "15ad",
|
||||
"vendor_id_int": 5549,
|
||||
"device": "SATA AHCI controller",
|
||||
"device_id": "07e0",
|
||||
"device_id_int": 2016,
|
||||
"svendor": "VMware",
|
||||
"svendor_id": "15ad",
|
||||
"svendor_id_int": 5549,
|
||||
"sdevice": "SATA AHCI controller",
|
||||
"sdevice_id": "07e0",
|
||||
"sdevice_id_int": 2016,
|
||||
"physlot": "37",
|
||||
"physlot_int": 55,
|
||||
"progif": "01",
|
||||
"progif_int": 1
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ lspci | jc --lspci -p -r
|
||||
[]
|
||||
$ lspci -nnmmv | jc --lspci -p -r
|
||||
[
|
||||
{
|
||||
"slot": "ff:02:05.0",
|
||||
"domain": "ff",
|
||||
"bus": "02",
|
||||
"dev": "05",
|
||||
"function": "0",
|
||||
"class": "SATA controller",
|
||||
"class_id": "0106",
|
||||
"vendor": "VMware",
|
||||
"vendor_id": "15ad",
|
||||
"device": "SATA AHCI controller",
|
||||
"device_id": "07e0",
|
||||
"svendor": "VMware",
|
||||
"svendor_id": "15ad",
|
||||
"sdevice": "SATA AHCI controller",
|
||||
"sdevice_id": "07e0",
|
||||
"physlot": "37",
|
||||
"progif": "01"
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
import re
|
||||
from typing import List, Dict
|
||||
|
2
man/jc.1
2
man/jc.1
@ -1,4 +1,4 @@
|
||||
.TH jc 1 2022-10-21 1.22.1 "JSON Convert"
|
||||
.TH jc 1 2022-10-23 1.22.1 "JSON Convert"
|
||||
.SH NAME
|
||||
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types, and strings
|
||||
.SH SYNOPSIS
|
||||
|
1
tests/fixtures/ubuntu-20.10/lspci-mmv.json
vendored
Normal file
1
tests/fixtures/ubuntu-20.10/lspci-mmv.json
vendored
Normal file
File diff suppressed because one or more lines are too long
1
tests/fixtures/ubuntu-20.10/lspci-nmmv.json
vendored
Normal file
1
tests/fixtures/ubuntu-20.10/lspci-nmmv.json
vendored
Normal file
File diff suppressed because one or more lines are too long
1
tests/fixtures/ubuntu-20.10/lspci-nnmmv.json
vendored
Normal file
1
tests/fixtures/ubuntu-20.10/lspci-nnmmv.json
vendored
Normal file
File diff suppressed because one or more lines are too long
64
tests/test_lspci.py
Normal file
64
tests/test_lspci.py
Normal file
@ -0,0 +1,64 @@
|
||||
import os
|
||||
import unittest
|
||||
import json
|
||||
from typing import Dict
|
||||
import jc.parsers.lspci
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
f_in: Dict = {}
|
||||
f_json: Dict = {}
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
fixtures = {
|
||||
'ubuntu_20_10_lspci_mmv': (
|
||||
'fixtures/ubuntu-20.10/lspci-mmv.out',
|
||||
'fixtures/ubuntu-20.10/lspci-mmv.json'),
|
||||
'ubuntu_20_10_lspci_nmmv': (
|
||||
'fixtures/ubuntu-20.10/lspci-nmmv.out',
|
||||
'fixtures/ubuntu-20.10/lspci-nmmv.json'),
|
||||
'ubuntu_20_10_lspci_nnmmv': (
|
||||
'fixtures/ubuntu-20.10/lspci-nnmmv.out',
|
||||
'fixtures/ubuntu-20.10/lspci-nnmmv.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_lspci_nodata(self):
|
||||
"""
|
||||
Test 'lspci' with no data
|
||||
"""
|
||||
self.assertEqual(jc.parsers.lspci.parse('', quiet=True), [])
|
||||
|
||||
def test_lspci_mmv_ubuntu_20_10(self):
|
||||
"""
|
||||
Test 'lspci -mmv' on Ubuntu 20.10
|
||||
"""
|
||||
self.assertEqual(jc.parsers.lspci.parse(self.f_in['ubuntu_20_10_lspci_mmv'], quiet=True),
|
||||
self.f_json['ubuntu_20_10_lspci_mmv'])
|
||||
|
||||
def test_lspci_nmmv_ubuntu_20_10(self):
|
||||
"""
|
||||
Test 'lspci -nmmv' on Ubuntu 20.10
|
||||
"""
|
||||
self.assertEqual(jc.parsers.lspci.parse(self.f_in['ubuntu_20_10_lspci_nmmv'], quiet=True),
|
||||
self.f_json['ubuntu_20_10_lspci_nmmv'])
|
||||
|
||||
def test_lspci_nnmmv_ubuntu_20_10(self):
|
||||
"""
|
||||
Test 'lspci -nnmmv' on Ubuntu 20.10
|
||||
"""
|
||||
self.assertEqual(jc.parsers.lspci.parse(self.f_in['ubuntu_20_10_lspci_nnmmv'], quiet=True),
|
||||
self.f_json['ubuntu_20_10_lspci_nnmmv'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user