From 5044388ab2e8d7d8b427fd51b0ab875611bd127f Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Sun, 26 Sep 2021 13:04:27 -0700 Subject: [PATCH] raise if line data is unrecognized --- jc/parsers/vmstat_s.py | 6 +++++- tests/test_vmstat_s.py | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/jc/parsers/vmstat_s.py b/jc/parsers/vmstat_s.py index e194ab42..77e44562 100644 --- a/jc/parsers/vmstat_s.py +++ b/jc/parsers/vmstat_s.py @@ -74,6 +74,7 @@ Examples: """ import jc.utils from jc.utils import stream_success, stream_error +from jc.exceptions import ParseError class info(): @@ -232,7 +233,10 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False): 'timezone': tz or None } - yield stream_success(output_line, ignore_exceptions) if raw else stream_success(_process(output_line), ignore_exceptions) + if output_line: + yield stream_success(output_line, ignore_exceptions) if raw else stream_success(_process(output_line), ignore_exceptions) + else: + raise ParseError('Not vmstat data') except Exception as e: yield stream_error(e, ignore_exceptions, line) diff --git a/tests/test_vmstat_s.py b/tests/test_vmstat_s.py index 077b3504..ec14302b 100644 --- a/tests/test_vmstat_s.py +++ b/tests/test_vmstat_s.py @@ -71,7 +71,6 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/vmstat-1-long-streaming.json'), 'r', encoding='utf-8') as f: self.ubuntu_18_04_vmstat_1_long_streaming_json = json.loads(f.read()) - def test_vmstat_nodata(self): """ Test 'vmstat' with no data @@ -81,7 +80,7 @@ class MyTests(unittest.TestCase): def test_vmstat_unparsable(self): data = 'unparsable data' g = jc.parsers.vmstat_s.parse(data.splitlines(), quiet=True) - with self.assertRaises(KeyError): + with self.assertRaises(ParseError): list(g) def test_vmstat_centos_7_7(self):