localstack-snapshot 0.3.3__tar.gz → 0.3.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/PKG-INFO +5 -5
  2. localstack_snapshot-0.3.5/localstack_snapshot/__init__.py +1 -0
  3. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/localstack_snapshot/pytest/snapshot.py +23 -1
  4. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/localstack_snapshot/snapshots/prototype.py +2 -2
  5. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/localstack_snapshot/snapshots/transformer.py +1 -2
  6. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/localstack_snapshot.egg-info/PKG-INFO +5 -5
  7. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/localstack_snapshot.egg-info/SOURCES.txt +1 -0
  8. localstack_snapshot-0.3.5/localstack_snapshot.egg-info/requires.txt +8 -0
  9. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/pyproject.toml +11 -10
  10. localstack_snapshot-0.3.5/tests/test_pytest_snapshot.py +53 -0
  11. localstack_snapshot-0.3.3/localstack_snapshot/__init__.py +0 -1
  12. localstack_snapshot-0.3.3/localstack_snapshot.egg-info/requires.txt +0 -8
  13. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/LICENSE +0 -0
  14. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/README.md +0 -0
  15. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/localstack_snapshot/pytest/__init__.py +0 -0
  16. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/localstack_snapshot/snapshots/__init__.py +0 -0
  17. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/localstack_snapshot/snapshots/report.py +0 -0
  18. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/localstack_snapshot/snapshots/transformer_utility.py +0 -0
  19. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/localstack_snapshot/util/__init__.py +0 -0
  20. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/localstack_snapshot/util/encoding.py +0 -0
  21. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/localstack_snapshot.egg-info/dependency_links.txt +0 -0
  22. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/localstack_snapshot.egg-info/top_level.txt +0 -0
  23. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/setup.cfg +0 -0
  24. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/tests/test_snapshots.py +0 -0
  25. {localstack_snapshot-0.3.3 → localstack_snapshot-0.3.5}/tests/test_transformer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: localstack-snapshot
3
- Version: 0.3.3
3
+ Version: 0.3.5
4
4
  Summary: Extracted snapshot testing lib for LocalStack
5
5
  Author-email: LocalStack Contributors <info@localstack.cloud>
6
6
  License:
@@ -218,10 +218,10 @@ License-File: LICENSE
218
218
  Requires-Dist: jsonpath-ng>1.6
219
219
  Requires-Dist: deepdiff
220
220
  Provides-Extra: dev
221
- Requires-Dist: black==23.10.0; extra == "dev"
222
- Requires-Dist: pytest>=7.0; extra == "dev"
223
- Requires-Dist: coverage[toml]>=5.0.0; extra == "dev"
224
- Requires-Dist: ruff==0.1.0; extra == "dev"
221
+ Requires-Dist: black==26.5.1; extra == "dev"
222
+ Requires-Dist: pytest>=9.1.1; extra == "dev"
223
+ Requires-Dist: coverage[toml]>=7.15.4; extra == "dev"
224
+ Requires-Dist: ruff==0.16.5; extra == "dev"
225
225
  Dynamic: license-file
226
226
 
227
227
  Snapshot testing for pytest
@@ -0,0 +1 @@
1
+ __version__ = "0.3.5"
@@ -1,5 +1,6 @@
1
1
  import json
2
2
  import os
3
+ from pathlib import Path
3
4
  from typing import Optional
4
5
 
5
6
  import pytest
@@ -97,6 +98,27 @@ def pytest_runtest_call(item: Item) -> None:
97
98
  sm._assert_all(verify, paths)
98
99
 
99
100
 
101
+ def package_scoped_nodeid(item: Item) -> str:
102
+ """The item's nodeid relative to its enclosing package, independent of pytest's rootdir.
103
+
104
+ Snapshot entries are keyed by the pytest nodeid, which is relative to pytest's rootdir.
105
+ The committed ``*.snapshot.json`` / ``*.validation.json`` files assume the rootdir is the
106
+ package containing the test (``tests/...::<test>``), but pytest can be invoked with a
107
+ different rootdir — VS Code's test runner, for example, pins ``--rootdir=<workspace folder>``,
108
+ which prefixes every nodeid with the package directory and makes every lookup of a recorded
109
+ entry miss. Keying by the nodeid relative to the nearest enclosing ``pyproject.toml`` keeps
110
+ the entries stable no matter where pytest was started from.
111
+ """
112
+ path = Path(item.path)
113
+ for parent in path.parents:
114
+ if (parent / "pyproject.toml").is_file():
115
+ # Partition splits by the first occurance and also returns the partition itself
116
+ # "tests/test_thing.py::TestThing::test_case".partition("::") == ("tests/test_thing.py", "::", "TestThing::test_case")
117
+ _, separator, remainder = item.nodeid.partition("::")
118
+ return path.relative_to(parent).as_posix() + separator + remainder
119
+ return item.nodeid
120
+
121
+
100
122
  @pytest.fixture(scope="function")
101
123
  def _snapshot_session(request: SubRequest):
102
124
  update_overwrite = os.environ.get("SNAPSHOT_UPDATE") == "1"
@@ -104,7 +126,7 @@ def _snapshot_session(request: SubRequest):
104
126
 
105
127
  sm = SnapshotSession(
106
128
  base_file_path=os.path.join(request.fspath.dirname, request.fspath.purebasename),
107
- scope_key=request.node.nodeid,
129
+ scope_key=package_scoped_nodeid(request.node),
108
130
  update=update_overwrite or request.config.option.snapshot_update,
109
131
  raw=raw_overwrite or request.config.option.snapshot_raw,
110
132
  verify=False if request.config.option.snapshot_skip_all else True,
@@ -217,7 +217,7 @@ class SnapshotSession:
217
217
 
218
218
  if not self.update and (not self.recorded_state or self.recorded_state.get(key) is None):
219
219
  raise Exception(
220
- f"No state for {self.scope_key} recorded. Please (re-)generate the snapshot for this test."
220
+ f"No state for {key} recorded. Please (re-)generate the snapshot for this test."
221
221
  )
222
222
 
223
223
  # TODO: we should return something meaningful here
@@ -239,7 +239,7 @@ class SnapshotSession:
239
239
 
240
240
  self.skip_verification_paths = skip_verification_paths or []
241
241
  if skip_verification_paths:
242
- SNAPSHOT_LOGGER.warning(
242
+ SNAPSHOT_LOGGER.debug(
243
243
  "Snapshot verification disabled for paths: %s", skip_verification_paths
244
244
  )
245
245
 
@@ -89,8 +89,7 @@ def _register_serialized_reference_replacement(
89
89
 
90
90
 
91
91
  class Transformer(Protocol):
92
- def transform(self, input_data: dict, *, ctx: TransformContext) -> dict:
93
- ...
92
+ def transform(self, input_data: dict, *, ctx: TransformContext) -> dict: ...
94
93
 
95
94
 
96
95
  # Transformers
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: localstack-snapshot
3
- Version: 0.3.3
3
+ Version: 0.3.5
4
4
  Summary: Extracted snapshot testing lib for LocalStack
5
5
  Author-email: LocalStack Contributors <info@localstack.cloud>
6
6
  License:
@@ -218,10 +218,10 @@ License-File: LICENSE
218
218
  Requires-Dist: jsonpath-ng>1.6
219
219
  Requires-Dist: deepdiff
220
220
  Provides-Extra: dev
221
- Requires-Dist: black==23.10.0; extra == "dev"
222
- Requires-Dist: pytest>=7.0; extra == "dev"
223
- Requires-Dist: coverage[toml]>=5.0.0; extra == "dev"
224
- Requires-Dist: ruff==0.1.0; extra == "dev"
221
+ Requires-Dist: black==26.5.1; extra == "dev"
222
+ Requires-Dist: pytest>=9.1.1; extra == "dev"
223
+ Requires-Dist: coverage[toml]>=7.15.4; extra == "dev"
224
+ Requires-Dist: ruff==0.16.5; extra == "dev"
225
225
  Dynamic: license-file
226
226
 
227
227
  Snapshot testing for pytest
@@ -16,5 +16,6 @@ localstack_snapshot/snapshots/transformer.py
16
16
  localstack_snapshot/snapshots/transformer_utility.py
17
17
  localstack_snapshot/util/__init__.py
18
18
  localstack_snapshot/util/encoding.py
19
+ tests/test_pytest_snapshot.py
19
20
  tests/test_snapshots.py
20
21
  tests/test_transformer.py
@@ -0,0 +1,8 @@
1
+ jsonpath-ng>1.6
2
+ deepdiff
3
+
4
+ [dev]
5
+ black==26.5.1
6
+ pytest>=9.1.1
7
+ coverage[toml]>=7.15.4
8
+ ruff==0.16.5
@@ -7,7 +7,7 @@ name = "localstack-snapshot"
7
7
  authors = [
8
8
  { name = "LocalStack Contributors", email = "info@localstack.cloud" }
9
9
  ]
10
- version = "0.3.3"
10
+ version = "0.3.5"
11
11
  description = "Extracted snapshot testing lib for LocalStack"
12
12
  dependencies = [
13
13
  "jsonpath-ng>1.6",
@@ -28,10 +28,10 @@ dynamic = ["readme"]
28
28
 
29
29
  [project.optional-dependencies]
30
30
  dev = [
31
- "black==23.10.0",
32
- "pytest>=7.0",
33
- "coverage[toml]>=5.0.0",
34
- "ruff==0.1.0"
31
+ "black==26.5.1",
32
+ "pytest>=9.1.1",
33
+ "coverage[toml]>=7.15.4",
34
+ "ruff==0.16.5"
35
35
  ]
36
36
 
37
37
  [tool.setuptools]
@@ -56,11 +56,6 @@ include = '((localstack_snapshot)/.*\.py$|tests/.*\.py$)'
56
56
  # Always generate Python 3.10-compatible code.
57
57
  target-version = "py310"
58
58
  line-length = 110
59
- select = ["B", "C", "E", "F", "I", "W", "T", "B9"]
60
- ignore = [
61
- "E501", # E501 Line too long - handled by black, see https://docs.astral.sh/ruff/faq/#is-ruff-compatible-with-black
62
- "C901", # C901 complex-structure - later refactoring will handle this, see https://docs.astral.sh/ruff/rules/complex-structure/#complex-structure-c901
63
- ]
64
59
  exclude = [
65
60
  ".venv*",
66
61
  "venv*",
@@ -70,3 +65,9 @@ exclude = [
70
65
  "*.egg-info",
71
66
  ".git",
72
67
  ]
68
+ [tool.ruff.lint]
69
+ select = ["B", "C", "E", "F", "I", "W", "T", "B9"]
70
+ ignore = [
71
+ "E501", # E501 Line too long - handled by black, see https://docs.astral.sh/ruff/faq/#is-ruff-compatible-with-black
72
+ "C901", # C901 complex-structure - later refactoring will handle this, see https://docs.astral.sh/ruff/rules/complex-structure/#complex-structure-c901
73
+ ]
@@ -0,0 +1,53 @@
1
+ from pathlib import Path
2
+ from types import SimpleNamespace
3
+
4
+ from localstack_snapshot.pytest.snapshot import package_scoped_nodeid
5
+
6
+
7
+ def _create_package(root: Path) -> Path:
8
+ package = root / "my-package"
9
+ (package / "tests" / "services").mkdir(parents=True)
10
+ (package / "pyproject.toml").touch()
11
+ return package
12
+
13
+
14
+ def test_nodeid_from_a_package_rooted_run_is_unchanged(tmp_path):
15
+ package = _create_package(tmp_path)
16
+ item = SimpleNamespace(
17
+ path=package / "tests" / "services" / "test_thing.py",
18
+ nodeid="tests/services/test_thing.py::TestThing::test_case[param]",
19
+ )
20
+
21
+ assert (
22
+ package_scoped_nodeid(item) == "tests/services/test_thing.py::TestThing::test_case[param]"
23
+ )
24
+
25
+
26
+ def test_nodeid_from_a_repo_rooted_run_is_anchored_to_the_package(tmp_path):
27
+ package = _create_package(tmp_path)
28
+ item = SimpleNamespace(
29
+ path=package / "tests" / "services" / "test_thing.py",
30
+ nodeid="my-package/tests/services/test_thing.py::test_case",
31
+ )
32
+
33
+ assert package_scoped_nodeid(item) == "tests/services/test_thing.py::test_case"
34
+
35
+
36
+ def test_nearest_pyproject_wins_over_the_workspace_root(tmp_path):
37
+ (tmp_path / "pyproject.toml").touch()
38
+ package = _create_package(tmp_path)
39
+ item = SimpleNamespace(
40
+ path=package / "tests" / "services" / "test_thing.py",
41
+ nodeid="my-package/tests/services/test_thing.py::test_case",
42
+ )
43
+
44
+ assert package_scoped_nodeid(item) == "tests/services/test_thing.py::test_case"
45
+
46
+
47
+ def test_nodeid_without_an_enclosing_package_is_unchanged(tmp_path):
48
+ item = SimpleNamespace(
49
+ path=tmp_path / "tests" / "test_thing.py",
50
+ nodeid="tests/test_thing.py::test_case",
51
+ )
52
+
53
+ assert package_scoped_nodeid(item) == "tests/test_thing.py::test_case"
@@ -1 +0,0 @@
1
- __version__ = "0.3.3"
@@ -1,8 +0,0 @@
1
- jsonpath-ng>1.6
2
- deepdiff
3
-
4
- [dev]
5
- black==23.10.0
6
- pytest>=7.0
7
- coverage[toml]>=5.0.0
8
- ruff==0.1.0