Skip to content

Commit eb3158a

Browse files
authored
Use inline_snapshot.external_file instead of syrupy (#29)
2 parents cad24bc + 4d361e6 commit eb3158a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+213
-868
lines changed

.mirror.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# DANGER: EDIT AT YOUR OWN RISK. Track this file in version control so that others can sync files correctly.
2-
- commit: fcb7c4aabba41339f8d81aa8b3a16dc3dd22a347
2+
- commit: 92e853634a273b8e222ca470242ec1f4aa4022d0
33
files:
44
- .github/python-release.yaml
55
- .github/python-test.yaml

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ci:
88

99
repos:
1010
- repo: https://github.com/George-Ogden/mirror-rorrim/
11-
rev: v0.4.5
11+
rev: v0.4.6
1212
hooks:
1313
- id: mirror-check
1414
fail_fast: true
@@ -21,7 +21,6 @@ repos:
2121
- id: end-of-file-fixer
2222
- id: mixed-line-ending
2323
- id: trailing-whitespace
24-
exclude: test_data/.*/snapshots/
2524
- id: requirements-txt-fixer
2625

2726
- repo: https://github.com/George-Ogden/linter/
@@ -64,6 +63,7 @@ repos:
6463
rev: v2.4.0
6564
hooks:
6665
- id: check-merge-conflict
66+
exclude: test_data/.*/snapshots/
6767
- id: dbg-check
6868
exclude: test_data/.*/snapshots/
6969
- id: todo-check

mirror/checker_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from inline_snapshot import snapshot
2+
from inline_snapshot._external._external_file import ExternalFile
23
import pytest
3-
from syrupy.assertion import SnapshotAssertion
44

55
from .checker import MirrorChecker
66
from .main import check_for_errors
@@ -86,7 +86,7 @@ def test_checker_check(
8686
expected_log: str,
8787
local_git_repo: GitDir,
8888
test_data_path: AbsDir,
89-
snapshot: SnapshotAssertion,
89+
json_snapshot: ExternalFile,
9090
caplog: pytest.LogCaptureFixture,
9191
log_cleanly: None,
9292
) -> None:
@@ -97,4 +97,4 @@ def test_checker_check(
9797
check_for_errors(checker.check)()
9898
assert e.value.code == exitcode
9999
assert normalize_message(caplog.text, git_dir=local_git_repo) == expected_log
100-
assert snapshot_of_repo(local_git_repo, include_lockfile=True) == snapshot
100+
assert snapshot_of_repo(local_git_repo, include_lockfile=True) == json_snapshot

mirror/conftest.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55
import textwrap
66

77
import git
8+
from inline_snapshot import external_file
9+
from inline_snapshot._external._external_file import ExternalFile
810
from loguru import logger
911
import pytest
1012
from pytest import FixtureRequest, LogCaptureFixture
11-
from syrupy.assertion import SnapshotAssertion
12-
from syrupy.extensions.amber import AmberSnapshotExtension
13-
from syrupy.location import PyTestLocation
14-
from syrupy.types import SnapshotIndex
1513
import yaml
1614
from yaml import Node
1715

1816
from .logger import ProgramState
19-
from .typed_path import AbsDir, AbsFile, GitDir, RelDir, RelFile
17+
from .typed_path import AbsDir, AbsFile, Ext, GitDir, RelDir, RelFile
2018

2119

2220
@pytest.fixture
@@ -37,20 +35,19 @@ def local_git_repo(typed_tmp_path: AbsDir, request: FixtureRequest) -> Generator
3735
os.chdir(request.config.invocation_params.dir)
3836

3937

40-
class DifferentNameExtension(AmberSnapshotExtension):
41-
location: AbsFile
38+
@pytest.fixture
39+
def snapshot_file(test_data_path: AbsDir, test_name: str) -> AbsFile:
40+
return test_data_path / RelDir("snapshots") / RelFile(test_name)
41+
4242

43-
@classmethod
44-
def get_location(cls, *, test_location: PyTestLocation, index: SnapshotIndex = 0) -> str:
45-
return os.fspath(cls.location)
43+
@pytest.fixture
44+
def json_snapshot(snapshot_file: AbsFile) -> ExternalFile:
45+
return external_file(os.fspath(snapshot_file + Ext(".json")))
4646

4747

4848
@pytest.fixture
49-
def snapshot(
50-
snapshot: SnapshotAssertion, test_data_path: AbsDir, test_name: str
51-
) -> SnapshotAssertion:
52-
DifferentNameExtension.location = test_data_path / RelDir("snapshots") / RelFile(test_name)
53-
return snapshot.use_extension(DifferentNameExtension)
49+
def text_snapshot(snapshot_file: AbsFile) -> ExternalFile:
50+
return external_file(os.fspath(snapshot_file + Ext(".txt")))
5451

5552

5653
@pytest.fixture(autouse=True)

mirror/diff_test.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import tempfile
55
import textwrap
66

7+
import _pytest.fixtures
8+
from inline_snapshot._external._external_file import ExternalFile
79
import pytest
8-
from syrupy.assertion import SnapshotAssertion
910

1011
from .diff import Diff
1112
from .file import MirrorFile
@@ -19,8 +20,14 @@ def test_data_path(global_test_data_path: AbsDir) -> AbsDir:
1920

2021

2122
@pytest.fixture
22-
def test_name(file: MirrorFile) -> str:
23-
return os.fspath(file.target)
23+
def test_name(file: MirrorFile, request: _pytest.fixtures.FixtureRequest) -> str:
24+
while not isinstance(request, _pytest.fixtures.TopRequest):
25+
assert isinstance(request, _pytest.fixtures.SubRequest)
26+
request = request._parent_request
27+
func_name: str = request.node.function.__name__
28+
assert func_name.startswith("test_diff_")
29+
name = func_name.replace("test_diff_", "", count=1)
30+
return os.fspath(RelDir(name) / file.target)
2431

2532

2633
@pytest.mark.parametrize(
@@ -35,7 +42,7 @@ def test_name(file: MirrorFile) -> str:
3542
],
3643
)
3744
def test_diff_apply_new_file(
38-
file: MirrorFile, test_data_path: AbsDir, snapshot: SnapshotAssertion, local_git_repo: GitDir
45+
file: MirrorFile, test_data_path: AbsDir, text_snapshot: ExternalFile, local_git_repo: GitDir
3946
) -> None:
4047
remote = AbsDir(tempfile.mkdtemp())
4148
add_commit(remote, test_data_path / RelDir("remote"))
@@ -47,7 +54,7 @@ def test_diff_apply_new_file(
4754
shutil.copy2(current_path, tmp_filepath)
4855
diff.apply(local_git_repo)
4956
with open(tmp_filepath) as f:
50-
assert f.read() == snapshot
57+
assert f.read() == text_snapshot
5158

5259

5360
@pytest.mark.typed
@@ -144,7 +151,7 @@ def test_diff_from_commit_empty(local_git_repo: GitDir) -> None:
144151
],
145152
)
146153
def test_diff_apply_versioned_file(
147-
file: MirrorFile, test_data_path: AbsDir, snapshot: SnapshotAssertion, local_git_repo: GitDir
154+
file: MirrorFile, test_data_path: AbsDir, text_snapshot: ExternalFile, local_git_repo: GitDir
148155
) -> None:
149156
test_data_path /= RelDir("merge")
150157
remote_path = GitDir(tempfile.mkdtemp(), check=False)
@@ -164,4 +171,4 @@ def test_diff_apply_versioned_file(
164171
shutil.copy2(test_data_path / file.target, local_git_repo / file.target)
165172
diff.apply(local_git_repo)
166173
with open(local_git_repo / file.target) as f:
167-
assert f.read() == snapshot
174+
assert f.read() == text_snapshot

mirror/installer_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from unittest import mock
22

3+
from inline_snapshot._external._external_file import ExternalFile
34
import pytest
4-
from syrupy.assertion import SnapshotAssertion
55

66
from .constants import MIRROR_FILE
77
from .repo import MirrorRepo
@@ -59,12 +59,12 @@ def test_installer_install(
5959
source: tuple[str | None, str] | None,
6060
local_git_repo: GitDir,
6161
test_data_path: AbsDir,
62-
snapshot: SnapshotAssertion,
62+
json_snapshot: ExternalFile,
6363
) -> None:
6464
installer = quick_installer(local_git_repo, source)
6565
setup_repo(local_git_repo, test_data_path / RelDir(test_name))
6666

6767
if isinstance(installer.source, RelFile):
6868
object.__setattr__(installer, "source", local_git_repo / installer.source)
6969
installer.install()
70-
assert snapshot_of_repo(local_git_repo, include_lockfile=False) == snapshot
70+
assert snapshot_of_repo(local_git_repo, include_lockfile=False) == json_snapshot

mirror/main_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def test_main_with_keyboard_interrupt(
235235
mirror_existed_before = (local_git_repo / MIRROR_LOCK).exists()
236236
with (
237237
pytest.raises(SystemExit) as e,
238-
mock.patch.object(GitHelper, "wait", mock.Mock(side_effect=[KeyboardInterrupt])), # type: ignore [list-item]
238+
mock.patch.object(GitHelper, "wait", mock.Mock(side_effect=[KeyboardInterrupt])),
239239
):
240240
main.main(argv, prog_name=MIRROR_NAME)
241241
assert e.value.code != 0

mirror/mirror_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import tempfile
44

55
from inline_snapshot import snapshot
6+
from inline_snapshot._external._external_file import ExternalFile
67
import pytest
78
from pytest import LogCaptureFixture
8-
from syrupy.assertion import SnapshotAssertion
99

1010
from .config_parser import Parser
1111
from .constants import MIRROR_LOCK
@@ -138,7 +138,7 @@ def multiple_repos_local_test_case() -> Mirror:
138138
(multiple_repos_local_test_case(), multiple_repos_local_test_case.__name__),
139139
],
140140
)
141-
def test_mirror_state(mirror: Mirror, snapshot: SnapshotAssertion, typed_tmp_path: AbsDir) -> None:
141+
def test_mirror_state(mirror: Mirror, text_snapshot: ExternalFile, typed_tmp_path: AbsDir) -> None:
142142
mirror.checkout_all()
143143
with open(typed_tmp_path / RelFile(MIRROR_LOCK), "a+") as f:
144144
mirror.state.dump(f)
@@ -147,7 +147,7 @@ def test_mirror_state(mirror: Mirror, snapshot: SnapshotAssertion, typed_tmp_pat
147147
if hasattr(mirror, "__replacement__"):
148148
for search, replacement in mirror.__replacement__.items():
149149
contents = contents.replace(search, replacement)
150-
assert contents == snapshot
150+
assert contents == text_snapshot
151151

152152

153153
def all_up_to_date_test_case() -> Mirror:

mirror/repo_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import git
88
from git import GitError
99
from inline_snapshot import snapshot
10+
from inline_snapshot._external._external_file import ExternalFile
1011
import pytest
1112
from pytest import LogCaptureFixture
12-
from syrupy.assertion import SnapshotAssertion
1313

1414
from .config import MirrorRepoConfig
1515
from .config_parser_test import quick_mirror_repo_config
@@ -133,7 +133,7 @@ def repo_renaming_test_case() -> MirrorRepo:
133133
],
134134
)
135135
def test_update_all(
136-
repo: MirrorRepo, test_data_path: AbsDir, snapshot: SnapshotAssertion, local_git_repo: GitDir
136+
repo: MirrorRepo, test_data_path: AbsDir, json_snapshot: ExternalFile, local_git_repo: GitDir
137137
) -> None:
138138
for file in repo.files:
139139
existing_file = test_data_path / RelDir("local") / file.target
@@ -149,7 +149,7 @@ def test_update_all(
149149
with open(local_git_repo / RelFile(filename)) as f:
150150
repo_contents[filename] = f.read()
151151
break
152-
assert repo_contents == snapshot
152+
assert repo_contents == json_snapshot
153153

154154

155155
def quick_repo_state(source: str, commit: str, files: Sequence[str]) -> MirrorRepoState:

mirror/syncer_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
from inline_snapshot._external._external_file import ExternalFile
12
import pytest
2-
from syrupy.assertion import SnapshotAssertion
33

44
from .syncer import MirrorSyncer
55
from .test_utils import setup_repo, snapshot_of_repo
@@ -26,9 +26,9 @@ def quick_syncer(target: str | AbsDir | None) -> MirrorSyncer:
2626
],
2727
)
2828
def test_installer_install(
29-
test_name: str, local_git_repo: GitDir, test_data_path: AbsDir, snapshot: SnapshotAssertion
29+
test_name: str, local_git_repo: GitDir, test_data_path: AbsDir, json_snapshot: ExternalFile
3030
) -> None:
3131
syncer = quick_syncer(local_git_repo)
3232
setup_repo(local_git_repo, test_data_path / RelDir(test_name))
3333
syncer.sync()
34-
assert snapshot_of_repo(local_git_repo, include_lockfile=True) == snapshot
34+
assert snapshot_of_repo(local_git_repo, include_lockfile=True) == json_snapshot

0 commit comments

Comments
 (0)