Skip to content

Commit

Permalink
- F Added parse inputs from docs string
Browse files Browse the repository at this point in the history
Co-Authored-By: Kevin Maes <kevin@kevinmaes.com>
Co-Authored-By: 4dsherwood <4dsherwood@users.noreply.github.com>
Co-Authored-By: blade290 <43077216+blade290@users.noreply.github.com>
Co-Authored-By: Nitsan Avni <nitsanav@gmail.com>
Co-Authored-By: Susan Fung <38925660+susanfung@users.noreply.github.com>
Co-Authored-By: Nazee Hajebi <2491283+NazeeHajebi@users.noreply.github.com>
Co-Authored-By: T. E. Green <78671457+Tegsy@users.noreply.github.com>
  • Loading branch information
8 people committed Feb 11, 2024
1 parent a387954 commit 8b01b42
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
12 changes: 12 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Test are running on all CI machine
Test fail if mariadb is in the requirements for linux

1. [ ] update Cyber-dojo to have latest version of approvaltests.py and
a. [x] verify which version of approval tests is in the new image that we just created
2. [ ] put an example of inline approvals into cyber-dojo
3. [ ] add JQ (nitsan created repo and submitted an issue)

Expand All @@ -23,6 +24,17 @@ Test fail if mariadb is in the requirements for linux
Key x = done, - = started

notes:
1. [ ] update Cyber-dojo to have latest version of approvaltests.py and

What have we learned?
- How does approvals work in cyber-dojo?
- There are two docker images with python approvals: 1. pytest 2. unittest
- is the version number important?
- Does it use the pytest plugin at all? Or just pytest?
- set up Gitpod
-


Possible problem:
we have linked the Execute command and the _____
when you run it
Expand Down
6 changes: 6 additions & 0 deletions approvaltests/inline/parse_docstring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from approvaltests.namer.inline_comparator import InlineComparator


def parse_docstring():
lines = InlineComparator.get_test_method_doc_string().split("\n")[:-1]
return [line.split("->")[0].strip() for line in lines ]
8 changes: 5 additions & 3 deletions approvaltests/namer/inline_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ def get_approved_filename(self, base: Optional[str] = None) -> str:
def get_received_filename(self, base: Optional[str] = None) -> str:
return tempfile.NamedTemporaryFile(suffix=".received.txt", delete=False).name

def get_test_method_doc_string(self):
@staticmethod
def get_test_method_doc_string():
test_stack_frame: FrameInfo = StackFrameNamer.get_test_frame()
method: Callable[..., Any] = self.get_caller_method(test_stack_frame)
method: Callable[..., Any] = InlineComparator.get_caller_method(test_stack_frame)
return remove_indentation_from(method.__doc__)

def get_caller_method(self, caller_frame) -> Callable:
@staticmethod
def get_caller_method(caller_frame) -> Callable:
caller_function_name: str = caller_frame[3]
caller_function_object = caller_frame.frame.f_globals.get(
caller_function_name, None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
inputs

0) 1
1) 2
2) Fizz
3) 4
4) Buzz
5) Fizz
6) 7
7) 8
20 changes: 16 additions & 4 deletions tests/test_inline_approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
assert_equal_with_reporter,
Options,
Reporter,
verify,
verify, verify_all,
)
from approvaltests.reporters import MultiReporter, ReporterThatAutomaticallyApproves
from approvaltests.inline.parse_docstring import parse_docstring
from approvaltests.reporters import MultiReporter


def get_approved_via_doc_string():
Expand Down Expand Up @@ -92,5 +93,16 @@ def verify_inline(actual):
assert_equal_with_reporter(get_approved_via_doc_string(), actual, options=options)


#
#
def test_docstring_parsing():
"""
1
2 -> 2
Fizz
4
Buzz
Fizz
7
8
"""
verify_all('inputs', parse_docstring())

0 comments on commit 8b01b42

Please sign in to comment.