Skip to content

Commit

Permalink
. d updated markdown snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed May 19, 2024
1 parent 1b17eaf commit e9ca727
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
15 changes: 9 additions & 6 deletions approvaltests/inline/inline_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

DELETE_ME_TO_APPROVE_ = "\n***** DELETE ME TO APPROVE *****"


class InlineOptions:

@staticmethod
Expand All @@ -27,8 +28,10 @@ def semi_automatic():
class SemiAutomaticInlineOptions(InlineOptions):
def apply(self, options: "Options") -> "Options":
return options.with_reporter(
InlinePythonReporter(ReporterThatAutomaticallyApproves(),
create_footer_function=lambda __: DELETE_ME_TO_APPROVE_)
InlinePythonReporter(
ReporterThatAutomaticallyApproves(),
create_footer_function=lambda __: DELETE_ME_TO_APPROVE_,
)
)

return SemiAutomaticInlineOptions()
Expand All @@ -48,8 +51,10 @@ def create_previous_capture_footer(approved_path):
class PreviousCaptureInlineOptions(InlineOptions):
def apply(self, options: "Options") -> "Options":
return options.with_reporter(
InlinePythonReporter(ReporterThatAutomaticallyApproves(),
create_footer_function=create_previous_capture_footer)
InlinePythonReporter(
ReporterThatAutomaticallyApproves(),
create_footer_function=create_previous_capture_footer,
)
)

return PreviousCaptureInlineOptions()
Expand All @@ -71,5 +76,3 @@ def apply(self, options: "Options") -> "Options":
return options

return ShowCodeInlineOptions() if do_show_code else DoNotShowCodeInlineOptions()


9 changes: 5 additions & 4 deletions approvaltests/namer/inline_python_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
from approvaltests import Reporter, StackFrameNamer
from approvaltests.inline.split_code import SplitCode


class InlinePythonReporter(Reporter):
def __init__(self, reporter: Reporter, create_footer_function: Callable[[str],str]=None):
def __init__(
self, reporter: Reporter, create_footer_function: Callable[[str], str] = None
):
self.diffReporter = reporter
self.footer_function = create_footer_function or (lambda __: "")
self.footer = ""
Expand All @@ -25,9 +28,7 @@ def get_test_source_file(self):
def create_received_file(self, received_path: str, test_source_file: str):
code = Path(test_source_file).read_text()

received_text = (
Path(received_path).read_text()[:-1] + self.footer
)
received_text = Path(received_path).read_text()[:-1] + self.footer
method_name = StackFrameNamer.get_test_frame().function
new_code = self.swap(received_text, code, method_name)
file = tempfile.NamedTemporaryFile(suffix=".received.txt", delete=False).name
Expand Down
6 changes: 4 additions & 2 deletions tests/test_inline_approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def test_inline_with_additional_reporter():
"hello\nworld",
options=(Options().inline().add_reporter(ReportWithBeyondCompare())),
)



def test_inline_with_preserved_approved_text():
"""
42
Expand All @@ -202,7 +203,8 @@ def test_inline_with_preserved_approved_text():
except ApprovalException:
pass
verify(get_approved_via_doc_string())



def test_inline_with_semi_automatic_inline():
"""
42
Expand Down

0 comments on commit e9ca727

Please sign in to comment.