Skip to content

Commit 831a126

Browse files
isidorejmasonleegregorrieglerblade290nitsanavni
committed
- F fully working previous result
Co-Authored-By: jmasonlee <262853+jmasonlee@users.noreply.github.com> Co-Authored-By: Gregor Riegler <rieglerg85@gmail.com> Co-Authored-By: blade290 <43077216+blade290@users.noreply.github.com> Co-Authored-By: Nitsan Avni <nitsanav@gmail.com> Co-Authored-By: bhargavgundu <7643639+bhargavgundu@users.noreply.github.com>
1 parent 6df0fd0 commit 831a126

3 files changed

Lines changed: 12 additions & 15 deletions

File tree

approvaltests/namer/inline_python_reporter.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from approvaltests import Reporter, StackFrameNamer
66
from approvaltests.inline.split_code import SplitCode
77

8+
PREVIOUS_RESULT_ = "vvvvv PREVIOUS RESULT vvvvv\n"
9+
810
DELETE_ME_TO_APPROVE_ = "\n***** DELETE ME TO APPROVE *****"
911

1012

@@ -18,8 +20,12 @@ def __init__(self, reporter, add_approval_line=False, previous_result=None):
1820

1921
def report(self, received_path: str, approved_path: str) -> bool:
2022
test_source_file = self.get_test_source_file()
23+
2124
if self.previous_result:
22-
previous_result_stuff = lambda: "\n" + "vvvvv PREVIOUS RESULT vvvvv" + "\n" + "41"
25+
approved_text = Path(approved_path).read_text()
26+
approved_text = approved_text.rsplit("\n", 1)[0]
27+
approved_text = approved_text.rsplit(PREVIOUS_RESULT_, 1)[-1]
28+
previous_result_stuff = lambda: "\n" + PREVIOUS_RESULT_ + approved_text
2329
self.semi_automatic_extra_line = DELETE_ME_TO_APPROVE_ + previous_result_stuff()
2430
received_path = self.create_received_file(received_path, test_source_file)
2531
return self.diffReporter.report(received_path, test_source_file)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
42
2+
***** DELETE ME TO APPROVE *****
3+
vvvvv PREVIOUS RESULT vvvvv
4+
41

tests/test_inline_approvals.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,9 @@ def test_inline_with_preserved_approved_text():
196196
vvvvv PREVIOUS RESULT vvvvv
197197
41
198198
"""
199-
this_is_the_docstring_we_want = remove_indentation_from("""
200-
42
201-
***** DELETE ME TO APPROVE *****
202-
vvvvv PREVIOUS RESULT vvvvv
203-
41
204-
""")
205-
206-
207-
# 1. Run a failing inline approval with a new configuration
208-
# 2. Capture whatever we've overwriting the docstring with
209-
# 3. Capture the last docstring so we can write it to previous result
210-
# 4. Check that the overwriting string is equal to the docstring we want
211199
options = Options().inline(InlineOptions.previous_capture())
212200
try:
213201
verify("42", options=options)
214202
except ApprovalException:
215203
pass
216-
# assert that the docstring is equal to the string we want
217-
assert get_approved_via_doc_string() == this_is_the_docstring_we_want
204+
verify(get_approved_via_doc_string())

0 commit comments

Comments
 (0)