Golden files will be created by the --accept option when they don't exist.
The golden file's directory will at least need to exist.
This commit is contained in:
parent
61e2acae60
commit
d769fa6971
1 changed files with 14 additions and 6 deletions
10
golden.py
10
golden.py
|
|
@ -15,7 +15,7 @@ def _accept_actual(failed):
|
||||||
for actual_str, golden_path in failed:
|
for actual_str, golden_path in failed:
|
||||||
with open(golden_path, "w") as golden_file:
|
with open(golden_path, "w") as golden_file:
|
||||||
golden_file.write(actual_str)
|
golden_file.write(actual_str)
|
||||||
print("Changed golden file: %s" % golden_path)
|
print("Wrote golden file: %s" % golden_path)
|
||||||
|
|
||||||
|
|
||||||
def _run_meld_gui(failed):
|
def _run_meld_gui(failed):
|
||||||
|
|
@ -41,10 +41,18 @@ _FAILED = set()
|
||||||
|
|
||||||
|
|
||||||
def assertGolden(actual, golden_path):
|
def assertGolden(actual, golden_path):
|
||||||
|
try:
|
||||||
with open(golden_path, "r") as golden_file:
|
with open(golden_path, "r") as golden_file:
|
||||||
expected = golden_file.read()
|
expected = golden_file.read()
|
||||||
|
except FileNotFoundError:
|
||||||
|
expected = None
|
||||||
if actual != expected:
|
if actual != expected:
|
||||||
_FAILED.add((actual, golden_path))
|
_FAILED.add((actual, golden_path))
|
||||||
|
if expected is None:
|
||||||
|
raise unittest.TestCase.failureException(
|
||||||
|
'The golden file does not exist: %r\nUse "--diff" or'
|
||||||
|
' "--accept" to create the golden file.' % golden_path)
|
||||||
|
else:
|
||||||
raise unittest.TestCase.failureException(
|
raise unittest.TestCase.failureException(
|
||||||
'Output does not match golden file: %r\nUse "--diff" or'
|
'Output does not match golden file: %r\nUse "--diff" or'
|
||||||
' "--accept" to update the golden file.' % golden_path)
|
' "--accept" to update the golden file.' % golden_path)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue