generated from tophat/new-project-kit
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support setting defaults (#802)
- Loading branch information
1 parent
11b0722
commit c877559
Showing
6 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# serializer version: 1 | ||
# name: test_asserting_multiple_times | ||
dict({ | ||
'excluded': 'value', | ||
'my-field': str, | ||
}) | ||
# --- | ||
# name: test_asserting_multiple_times.1 | ||
dict({ | ||
'excluded': 'value', | ||
'my-field': int, | ||
}) | ||
# --- | ||
# name: test_asserting_multiple_times_chained | ||
dict({ | ||
'my-field': str, | ||
}) | ||
# --- | ||
# name: test_asserting_multiple_times_chained.1 | ||
dict({ | ||
'my-field': int, | ||
}) | ||
# --- |
3 changes: 3 additions & 0 deletions
3
...ples/__snapshots__/test_custom_defaults/test_asserting_multiple_times_chained_json.1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"my-field": "int" | ||
} |
3 changes: 3 additions & 0 deletions
3
...amples/__snapshots__/test_custom_defaults/test_asserting_multiple_times_chained_json.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"my-field": "str" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Example: Custom snapshot defaults | ||
Here we modify snapshot defaults globally, instead of per assert. | ||
This gives the ability to modify the snapshot functionality to your hearts content | ||
and then simply re-use them, without having to pass those defaults to every assert. | ||
Especially useful if there's a lot of tests that need to modify the default behaviour. | ||
""" | ||
import pytest | ||
|
||
from syrupy.extensions.json import JSONSnapshotExtension | ||
from syrupy.filters import paths | ||
from syrupy.matchers import path_type | ||
|
||
|
||
@pytest.fixture | ||
def snapshot_matcher(snapshot): | ||
return snapshot.with_defaults(matcher=path_type(mapping={"my-field": (str, int)})) | ||
|
||
|
||
@pytest.fixture | ||
def snapshot_exclude(snapshot_matcher): | ||
return snapshot_matcher.with_defaults(exclude=paths("excluded")) | ||
|
||
|
||
@pytest.fixture | ||
def snapshot_json(snapshot_exclude): | ||
return snapshot_exclude.with_defaults(extension_class=JSONSnapshotExtension) | ||
|
||
|
||
def test_asserting_multiple_times(snapshot_matcher): | ||
assert {"my-field": "my-string", "excluded": "value"} == snapshot_matcher | ||
assert {"my-field": 12345, "excluded": "value"} == snapshot_matcher | ||
|
||
|
||
def test_asserting_multiple_times_chained(snapshot_exclude): | ||
assert {"my-field": "my-string", "excluded": "value"} == snapshot_exclude | ||
assert {"my-field": 12345, "excluded": "value"} == snapshot_exclude | ||
|
||
|
||
def test_asserting_multiple_times_chained_json(snapshot_json): | ||
assert {"my-field": "my-string", "excluded": "value"} == snapshot_json | ||
assert {"my-field": 12345, "excluded": "value"} == snapshot_json |