Skip to content

Commit

Permalink
- F Added options.add_reporter
Browse files Browse the repository at this point in the history
Closes #162

Co-Authored-By: 4dsherwood <4dsherwood@users.noreply.github.com>
Co-Authored-By: Susan Fung <38925660+susanfung@users.noreply.github.com>
Co-Authored-By: Nitsan Avni <nitsanav@gmail.com>
Co-Authored-By: Nazee Hajebi <2491283+NazeeHajebi@users.noreply.github.com>
Co-Authored-By: bhargavgundu <7643639+bhargavgundu@users.noreply.github.com>
  • Loading branch information
6 people committed May 12, 2024
1 parent c7ba931 commit 0a88a14
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
19 changes: 3 additions & 16 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- [ ] docs: point to new architecture docs from python repo


Test are running on all CI machine

Typing -> Talking -> Next
Expand All @@ -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?
Expand Down
4 changes: 4 additions & 0 deletions approvaltests/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
3 changes: 3 additions & 0 deletions approvaltests/reporters/multi_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])})"
15 changes: 15 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)'

0 comments on commit 0a88a14

Please sign in to comment.