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

add input type checks

This commit is contained in:
Kelly Brazil
2021-11-30 09:56:33 -08:00
parent caf0a5c871
commit 3a9f0934c4
2 changed files with 5 additions and 3 deletions

View File

@ -123,13 +123,15 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False):
Iterator object
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
if not quiet: jc.utils.compatibility(__name__, info.compatible)
if not hasattr(data, '__iter__') or isinstance(data, (str, bytes)):
raise TypeError("Input data must be a non-string iterable object.")
parent = ''
for line in data:
try:
if not isinstance(line, str): raise TypeError("Input line must be a 'str' object.")
# skip line if it starts with 'total 1234'
if re.match(r'total [0-9]+', line):

View File

@ -103,7 +103,7 @@ class MyTests(unittest.TestCase):
"""
Test plain 'ls' on an empty directory
"""
self.assertEqual(list(jc.parsers.ls_s.parse('', quiet=True)), [])
self.assertEqual(list(jc.parsers.ls_s.parse([], quiet=True)), [])
def test_ls_s_centos_7_7_raise_exception(self):
"""