Skip to content

Commit 8704465

Browse files
isidorejmasonleegregorrieglerblade290nitsanavni
committed
- r moved lambda
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 bfc37ad commit 8704465

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

approvaltests/inline/inline_options.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
from pathlib import Path
2+
3+
PREVIOUS_RESULT_ = "vvvvv PREVIOUS RESULT vvvvv\n"
4+
5+
DELETE_ME_TO_APPROVE_ = "\n***** DELETE ME TO APPROVE *****"
6+
17
class InlineOptions:
28

39
@staticmethod
@@ -55,11 +61,17 @@ def previous_capture():
5561
from approvaltests.namer.inline_python_reporter import InlinePythonReporter
5662
from approvaltests.reporters import ReporterThatAutomaticallyApproves
5763

64+
def applesauce(approved_path):
65+
approved_text = Path(approved_path).read_text()
66+
approved_text = approved_text.rsplit("\n", 1)[0]
67+
approved_text = approved_text.rsplit(PREVIOUS_RESULT_, 1)[-1]
68+
previous_result_stuff = lambda: "\n" + PREVIOUS_RESULT_ + approved_text
69+
return DELETE_ME_TO_APPROVE_ + previous_result_stuff()
5870
class SemiAutomaticInlineOptions(InlineOptions):
5971
def apply(self, options: "Options") -> "Options":
6072
return options.with_reporter(
6173
InlinePythonReporter(
62-
ReporterThatAutomaticallyApproves(), add_approval_line=False, previous_result=True
74+
ReporterThatAutomaticallyApproves(), add_approval_line=False, previous_result=applesauce
6375
)
6476
)
6577

approvaltests/namer/inline_python_reporter.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,8 @@ def __init__(self, reporter, add_approval_line=False, previous_result=None):
2020

2121
def report(self, received_path: str, approved_path: str) -> bool:
2222
test_source_file = self.get_test_source_file()
23-
def applesauce():
24-
approved_text = Path(approved_path).read_text()
25-
approved_text = approved_text.rsplit("\n", 1)[0]
26-
approved_text = approved_text.rsplit(PREVIOUS_RESULT_, 1)[-1]
27-
previous_result_stuff = lambda: "\n" + PREVIOUS_RESULT_ + approved_text
28-
return DELETE_ME_TO_APPROVE_ + previous_result_stuff()
2923
if self.previous_result:
30-
self.semi_automatic_extra_line = applesauce()
24+
self.semi_automatic_extra_line = self.previous_result(approved_path)
3125
received_path = self.create_received_file(received_path, test_source_file)
3226
return self.diffReporter.report(received_path, test_source_file)
3327

0 commit comments

Comments
 (0)