diff --git a/changelog.txt b/changelog.txt index 94c0ceba..934ae52e 100644 --- a/changelog.txt +++ b/changelog.txt @@ -6,6 +6,7 @@ jc changelog - 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 +- Update df parser to fix error on parsing empty data - Add tests to all parsers for no data condition 20200610 v1.11.4 diff --git a/jc/parsers/df.py b/jc/parsers/df.py index 880537f8..ab8a6ef7 100644 --- a/jc/parsers/df.py +++ b/jc/parsers/df.py @@ -73,7 +73,7 @@ import jc.parsers.universal class info(): - version = '1.3' + version = '1.4' description = 'df command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -184,14 +184,16 @@ def parse(data, raw=False, quiet=False): jc.utils.compatibility(__name__, info.compatible) cleandata = data.splitlines() + raw_output = [] - # fix headers - cleandata[0] = cleandata[0].lower() - cleandata[0] = cleandata[0].replace('-', '_') - cleandata[0] = cleandata[0].replace('mounted on', 'mounted_on') + if len(cleandata) > 1: + # fix headers + cleandata[0] = cleandata[0].lower() + cleandata[0] = cleandata[0].replace('-', '_') + cleandata[0] = cleandata[0].replace('mounted on', 'mounted_on') - # parse the data - raw_output = jc.parsers.universal.sparse_table_parse(cleandata) + # parse the data + raw_output = jc.parsers.universal.sparse_table_parse(cleandata) if raw: return raw_output diff --git a/tests/test_df.py b/tests/test_df.py index 47f928c1..d59ef778 100644 --- a/tests/test_df.py +++ b/tests/test_df.py @@ -59,6 +59,12 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/df-h.json'), 'r', encoding='utf-8') as f: self.osx_10_14_6_df_h_json = json.loads(f.read()) + def test_df_nodata(self): + """ + Test plain 'df' with no data + """ + self.assertEqual(jc.parsers.df.parse('', quiet=True), []) + def test_df_centos_7_7(self): """ Test plain 'df' on Centos 7.7