Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
isidore committed Apr 28, 2024
2 parents 4bd9045 + f80f044 commit fb700dd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
3 changes: 1 addition & 2 deletions approvaltests/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def with_extension(
self,
extension_with_dot: str,
*, # enforce keyword arguments - https://www.python.org/dev/peps/pep-3102/,
no_override=False
no_override=False,
) -> "Options":
if not extension_with_dot.startswith("."):
extension_with_dot = "." + extension_with_dot
Expand Down Expand Up @@ -87,4 +87,3 @@ def inline(self, inline_options: InlineOptions = None) -> "Options":
from approvaltests.namer.inline_comparator import InlineComparator

return InlineComparator().register(self, inline_options)

25 changes: 16 additions & 9 deletions approvaltests/inline/inline_options.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@


class InlineOptions:

@staticmethod
def automatic():
from approvaltests.namer.inline_python_reporter import InlinePythonReporter
from approvaltests.reporters import ReporterThatAutomaticallyApproves

class AutomaticInlineOptions(InlineOptions):
def apply(self, options: "Options") -> "Options":
return options.with_reporter(InlinePythonReporter(ReporterThatAutomaticallyApproves()))
return options.with_reporter(
InlinePythonReporter(ReporterThatAutomaticallyApproves())
)

return AutomaticInlineOptions()

@staticmethod
Expand All @@ -19,14 +20,20 @@ def semi_automatic():

class SemiAutomaticInlineOptions(InlineOptions):
def apply(self, options: "Options") -> "Options":
return options.with_reporter(InlinePythonReporter(ReporterThatAutomaticallyApproves(), add_approval_line=True))
return options.with_reporter(
InlinePythonReporter(
ReporterThatAutomaticallyApproves(), add_approval_line=True
)
)

return SemiAutomaticInlineOptions()

@staticmethod
@staticmethod
def applesauce():
return InlineOptions()

def apply(self, options: "Options") -> "Options":

return options

@staticmethod
Expand All @@ -36,9 +43,9 @@ def show_code(do_show_code: bool = True):
class ShowCodeInlineOptions(InlineOptions):
def apply(self, options: "Options") -> "Options":
return options.with_reporter(InlinePythonReporter(options.reporter))

class DoNotShowCodeInlineOptions(InlineOptions):
def apply(self, options: "Options") -> "Options":
return options

return ShowCodeInlineOptions() if do_show_code else DoNotShowCodeInlineOptions()

8 changes: 6 additions & 2 deletions approvaltests/namer/inline_python_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
class InlinePythonReporter(Reporter):
def __init__(self, reporter, add_approval_line=False):
self.diffReporter = reporter
self.semi_automatic_extra_line = "\n***** DELETE ME TO APPROVE *****" if add_approval_line else ""
self.semi_automatic_extra_line = (
"\n***** DELETE ME TO APPROVE *****" if add_approval_line else ""
)

def report(self, received_path: str, approved_path: str) -> bool:
test_source_file = self.get_test_source_file()
Expand All @@ -22,7 +24,9 @@ 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.semi_automatic_extra_line
received_text = (
Path(received_path).read_text()[:-1] + self.semi_automatic_extra_line
)
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

0 comments on commit fb700dd

Please sign in to comment.