mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-13 01:20:24 +02:00
add length guard and test for uname with no -a on linux
This commit is contained in:
@ -119,11 +119,12 @@ def parse(data, raw=False, quiet=False):
|
||||
# case of only two existing is undefined. Must either be one or all three existing, otherwise
|
||||
# there will be unexpected results during parsing.
|
||||
fixup = data.split()
|
||||
fixup_set = set([fixup[-2], fixup[-3], fixup[-4]])
|
||||
if len(fixup_set) > 2:
|
||||
fixup.insert(-1, 'unknown')
|
||||
fixup.insert(-1, 'unknown')
|
||||
data = ' '.join(fixup)
|
||||
if len(fixup) >= 4:
|
||||
fixup_set = set([fixup[-2], fixup[-3], fixup[-4]])
|
||||
if len(fixup_set) > 2:
|
||||
fixup.insert(-1, 'unknown')
|
||||
fixup.insert(-1, 'unknown')
|
||||
data = ' '.join(fixup)
|
||||
|
||||
parsed_line = data.split(maxsplit=3)
|
||||
|
||||
|
1
tests/fixtures/centos-7.7/uname.out
vendored
Normal file
1
tests/fixtures/centos-7.7/uname.out
vendored
Normal file
@ -0,0 +1 @@
|
||||
Linux
|
@ -13,6 +13,9 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/uname-a.out'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_uname_a = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/uname.out'), 'r', encoding='utf-8') as f:
|
||||
self.centos_7_7_uname = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/uname-a.out'), 'r', encoding='utf-8') as f:
|
||||
self.ubuntu_18_4_uname_a = f.read()
|
||||
|
||||
@ -74,12 +77,18 @@ class MyTests(unittest.TestCase):
|
||||
"""
|
||||
self.assertEqual(jc.parsers.uname.parse('', quiet=True), {})
|
||||
|
||||
def test_uname_no_a(self):
|
||||
def test_uname_no_a_osx(self):
|
||||
"""
|
||||
Test 'uname' without -a option. Should generate a ParseError exception
|
||||
Test 'uname' without -a option on OSX. Should generate a ParseError exception
|
||||
"""
|
||||
self.assertRaises(jc.parsers.uname.ParseError, jc.parsers.uname.parse, self.osx_10_14_6_uname)
|
||||
|
||||
def test_uname_no_a_centos(self):
|
||||
"""
|
||||
Test 'uname' without -a option on Centos. Should generate a ParseError exception
|
||||
"""
|
||||
self.assertRaises(jc.parsers.uname.ParseError, jc.parsers.uname.parse, self.centos_7_7_uname)
|
||||
|
||||
def test_uname_centos_7_7(self):
|
||||
"""
|
||||
Test 'uname -a' on Centos 7.7
|
||||
|
Reference in New Issue
Block a user