diff --git a/tests/test_cli.py b/tests/test_cli.py index 7d7b5a9bb..774db098f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -284,10 +284,6 @@ class Command(object): newlines.append(line) output = "\n".join(newlines) - # Make sure all test output has trailing newline, simplifies diffing - if not output.endswith("\n"): - output += "\n" - # Strip the test directory out of the saved output search = '"%s/' % utils.TOPDIR if search in output: diff --git a/tests/utils.py b/tests/utils.py index ae50aa91b..5c813f625 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -219,13 +219,32 @@ def test_create(testconn, xml, define_func="defineXML"): def diff_compare(actual_out, filename=None, expect_out=None): - """Compare passed string output to contents of filename""" + """ + Test suite helper for comparing two strings + + If filename is passed, but the file doesn't exist, we write actual_out + to it. This makes it easy to populate output for new testcases + + If the --regenerate-output pytest flag was passed, we re-write every + specified filename. + + @actual_out: Output we generated + @filename: filename where expected good test output is stored + @expect_out: expected string to compare against + """ + # Make sure all test output has trailing newline, simplifies diffing + if not actual_out.endswith("\n"): + actual_out += "\n" + if not expect_out: if not os.path.exists(filename) or TESTCONFIG.regenerate_output: open(filename, "w").write(actual_out) expect_out = open(filename).read() - diff = xmlutil.diff(expect_out.rstrip(), actual_out.rstrip(), + if not expect_out.endswith("\n"): + expect_out += "\n" + + diff = xmlutil.diff(expect_out, actual_out, filename or '', "Generated output") if diff: raise AssertionError("Conversion outputs did not match.\n%s" % diff)