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-10 17:20:09 -07:00
parent 35d733b44f
commit d8f2f4c95b
5 changed files with 82 additions and 66 deletions

View File

@ -4,6 +4,8 @@ jc changelog
- Update airport_s parser to fix error on parsing empty data - Update airport_s parser to fix error on parsing empty data
- Update arp parser to fix error on parsing empty data - Update arp parser to fix error on parsing empty data
- Update blkid parser to fix error on parsing empty data - Update blkid parser to fix error on parsing empty data
- Update crontab parser to fix error on parsing empty data
- Update crontab_u parser to fix error on parsing empty data
- Add tests to all parsers for no data condition - Add tests to all parsers for no data condition
20200610 v1.11.4 20200610 v1.11.4

View File

@ -132,7 +132,7 @@ import jc.parsers.universal
class info(): class info():
version = '1.2' version = '1.3'
description = 'crontab command and file parser' description = 'crontab command and file parser'
author = 'Kelly Brazil' author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com' author_email = 'kellyjonbrazil@gmail.com'
@ -225,6 +225,7 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines # Clear any blank lines
cleandata = list(filter(None, cleandata)) cleandata = list(filter(None, cleandata))
if cleandata:
# Clear any commented lines # Clear any commented lines
for i, line in reversed(list(enumerate(cleandata))): for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('#'): if line.strip().startswith('#'):

View File

@ -133,7 +133,7 @@ import jc.parsers.universal
class info(): class info():
version = '1.1' version = '1.2'
description = 'crontab file parser with user support' description = 'crontab file parser with user support'
author = 'Kelly Brazil' author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com' author_email = 'kellyjonbrazil@gmail.com'
@ -226,6 +226,7 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines # Clear any blank lines
cleandata = list(filter(None, cleandata)) cleandata = list(filter(None, cleandata))
if cleandata:
# Clear any commented lines # Clear any commented lines
for i, line in reversed(list(enumerate(cleandata))): for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('#'): if line.strip().startswith('#'):

View File

@ -17,6 +17,12 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/crontab.json'), 'r', encoding='utf-8') as f: with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/crontab.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_crontab_json = json.loads(f.read()) self.centos_7_7_crontab_json = json.loads(f.read())
def test_crontab_nodata(self):
"""
Test 'crontab' with no data
"""
self.assertEqual(jc.parsers.crontab.parse('', quiet=True), {})
def test_crontab_centos_7_7(self): def test_crontab_centos_7_7(self):
""" """
Test 'crontab' on Centos 7.7 Test 'crontab' 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/centos-7.7/crontab-u.json'), 'r', encoding='utf-8') as f: with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/crontab-u.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_crontab_u_json = json.loads(f.read()) self.centos_7_7_crontab_u_json = json.loads(f.read())
def test_crontab_u_nodata(self):
"""
Test 'crontab' with no data (has a user field)
"""
self.assertEqual(jc.parsers.crontab_u.parse('', quiet=True), {})
def test_crontab_u_ubuntu_18_4(self): def test_crontab_u_ubuntu_18_4(self):
""" """
Test 'crontab' on Ubuntu 18.4 (has a user field) Test 'crontab' on Ubuntu 18.4 (has a user field)