mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-18 06:03:58 +03:00
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>
This commit is contained in:
parent
effe274a9b
commit
4ca0d2c29b
@ -284,10 +284,6 @@ class Command(object):
|
|||||||
newlines.append(line)
|
newlines.append(line)
|
||||||
output = "\n".join(newlines)
|
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
|
# Strip the test directory out of the saved output
|
||||||
search = '"%s/' % utils.TOPDIR
|
search = '"%s/' % utils.TOPDIR
|
||||||
if search in output:
|
if search in output:
|
||||||
|
@ -219,13 +219,32 @@ def test_create(testconn, xml, define_func="defineXML"):
|
|||||||
|
|
||||||
|
|
||||||
def diff_compare(actual_out, filename=None, expect_out=None):
|
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 expect_out:
|
||||||
if not os.path.exists(filename) or TESTCONFIG.regenerate_output:
|
if not os.path.exists(filename) or TESTCONFIG.regenerate_output:
|
||||||
open(filename, "w").write(actual_out)
|
open(filename, "w").write(actual_out)
|
||||||
expect_out = open(filename).read()
|
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")
|
filename or '', "Generated output")
|
||||||
if diff:
|
if diff:
|
||||||
raise AssertionError("Conversion outputs did not match.\n%s" % diff)
|
raise AssertionError("Conversion outputs did not match.\n%s" % diff)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user