diff --git a/TODO.md b/TODO.md index 37ee5a6..8c04943 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,6 @@ +- [ ] docs: point to new architecture docs from python repo + + Test are running on all CI machine Typing -> Talking -> Next @@ -18,22 +21,6 @@ Rotate on green was designed for git handoff, each commit is green Ping-Pong Pairing Try to make the smallest change possible, then rotate -Support inline on CyberDojo -IF it is in CyberDojo AND inline approvals, - THEN we need to do a deep compare - -how could we fix this? -option 1: we can use the automatic approver - not there is a bug in the automatic approver -option 2: Llewellyns idea - -make semi automatic -original plan modify auto reporter - instead we will make this work -then Come back and impement this in an API -and that will depend on what the implementation looks like -Add an extra line for this specific case - POssible FEATURE Create an API to add a REPORTER.[test_inline_approvals.py](tests%2Ftest_inline_approvals.p[ok.approved.txt](ok.approved.txt)y) now we have a combined reporter and then ?? only the last one works? diff --git a/approvaltests/core/options.py b/approvaltests/core/options.py index c430fc2..36c2c98 100644 --- a/approvaltests/core/options.py +++ b/approvaltests/core/options.py @@ -87,3 +87,7 @@ def inline(self, inline_options: InlineOptions = None) -> "Options": from approvaltests.namer.inline_comparator import InlineComparator return InlineComparator().register(self, inline_options) + + def add_reporter(self, additional_reporter: Reporter) -> "Options": + from approvaltests.reporters import MultiReporter + return self.with_reporter(MultiReporter(self.reporter, additional_reporter)) diff --git a/approvaltests/reporters/multi_reporter.py b/approvaltests/reporters/multi_reporter.py index 80de66c..68eb416 100644 --- a/approvaltests/reporters/multi_reporter.py +++ b/approvaltests/reporters/multi_reporter.py @@ -16,3 +16,6 @@ def __init__(self, *reporters) -> None: def report(self, received_path, approved_path): for reporter in self.reporters: reporter.report(received_path, approved_path) + + def __str__(self): + return f"MultiReporter({', '.join([r.__class__.__name__ for r in self.reporters])})" \ No newline at end of file diff --git a/tests/test_options.py b/tests/test_options.py index 3a42abd..4b75218 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -9,6 +9,8 @@ ) from approvaltests.core.options import Options from approvaltests.mrjob import mrjob_approvals +from approvaltests.reporters import ReportByCreatingDiffFile, MultiReporter +from approvaltests.reporters.report_with_beyond_compare import ReportWithPycharm from approvaltests.utilities import command_line_approvals from approvaltests.utilities.logger import simple_logger_approvals @@ -66,3 +68,16 @@ def test_file_extensions(): verify(content, options=Options().for_file.with_extension(".md")) # end-snippet verify(content, options=Options().for_file.with_extension("md")) + +def test_add_reporter(): + # current behaviour, override + options0 = Options().with_reporter(ReportByCreatingDiffFile()).with_reporter(ReportWithPycharm()) + assert type(options0.reporter) == ReportWithPycharm + + # current work around, create a MultiReporter + options_multi = Options().with_reporter(MultiReporter(ReportByCreatingDiffFile(), ReportWithPycharm())) + assert str(options_multi.reporter) == 'MultiReporter(ReportByCreatingDiffFile, ReportWithPycharm)' + + # new behaviour, append + options0 = Options().with_reporter(ReportByCreatingDiffFile()).add_reporter(ReportWithPycharm()) + assert str(options_multi.reporter) == 'MultiReporter(ReportByCreatingDiffFile, ReportWithPycharm)'