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 Apr 28, 2024
1 parent 6f9dc65 commit f80f044
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
6 changes: 3 additions & 3 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 @@ -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)
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()

4 changes: 2 additions & 2 deletions approvaltests/namer/inline_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
41 changes: 15 additions & 26 deletions tests/test_inline_approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ def greeting():
return "hello\nworld"







def test_docstring_parsing():
"""
1
Expand Down Expand Up @@ -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
Expand All @@ -220,4 +209,4 @@ def test_semi_automatic_inline_reporter():
# diffcompare in inline way
# ---
# showcode = false
#
#

0 comments on commit f80f044

Please sign in to comment.