generated from tophat/new-project-kit
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
The snapshot_name_suffix will hold an optional suffix to be used instead of index in the snapshot_name. The suffix will by default be formatted to be between brackets: "[<snapshot_name_suffix>]" Co-authored-by: Ouail Bendidi <ouail.bendidi@gmail.com>
- Loading branch information
Showing
12 changed files
with
153 additions
and
22 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
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
Binary file added
BIN
+90 Bytes
...st_custom_image_name_suffix/test_png_image_with_custom_name_suffix[blueish].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+90 Bytes
...st_custom_image_name_suffix/test_png_image_with_custom_name_suffix[reddish].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions
6
tests/examples/__snapshots__/test_custom_snapshot_name_suffix.ambr
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,6 @@ | ||
# name: test_snapshot_custom_snapshot_name_suffix[test_is_amazing] | ||
'Syrupy is amazing!' | ||
--- | ||
# name: test_snapshot_custom_snapshot_name_suffix[test_is_awesome] | ||
'Syrupy is awesome!' | ||
--- |
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,25 @@ | ||
import base64 | ||
|
||
import pytest | ||
|
||
from syrupy.extensions.image import PNGImageSnapshotExtension | ||
|
||
|
||
@pytest.fixture | ||
def snapshot(snapshot): | ||
return snapshot.use_extension(PNGImageSnapshotExtension) | ||
|
||
|
||
def test_png_image_with_custom_name_suffix(snapshot): | ||
reddish_square = base64.b64decode( | ||
b"iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAIUlEQVQIHTXB" | ||
b"MQEAAAABQUYtvpD+dUzu3KBzg84NOjfoBjmmAd3WpSsrAAAAAElFTkSuQmCC" | ||
) | ||
|
||
blueish_square = base64.b64decode( | ||
b"iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAIUlEQVQIHTXB" | ||
b"MQEAAAABQUYtvpD+dUzuTKozqc6kOpPqBjg+Ad2g/BLMAAAAAElFTkSuQmCC" | ||
) | ||
|
||
assert blueish_square == snapshot(name="blueish") | ||
assert reddish_square == snapshot(name="reddish") |
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,3 @@ | ||
def test_snapshot_custom_snapshot_name_suffix(snapshot): | ||
assert "Syrupy is amazing!" == snapshot(name="test_is_amazing") | ||
assert "Syrupy is awesome!" == snapshot(name="test_is_awesome") |
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,63 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def testcases(): | ||
return { | ||
"base": ( | ||
""" | ||
def test_a(snapshot): | ||
assert snapshot(name="xyz") == "case 1" | ||
assert snapshot(name="zyx") == "case 2" | ||
""" | ||
), | ||
"modified": ( | ||
""" | ||
def test_a(snapshot): | ||
assert snapshot(name="xyz") == "case 1" | ||
assert snapshot(name="zyx") == "case ??" | ||
""" | ||
), | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def run_testcases(testdir, testcases): | ||
testdir.makepyfile(test_1=testcases["base"]) | ||
result = testdir.runpytest( | ||
"-v", | ||
"--snapshot-update", | ||
) | ||
result.stdout.re_match_lines((r"2 snapshots generated\.")) | ||
return testdir, testcases | ||
|
||
|
||
def test_run_all(run_testcases): | ||
testdir, testcases = run_testcases | ||
result = testdir.runpytest( | ||
"-v", | ||
) | ||
result.stdout.re_match_lines("2 snapshots passed") | ||
assert result.ret == 0 | ||
|
||
|
||
def test_failure(run_testcases): | ||
testdir, testcases = run_testcases | ||
testdir.makepyfile(test_1=testcases["modified"]) | ||
result = testdir.runpytest( | ||
"-v", | ||
) | ||
result.stdout.re_match_lines("1 snapshot failed. 1 snapshot passed.") | ||
assert result.ret == 1 | ||
|
||
|
||
def test_update(run_testcases): | ||
testdir, testcases = run_testcases | ||
testdir.makepyfile(test_1=testcases["modified"]) | ||
result = testdir.runpytest( | ||
"-v", | ||
"--snapshot-update", | ||
) | ||
assert "Can not relate snapshot name" not in str(result.stdout) | ||
result.stdout.re_match_lines("1 snapshot passed. 1 snapshot updated.") | ||
assert result.ret == 0 |
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