Skip to content

Commit

Permalink
Add test for malformed pdml
Browse files Browse the repository at this point in the history
  • Loading branch information
Enteee committed Oct 31, 2018
1 parent 0c08e89 commit d168045
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
6 changes: 5 additions & 1 deletion pdml2flow/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ def start_parser():
for name, value in Conf.get().items():
debug('{} : {}'.format(name, value))

handler = PdmlHandler()
try:
xml.sax.parse(Conf.IN, PdmlHandler())
xml.sax.parse(
Conf.IN,
handler
)
except xml.sax._exceptions.SAXParseException as e:
# this might happen when a pdml file is malformed
warning('Parser returned exception: {}'.format(e))
Expand Down
Empty file.
1 change: 1 addition & 0 deletions test/pdml2flow_tests/malformed/stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Warning: 0] Parser returned exception: test/pdml2flow_tests//malformed/stdin:1:0: syntax error
1 change: 1 addition & 0 deletions test/pdml2flow_tests/malformed/stdin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THIS IS NOT XML!!
Empty file.
30 changes: 23 additions & 7 deletions test/system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ def system_test(self):
io.StringIO() as f_stdout, \
io.StringIO() as f_stderr:

# set stdin & stdout
# wire up io
Conf.IN = f_stdin
Conf.OUT = f_stdout
Conf.OUT_DEBUG = f_stderr
Conf.OUT_WARNING = f_stderr
Conf.OUT_ERROR = f_stderr

try:
# try to load arguments
with open('{}/{}/args'.format(directory, test)) as f:
Expand All @@ -51,8 +55,10 @@ def system_test(self):
run()

# compare stdout
objs_raw =f_stdout.getvalue()
objs = self.read_json(objs_raw)
stdout_raw = f_stdout.getvalue()
objs = self.read_json(stdout_raw)

stderr_raw = f_stderr.getvalue()

with open('{}/{}/stdout'.format(directory, test)) as f:
expected_raw = f.read()
Expand All @@ -64,15 +70,25 @@ def system_test(self):

# if no object loaded, fall back to raw comparison
if len(expected) == 0 or len(objs) == 0:
self.assertEqual(expected_raw, objs_raw)
self.assertEqual(
expected_raw,
stdout_raw
)

try:
# try compare stderr
with open('{}/{}/stderr'.format(directory, test)) as f:
expected = c_stdout.read()
self.assertEqual(expected, f_stderr.getvalue())
expected_raw = f.read()
self.assertEqual(
expected_raw,
stderr_raw
)
except FileNotFoundError:
pass
self.assertEqual(
'',
stderr_raw
)

return system_test

def add_tests(run, directory):
Expand Down

0 comments on commit d168045

Please sign in to comment.