mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-07 00:57:22 +02:00
raise ParseError if -t option is detected. add test
This commit is contained in:
@ -257,6 +257,7 @@ Examples:
|
||||
"""
|
||||
import jc.utils
|
||||
from jc.parsers.universal import sparse_table_parse
|
||||
from jc.exceptions import ParseError
|
||||
|
||||
|
||||
class info():
|
||||
@ -823,6 +824,10 @@ def parse(data, raw=False, quiet=False):
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
for line in data.splitlines():
|
||||
# only -v option or no options are supported
|
||||
if line.startswith('/'):
|
||||
raise ParseError('Only `lsusb` or `lsusb -v` are supported.')
|
||||
|
||||
# sections
|
||||
if lsusb._set_sections(line):
|
||||
continue
|
||||
|
15
tests/fixtures/generic/lsusb-t.out
vendored
Normal file
15
tests/fixtures/generic/lsusb-t.out
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
/: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 5000M
|
||||
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
|
||||
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|
||||
|__ Port 2: Dev 90, If 0, Class=Communications, Driver=cdc_acm, 12M
|
||||
|__ Port 2: Dev 90, If 1, Class=CDC Data, Driver=cdc_acm, 12M
|
||||
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
|
||||
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 480M
|
||||
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
|
||||
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
|
||||
|__ Port 1: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|
||||
|__ Port 2: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|
||||
|__ Port 6: Dev 66, If 0, Class=Hub, Driver=hub/4p, 480M
|
||||
|__ Port 1: Dev 67, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|
||||
|__ Port 1: Dev 67, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
|
||||
|
@ -2,6 +2,7 @@ import os
|
||||
import json
|
||||
import unittest
|
||||
import jc.parsers.lsusb
|
||||
from jc.exceptions import ParseError
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
@ -25,6 +26,9 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/lsusb-test-attributes2.out'), 'r', encoding='utf-8') as f:
|
||||
self.generic_lsusb_test_attributes2 = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/lsusb-t.out'), 'r', encoding='utf-8') as f:
|
||||
self.generic_lsusb_t = f.read()
|
||||
|
||||
# output
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/lsusb.json'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_lsusb_json = json.loads(f.read())
|
||||
@ -47,6 +51,12 @@ class MyTests(unittest.TestCase):
|
||||
"""
|
||||
self.assertEqual(jc.parsers.lsusb.parse('', quiet=True), [])
|
||||
|
||||
def test_lsusb_parse_error_generic(self):
|
||||
"""
|
||||
Test 'lsusb' with -t option (should raise ParseError)
|
||||
"""
|
||||
self.assertRaises(ParseError, jc.parsers.lsusb.parse, self.generic_lsusb_t, quiet=True)
|
||||
|
||||
def test_lsusb_centos_7_7(self):
|
||||
"""
|
||||
Test 'lsusb' on Centos 7.7
|
||||
|
Reference in New Issue
Block a user