Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
isidore committed Aug 27, 2023
2 parents 3b2b3a2 + 68437e8 commit 03387c7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
8 changes: 7 additions & 1 deletion approvaltests/approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,13 @@ def verify_as_json(
object_to_verify = utils.deserialize_json_fields(object_to_verify)
options = initialize_options(options, reporter)
json_text = utils.to_json(object_to_verify) + "\n"
verify(json_text, None, encoding="utf-8", newline="\n", options=options.for_file.with_extension(".json"))
verify(
json_text,
None,
encoding="utf-8",
newline="\n",
options=options.for_file.with_extension(".json"),
)


# end-snippet
Expand Down
10 changes: 8 additions & 2 deletions docs/how_to/create_custom_verify_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ def verify_as_json(
object_to_verify = utils.deserialize_json_fields(object_to_verify)
options = initialize_options(options, reporter)
json_text = utils.to_json(object_to_verify) + "\n"
verify(json_text, None, encoding="utf-8", newline="\n", options=options)
verify(
json_text,
None,
encoding="utf-8",
newline="\n",
options=options.for_file.with_extension(".json"),
)
```
<sup><a href='/approvaltests/approvals.py#L221-L236' title='Snippet source file'>snippet source</a> | <a href='#snippet-verify_as_json' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests/approvals.py#L221-L242' title='Snippet source file'>snippet source</a> | <a href='#snippet-verify_as_json' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

## Create a `Verifiable` Object
Expand Down
15 changes: 10 additions & 5 deletions tests/namers/test_templated_namer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ def test_template_fields():
table = MarkdownTable().with_headers("template", "usage")
for fields in dir(TemplateFields):
if not fields.startswith("__"):
table.add_rows(fields,f"{{{fields}}}")
table.add_rows(fields, f"{{{fields}}}")
verify(table)


def test_get_received_filename():
namer = TemplatedCustomNamer(
"/my/source/directory/{approved_or_received}/{test_file_name}.{test_case_name}.{file_extension}"
)
assert (namer.get_received_filename() == "/my/source/directory/received/"
"test_templated_namer.test_get_received_filename.txt")
assert (
namer.get_received_filename() == "/my/source/directory/received/"
"test_templated_namer.test_get_received_filename.txt"
)


def test_approved_file_extension():
Expand All @@ -65,5 +68,7 @@ def test_get_approved_filename():
namer = TemplatedCustomNamer(
"/my/source/directory/{approved_or_received}/{test_file_name}.{test_case_name}.{file_extension}"
)
assert (namer.get_approved_filename() == "/my/source/directory/approved/"
"test_templated_namer.test_get_approved_filename.txt")
assert (
namer.get_approved_filename() == "/my/source/directory/approved/"
"test_templated_namer.test_get_approved_filename.txt"
)

0 comments on commit 03387c7

Please sign in to comment.