Skip to content

Commit c7968fd

Browse files
authored
fix: raw single should use the same name for snapshot and file (#91)
* test: add failing test case * fix: raw single should use the same name for snapshot and file * test: restore previous testcase
1 parent 2f41347 commit c7968fd

File tree

8 files changed

+34
-3
lines changed

8 files changed

+34
-3
lines changed

src/syrupy/serializers/raw_single.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ def discover_snapshots(self, filepath: str) -> "SnapshotFile":
3434
return snapshot_file
3535

3636
def get_file_basename(self, index: int) -> str:
37-
return self.__clean_filename(self.get_snapshot_name(index=index))
37+
return self.get_snapshot_name(index=index)
38+
39+
def get_snapshot_name(self, index: int = 0) -> str:
40+
return self.__clean_filename(
41+
super(RawSingleSnapshotSerializer, self).get_snapshot_name(index=index)
42+
)
3843

3944
@property
4045
def snapshot_subdirectory_name(self) -> str:

tests/__snapshots__/test_amber_serializer.ambr

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
# name: TestClass.test_name
1+
# name: TestClass.test_class_method_name
22
'this is in a test class'
33
---
4+
# name: TestClass.test_class_method_parametrized[a]
5+
'a'
6+
---
7+
# name: TestClass.test_class_method_parametrized[b]
8+
'b'
9+
---
10+
# name: TestClass.test_class_method_parametrized[c]
11+
'c'
12+
---
413
# name: test_bool[False]
514
False
615
---
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is in a test class
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
y
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
z

tests/test_amber_serializer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,9 @@ def test_cycle(cyclic, snapshot):
9696

9797

9898
class TestClass:
99-
def test_name(self, snapshot):
99+
def test_class_method_name(self, snapshot):
100100
assert snapshot == "this is in a test class"
101+
102+
@pytest.mark.parametrize("actual", ["a", "b", "c"])
103+
def test_class_method_parametrized(self, snapshot, actual):
104+
assert snapshot == actual

tests/test_raw_single_serializer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,12 @@ def test_does_not_write_non_binary(testdir, snapshot_raw: "SnapshotAssertion"):
2727
with pytest.raises(TypeError, match="Expected 'bytes', got 'str'"):
2828
snapshot_raw.serializer._write_snapshot_to_file(snapshot_file)
2929
assert not os.path.exists(snapshot_file.filepath)
30+
31+
32+
class TestClass:
33+
def test_class_method_name(self, snapshot_raw):
34+
assert snapshot_raw == b"this is in a test class"
35+
36+
@pytest.mark.parametrize("content", [b"x", b"y", b"z"])
37+
def test_class_method_parametrized(self, snapshot_raw, content):
38+
assert snapshot_raw == content

0 commit comments

Comments
 (0)