tests: Rework how we pass command line objects down to test data

This commit is contained in:
Cole Robinson 2018-01-08 17:05:55 -05:00
parent 89945118df
commit 044d93d471
3 changed files with 14 additions and 5 deletions

View File

@ -431,7 +431,8 @@ class TestBaseCommand(distutils.core.Command):
cov.start()
import tests as testsmodule
testsmodule.utils.REGENERATE_OUTPUT = bool(self.regenerate_output)
testsmodule.utils.clistate.regenerate_output = bool(
self.regenerate_output)
# This makes the test runner report results before exiting from ctrl-c
unittest.installHandler()

View File

@ -252,7 +252,8 @@ class Command(object):
# Generate test files that don't exist yet
filename = self.compare_file
if utils.REGENERATE_OUTPUT or not os.path.exists(filename):
if (utils.clistate.regenerate_output or
not os.path.exists(filename)):
open(filename, "w").write(output)
if "--print-diff" in self.argv and output.count("\n") > 3:

View File

@ -22,12 +22,19 @@ import virtinst
import virtinst.cli
import virtinst.uri
# DON'T EDIT THIS. Use 'setup.py test --regenerate-output'
REGENERATE_OUTPUT = False
# pylint: disable=protected-access
# Access to protected member, needed to unittest stuff
class _CLIState(object):
"""
Class containing any bits passed in from setup.py
"""
def __init__(self):
self.regenerate_output = False
clistate = _CLIState()
_capsprefix = ",caps=%s/tests/capabilities-xml/" % os.getcwd()
_domcapsprefix = ",domcaps=%s/tests/capabilities-xml/" % os.getcwd()
@ -175,7 +182,7 @@ def read_file(filename):
def diff_compare(actual_out, filename=None, expect_out=None):
"""Compare passed string output to contents of filename"""
if not expect_out:
if not os.path.exists(filename) or REGENERATE_OUTPUT:
if not os.path.exists(filename) or clistate.regenerate_output:
open(filename, "w").write(actual_out)
expect_out = read_file(filename)