diff --git a/approvaltests/core/options.py b/approvaltests/core/options.py index 02b5f60..c430fc2 100644 --- a/approvaltests/core/options.py +++ b/approvaltests/core/options.py @@ -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 @@ -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) - diff --git a/approvaltests/inline/inline_options.py b/approvaltests/inline/inline_options.py index 52722f9..43d7254 100644 --- a/approvaltests/inline/inline_options.py +++ b/approvaltests/inline/inline_options.py @@ -1,7 +1,5 @@ - - class InlineOptions: - + @staticmethod def automatic(): from approvaltests.namer.inline_python_reporter import InlinePythonReporter @@ -9,7 +7,10 @@ def automatic(): class AutomaticInlineOptions(InlineOptions): def apply(self, options: "Options") -> "Options": - return options.with_reporter(InlinePythonReporter(ReporterThatAutomaticallyApproves())) + return options.with_reporter( + InlinePythonReporter(ReporterThatAutomaticallyApproves()) + ) + return AutomaticInlineOptions() @staticmethod @@ -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 @@ -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() - \ No newline at end of file diff --git a/approvaltests/namer/inline_python_reporter.py b/approvaltests/namer/inline_python_reporter.py index 8f94777..57de419 100644 --- a/approvaltests/namer/inline_python_reporter.py +++ b/approvaltests/namer/inline_python_reporter.py @@ -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() @@ -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