diff options
author | Cole Robinson <crobinso@redhat.com> | 2022-08-03 10:33:12 -0400 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2022-08-03 12:34:47 -0400 |
commit | 4ca0d2c29b9cf754f0203f6f1fbe32c472524c34 (patch) | |
tree | ad7d0e7a00b3e12aaac787496d4f7cafedfa199f /tests | |
parent | effe274a9be478a21f3f0baf864cf3103a9a8b73 (diff) | |
download | virt-manager-4ca0d2c29b9cf754f0203f6f1fbe32c472524c34.tar.gz |
tests: More trailing newline fixes
The diff_compare rstrip() should never have been added, let's fix
it once and for all but dealing with missing newlines in the diff
helper
Signed-off-by: Cole Robinson <crobinso@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cli.py | 4 | ||||
-rw-r--r-- | tests/utils.py | 23 |
2 files changed, 21 insertions, 6 deletions
diff --git a/tests/test_cli.py b/tests/test_cli.py index 7d7b5a9b..774db098 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 ae50aa91..5c813f62 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) |