Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove unused snapshots in snapshot file #11

Merged
merged 19 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/syrupy/assertion.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import traceback
import pytest
import os
from typing import Callable, List, Optional, Any
from typing import Any, Callable, List, Optional, Type

from .exceptions import SnapshotDoesNotExist

from .io import SnapshotIO, SnapshotIOClass
from .serializer import SnapshotSerializer, SnapshotSerializerClass
from .io import SnapshotIO
from .serializer import SnapshotSerializer
from .location import TestLocation


Expand All @@ -15,8 +15,8 @@ def __init__(
self,
*,
update_snapshots: bool,
io_class: SnapshotIOClass,
serializer_class: SnapshotSerializerClass,
io_class: Type[SnapshotIO],
serializer_class: Type[SnapshotSerializer],
test_location: TestLocation,
session,
):
Expand Down Expand Up @@ -51,8 +51,8 @@ def num_executions(self) -> int:

def with_class(
self,
io_class: SnapshotIOClass = None,
serializer_class: SnapshotSerializerClass = None,
io_class: Type[SnapshotIO] = None,
serializer_class: Type[SnapshotSerializer] = None,
):
return self.__class__(
update_snapshots=self._update_snapshots,
Expand Down
3 changes: 0 additions & 3 deletions src/syrupy/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,3 @@ def _snap_file_hook(self, index: int):
snapshot_file = self.get_filepath(index)
snapshot_name = self.get_snapshot_name(index)
self._file_hook(snapshot_file, snapshot_name)


SnapshotIOClass = Callable[..., SnapshotIO]
7 changes: 4 additions & 3 deletions src/syrupy/plugins/image/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def discover_snapshots(self, filepath: str) -> Set[str]:
return {os.path.splitext(os.path.basename(filepath))[0]}

def get_file_basename(self, index: int) -> str:
ext = f".{self.extension}"
maybe_extension = f".{self.extension}" if self.extension else ""
sanitized_name = self._clean_filename(self.get_snapshot_name(index=index))
return f"{sanitized_name[:255 - len(ext)]}{ext}"
return f"{sanitized_name}{maybe_extension}"

def _get_snapshot_dirname(self):
return os.path.splitext(os.path.basename(str(self.test_location.filename)))[0]
Expand All @@ -48,4 +48,5 @@ def _write_file(self, filepath: str, data: Any):

def _clean_filename(self, filename: str) -> str:
filename = str(filename).strip().replace(" ", "_")
return re.sub(r"(?u)[^-\w.]", "", filename)
max_filename_length = 255 - (len(self.extension) if self.extension else 0)
iamogbz marked this conversation as resolved.
Show resolved Hide resolved
return re.sub(r"(?u)[^-\w.]", "", filename)[:max_filename_length]
3 changes: 0 additions & 3 deletions src/syrupy/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ def encode(self, data):

def decode(self, data):
return data


SnapshotSerializerClass = Callable[..., SnapshotSerializer]
2 changes: 1 addition & 1 deletion src/syrupy/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _diff_snapshot_files(
}

def _count_snapshots(self, snapshot_files: SnapshotFiles) -> int:
return sum([len(snapshots) for _, snapshots in snapshot_files.items()])
return sum(map(len, snapshot_files.values()))
iamogbz marked this conversation as resolved.
Show resolved Hide resolved

def _in_snapshot_dir(self, path: str) -> bool:
parts = path.split(os.path.sep)
Expand Down