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 Nov 26, 2023
1 parent 32be897 commit 9928b32
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
20 changes: 10 additions & 10 deletions approvaltests/inline/split_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ def __init__(self, before_method, after_method, tab):
self.before_method = before_method
self.after_method = after_method
self.tab = tab

def __str__(self):
return f"before:\n{self.before_method}\nafter:\n{self.after_method}"

@staticmethod
def on_method(code, method_name) -> 'SplitCode':
lines = code.split('\n')
def on_method(code, method_name) -> "SplitCode":
lines = code.split("\n")
before = []
after = []
inside_method = False
Expand All @@ -19,14 +21,13 @@ def on_method(code, method_name) -> 'SplitCode':
for line in lines:
stripped_line = line.strip()


if state == 0:
before.append(line)
if stripped_line.startswith(f'def {method_name}('):
if stripped_line.startswith(f"def {method_name}("):
state = 1
continue
if state == 1:
tab = line[:line.find(stripped_line)]
tab = line[: line.find(stripped_line)]
if stripped_line.startswith('"""'):
state = 2
continue
Expand All @@ -39,10 +40,9 @@ def on_method(code, method_name) -> 'SplitCode':
if state == 3:
after.append(line)

return SplitCode('\n'.join(before), '\n'.join(after),tab)
return SplitCode("\n".join(before), "\n".join(after), tab)

def indent(self, received_text):
lines = received_text.split('\n')
indented_lines = [f'{self.tab}{line}' for line in lines]
return '\n'.join(indented_lines)

lines = received_text.split("\n")
indented_lines = [f"{self.tab}{line}" for line in lines]
return "\n".join(indented_lines)
3 changes: 1 addition & 2 deletions approvaltests/namer/inline_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def get_caller_method(self, caller_frame) -> Callable:
)
return caller_function_object


def register(self, options: "Options", show_code : bool):
def register(self, options: "Options", show_code: bool):
options2 = options.with_namer(self)
if show_code:
options2 = options2.with_reporter(InlinePythonReporter())
Expand Down
1 change: 0 additions & 1 deletion approvaltests/namer/inline_python_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class InlinePythonReporter(Reporter):

def __init__(self):
self.test_source_file = self.get_test_source_file()
self.diffReporter = DiffReporter()
Expand Down
15 changes: 7 additions & 8 deletions tests/test_inline_approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def fizz_buzz(param):
if i % 15 == 0:
return_string += "FizzBuzz\n"
elif i % 3 == 0:
return_string += "Fizz\n"
return_string += "Fizz\n"
elif i % 5 == 0:
return_string += "Buzz\n"
return_string += "Buzz\n"
else:
return_string += str(i) + "\n"
return_string += str(i) + "\n"
return return_string


Expand All @@ -59,23 +59,22 @@ def test_fizz_buzz_to_15():
8
"""
verify(fizz_buzz(8), options=Options().inline())


def test_docstrings():
"""
hello
hello
world
"""
# verify_inline(greetting())
# verify(greetting(), options=Options().inline(show_code= False))
verify(greeting(), options = Options().inline(show_code= True))


verify(greeting(), options=Options().inline(show_code=True))


def greeting():
return "hello \n world"



class InlineReporter(Reporter):
# TODO: Start here - Make this report create a temp file of the fixed source,
# and compare it with the existing source.
Expand Down
9 changes: 5 additions & 4 deletions tests/test_split_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@


def test_splitting_code():
code = \
remove_indentation_from('''
code = remove_indentation_from(
'''
def other_code():
pass
def testy_mctest():
Expand All @@ -18,5 +18,6 @@ def testy_mctest():
def greeting():
# start of greeting() method
return "hello world"
''');
verify(SplitCode.on_method(code, "testy_mctest"))
'''
)
verify(SplitCode.on_method(code, "testy_mctest"))

0 comments on commit 9928b32

Please sign in to comment.