-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: 4dsherwood <[email protected]> Co-Authored-By: Nitsan Avni <[email protected]>
- Loading branch information
1 parent
f5c0e50
commit 29138a7
Showing
2 changed files
with
29 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 9 additions & 38 deletions
47
tests/reporters/test_reporter_that_creates_an_approval_script.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,9 @@ | ||
# use an approval test | ||
# generate the command file contents and approve that contents | ||
# two failing tests that use the new reporter | ||
from pathlib import Path | ||
|
||
from approvaltests import Options, verify, Reporter | ||
from approved_file_log import APPROVAL_TESTS_TEMP_DIRECTORY | ||
from reporters import get_command_text | ||
|
||
|
||
# approval_script.bat is the name of the script that will be created | ||
|
||
# We want a class, not a function. Reporters are classes. Case matters in Python. | ||
# Once we choose a reporter, we can use it in all our tests. | ||
|
||
|
||
class ReporterThatCreatesAnApprovalScript (Reporter): | ||
file = None | ||
def create_approval_script(self, script:str): | ||
if ReporterThatCreatesAnApprovalScript.file==None: | ||
ReporterThatCreatesAnApprovalScript.file = Path(APPROVAL_TESTS_TEMP_DIRECTORY)/"approval_script.bat" | ||
ReporterThatCreatesAnApprovalScript.file.mkdir(parents=True, exist_ok=True) | ||
ReporterThatCreatesAnApprovalScript.file.write_text("") | ||
dir = APPROVAL_TESTS_TEMP_DIRECTORY | ||
with open(f"{dir}/approval_script.bat", "a") as f: | ||
f.write(script) | ||
f.write("\n") | ||
|
||
def report(self, received_path: str, approved_path: str) -> bool: | ||
self.create_approval_script( get_command_text(received_path, approved_path)) | ||
return True | ||
|
||
|
||
def test_first(): | ||
verify("hello first test", options=Options().with_reporter(ReporterThatCreatesAnApprovalScript())) | ||
|
||
def test_two(): | ||
verify("hello second test", options=Options().with_reporter(ReporterThatCreatesAnApprovalScript())) | ||
# from approvaltests import Options, verify | ||
# from reporters.reporter_that_creates_an_approval_script import ReporterThatCreatesAnApprovalScript | ||
# | ||
# | ||
# def test_first(): | ||
# verify("hello first test", options=Options().with_reporter(ReporterThatCreatesAnApprovalScript())) | ||
# | ||
# def test_two(): | ||
# verify("hello second test", options=Options().with_reporter(ReporterThatCreatesAnApprovalScript())) |