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
20
golden.py
20
golden.py
|
|
@ -15,7 +15,7 @@ def _accept_actual(failed):
|
|||
for actual_str, golden_path in failed:
|
||||
with open(golden_path, "w") as golden_file:
|
||||
golden_file.write(actual_str)
|
||||
print("Changed golden file: %s" % golden_path)
|
||||
print("Wrote golden file: %s" % golden_path)
|
||||
|
||||
|
||||
def _run_meld_gui(failed):
|
||||
|
|
@ -41,13 +41,21 @@ _FAILED = set()
|
|||
|
||||
|
||||
def assertGolden(actual, golden_path):
|
||||
with open(golden_path, "r") as golden_file:
|
||||
expected = golden_file.read()
|
||||
try:
|
||||
with open(golden_path, "r") as golden_file:
|
||||
expected = golden_file.read()
|
||||
except FileNotFoundError:
|
||||
expected = None
|
||||
if actual != expected:
|
||||
_FAILED.add((actual, golden_path))
|
||||
raise unittest.TestCase.failureException(
|
||||
'Output does not match golden file: %r\nUse "--diff" or'
|
||||
' "--accept" to update the golden file.' % 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(
|
||||
'Output does not match golden file: %r\nUse "--diff" or'
|
||||
' "--accept" to update the golden file.' % golden_path)
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue