1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

fix for no data

This commit is contained in:
Kelly Brazil
2020-06-11 17:59:06 -07:00
parent 1b57ec92f0
commit 04d2eec558
6 changed files with 58 additions and 32 deletions

View File

@ -15,6 +15,8 @@ jc changelog
- Update ntpq parser to fix error on parsing empty data
- Update ps parser to fix error on parsing empty data
- Update route parser to fix error on parsing empty data
- Update systemctl parser to fix error on parsing empty data
- Update systemctl_lj parser to fix error on parsing empty data
- Add tests to all parsers for no data condition
- Update ss parser to fix integer fields

View File

@ -40,7 +40,7 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'systemctl command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -99,6 +99,9 @@ def parse(data, raw=False, quiet=False):
linedata = data.splitlines()
# Clear any blank lines
linedata = list(filter(None, linedata))
raw_output = []
if linedata:
# clean up non-ascii characters, if any
cleandata = []
for entry in linedata:

View File

@ -59,7 +59,7 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'systemctl list-jobs command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -126,6 +126,9 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
linedata = list(filter(None, linedata))
# clean up non-ascii characters, if any
raw_output = []
if linedata:
cleandata = []
for entry in linedata:
cleandata.append(entry.encode('ascii', errors='ignore').decode())

View File

@ -35,6 +35,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/stat.json'), 'r', encoding='utf-8') as f:
self.freebsd12_stat_json = json.loads(f.read())
def test_stat_nodata(self):
"""
Test 'stat' with no data
"""
self.assertEqual(jc.parsers.stat.parse('', quiet=True), [])
def test_stat_centos_7_7(self):
"""
Test 'stat /bin/*' on Centos 7.7

View File

@ -23,6 +23,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/systemctl.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_systemctl_json = json.loads(f.read())
def test_systemctl_nodata(self):
"""
Test 'systemctl' with no data
"""
self.assertEqual(jc.parsers.systemctl.parse('', quiet=True), [])
def test_systemctl_centos_7_7(self):
"""
Test 'systemctl -a' on Centos 7.7

View File

@ -17,6 +17,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/systemctl-lj.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_systemctl_lj_json = json.loads(f.read())
def test_systemctl_lj_nodata(self):
"""
Test 'systemctl -a list-jobs' with no data
"""
self.assertEqual(jc.parsers.systemctl_lj.parse('', quiet=True), [])
def test_systemctl_lj_ubuntu_18_4(self):
"""
Test 'systemctl -a list-jobs' on Ubuntu 18.4