From f80f044bef87c92957083d5a5fa30f945df8aa83 Mon Sep 17 00:00:00 2001 From: github actions Date: Sun, 28 Apr 2024 19:27:28 +0000 Subject: [PATCH] d updated markdown snippets --- approvaltests/core/options.py | 6 +-- approvaltests/inline/inline_options.py | 25 +++++++---- approvaltests/namer/inline_comparator.py | 4 +- approvaltests/namer/inline_python_reporter.py | 8 +++- tests/test_inline_approvals.py | 41 +++++++------------ 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/approvaltests/core/options.py b/approvaltests/core/options.py index b98ce8a..bd2d03a 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 @@ -85,6 +85,6 @@ def namer(self) -> Namer: def inline(self, inline_options: InlineOptions = None) -> "Options": from approvaltests.namer.inline_comparator import InlineComparator - print(f'inline_options = {inline_options.__class__.__name__}') - return InlineComparator().register(self, inline_options) + print(f"inline_options = {inline_options.__class__.__name__}") + 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_comparator.py b/approvaltests/namer/inline_comparator.py index 01eed1d..cfa61aa 100644 --- a/approvaltests/namer/inline_comparator.py +++ b/approvaltests/namer/inline_comparator.py @@ -43,11 +43,11 @@ def get_caller_method(caller_frame) -> Callable: caller_function_object = clazz.__dict__.get(caller_function_name) return caller_function_object -#return InlineComparator().register(self, inline_options) + # return InlineComparator().register(self, inline_options) def register(self, options: "Options", inline_options: InlineOptions = None): inline_options = InlineOptions() if inline_options is None else inline_options options2 = options.with_namer(self) - print(f'inline_options = {inline_options.__class__.__name__}') + print(f"inline_options = {inline_options.__class__.__name__}") options2 = inline_options.apply(options2) return options2 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 diff --git a/tests/test_inline_approvals.py b/tests/test_inline_approvals.py index dc6fa55..52688c8 100644 --- a/tests/test_inline_approvals.py +++ b/tests/test_inline_approvals.py @@ -79,11 +79,6 @@ def greeting(): return "hello\nworld" - - - - - def test_docstring_parsing(): """ 1 @@ -177,41 +172,35 @@ def test_bug_blank_lines(): """ - verify( - "\n\ntest bug with blank lines\n\n\n\n", - options=Options().inline() - ) - - - + verify("\n\ntest bug with blank lines\n\n\n\n", options=Options().inline()) def test_semi_automatic_inline_reporter(): """ 1 2 - - """ - #verify("1\n2\n5", options=Options().inline(InlineOptions.semi_automatic())) - #verify("1\n2\n5", options=Options().inline(InlineOptions.automatic())) - # verify("1\n2\n5", options=Options().inline(InlineOptions.applesauce())) # when it is false - #verify("1\n2\n5", options=Options().inline(InlineOptions.show_code())) - verify("1\n2\n5", options=Options().inline(InlineOptions.show_code())) - + + """ + # verify("1\n2\n5", options=Options().inline(InlineOptions.semi_automatic())) + # verify("1\n2\n5", options=Options().inline(InlineOptions.automatic())) + # verify("1\n2\n5", options=Options().inline(InlineOptions.applesauce())) # when it is false + # verify("1\n2\n5", options=Options().inline(InlineOptions.show_code())) + verify("1\n2\n5", options=Options().inline(InlineOptions.show_code())) + # show_code # keep show_code becase we only want to change one thing at time - + # reports contents only # report contents without showing code # compare full source code - # report on + # report on # inline only on test resutls - #report docstring only only report the docstring + # report docstring only only report the docstring # report results only # report results and docstring - #use diffcompare in traditional way + # use diffcompare in traditional way # use diffcompare in inline way - #only report the results + # only report the results # report results only # report results without surrounding code # report results no surrounding code @@ -220,4 +209,4 @@ def test_semi_automatic_inline_reporter(): # diffcompare in inline way # --- # showcode = false - # \ No newline at end of file + #