Skip to content

Commit

Permalink
fix: raw single should use the same name for snapshot and file (#91)
Browse files Browse the repository at this point in the history
* test: add failing test case

* fix: raw single should use the same name for snapshot and file

* test: restore previous testcase
  • Loading branch information
iamogbz authored Jan 7, 2020
1 parent 2f41347 commit c7968fd
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/syrupy/serializers/raw_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ def discover_snapshots(self, filepath: str) -> "SnapshotFile":
return snapshot_file

def get_file_basename(self, index: int) -> str:
return self.__clean_filename(self.get_snapshot_name(index=index))
return self.get_snapshot_name(index=index)

def get_snapshot_name(self, index: int = 0) -> str:
return self.__clean_filename(
super(RawSingleSnapshotSerializer, self).get_snapshot_name(index=index)
)

@property
def snapshot_subdirectory_name(self) -> str:
Expand Down
11 changes: 10 additions & 1 deletion tests/__snapshots__/test_amber_serializer.ambr
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# name: TestClass.test_name
# name: TestClass.test_class_method_name
'this is in a test class'
---
# name: TestClass.test_class_method_parametrized[a]
'a'
---
# name: TestClass.test_class_method_parametrized[b]
'b'
---
# name: TestClass.test_class_method_parametrized[c]
'c'
---
# name: test_bool[False]
False
---
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is in a test class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
y
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z
6 changes: 5 additions & 1 deletion tests/test_amber_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,9 @@ def test_cycle(cyclic, snapshot):


class TestClass:
def test_name(self, snapshot):
def test_class_method_name(self, snapshot):
assert snapshot == "this is in a test class"

@pytest.mark.parametrize("actual", ["a", "b", "c"])
def test_class_method_parametrized(self, snapshot, actual):
assert snapshot == actual
9 changes: 9 additions & 0 deletions tests/test_raw_single_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ def test_does_not_write_non_binary(testdir, snapshot_raw: "SnapshotAssertion"):
with pytest.raises(TypeError, match="Expected 'bytes', got 'str'"):
snapshot_raw.serializer._write_snapshot_to_file(snapshot_file)
assert not os.path.exists(snapshot_file.filepath)


class TestClass:
def test_class_method_name(self, snapshot_raw):
assert snapshot_raw == b"this is in a test class"

@pytest.mark.parametrize("content", [b"x", b"y", b"z"])
def test_class_method_parametrized(self, snapshot_raw, content):
assert snapshot_raw == content

0 comments on commit c7968fd

Please sign in to comment.