172def test_demonstrate_available_approvaltests_options() -> None:
173 # begin-snippet: options_with_all_options
174 options = (
175 Options()
176
177 # write the .approved/.received files as Markdown instead of .txt
178 .for_file.with_extension(".md")
179
180 # uppercase the text before it is written/compared, so the effect
181 # is visible in the received/approved files themselves
182 .with_scrubber(lambda text: text.upper())
183
184 # add_scrubber stacks an additional scrubber on top of any scrubbers already
185 # added, instead of replacing them like with_scrubber would; here there's only
186 # one scrubber (from with_scrubber above). The newly added scrubber turns "!"
187 # into "!!!", which sets up the comparator below to show off what it ignores
188 .add_scrubber(lambda text: text.replace("!", "!!!"))
189
190 # use a custom namer, so the user controls the approved/received file names
191 # directly, instead of having them derived from the test's own name
192 .with_namer(UserSpecifiedFileNamer())
193
194 # use a custom comparator that ignores trailing "!"s, so the mismatch
195 # created by add_scrubber above still counts as approved
196 .with_comparator(IgnoreTrailingExclamationsComparator())
197
198 # launch Beyond Compare to review any mismatch
199 .with_reporter(ReportWithBeyondCompare())
200 )
201
202 verify("Hello, Approvals!", options=options)
203 # end-snippet
class IgnoreTrailingExclamationsComparator(Comparator):
@override
def compare(self, received_path, approved_path) -> bool:
received = ….rstrip("!\n")
approved = ….rstrip("!\n")
return received == approved