Script 'mail_helper' called by obssrc
Hello community,
here is the log from the commit of package python-inline-snapshot for
openSUSE:Factory checked in at 2026-07-02 20:08:43
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-inline-snapshot (Old)
and /work/SRC/openSUSE:Factory/.python-inline-snapshot.new.1982 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-inline-snapshot"
Thu Jul 2 20:08:43 2026 rev:11 rq:1363034 version:0.34.2
Changes:
--------
---
/work/SRC/openSUSE:Factory/python-inline-snapshot/python-inline-snapshot.changes
2026-05-20 15:23:39.384004109 +0200
+++
/work/SRC/openSUSE:Factory/.python-inline-snapshot.new.1982/python-inline-snapshot.changes
2026-07-02 20:11:18.917260322 +0200
@@ -1,0 +2,17 @@
+Wed Jul 1 16:24:15 UTC 2026 - Dirk Müller <[email protected]>
+
+- update to 0.34.2:
+ * Fixed snapshot updates when pytest reuses stale assertion-
+ rewrite cache files after a test folder is moved, which could
+ leave cached code objects pointing at the old source path
+ * Fixed `snapshot_arg()` to use the `fix` category (instead of
+ `create`) when creating an argument with an existing non-
+ ellipsis default argument value.
+ * `get_snapshot_value()` now accepts a `which` parameter
+ (`"new"` or `"old"`) to select whether to return the new
+ (just-compared) or the old (previously stored) snapshot value
+ (#336).
+ * `Example.run_pytest`: deterministic test order by using `-p
+ no:ranodmly`
+
+-------------------------------------------------------------------
Old:
----
inline_snapshot-0.33.0.tar.gz
New:
----
inline_snapshot-0.34.2.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-inline-snapshot.spec ++++++
--- /var/tmp/diff_new_pack.7vBn7v/_old 2026-07-02 20:11:19.449278730 +0200
+++ /var/tmp/diff_new_pack.7vBn7v/_new 2026-07-02 20:11:19.453278869 +0200
@@ -26,7 +26,7 @@
%endif
%{?sle15_python_module_pythons}
Name: python-inline-snapshot%{psuffix}
-Version: 0.33.0
+Version: 0.34.2
Release: 0
Summary: Create and update inline snapshots in your Python code
License: MIT
++++++ inline_snapshot-0.33.0.tar.gz -> inline_snapshot-0.34.2.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/.pre-commit-config.yaml
new/inline_snapshot-0.34.2/.pre-commit-config.yaml
--- old/inline_snapshot-0.33.0/.pre-commit-config.yaml 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/.pre-commit-config.yaml 2020-02-02
01:00:00.000000000 +0100
@@ -33,6 +33,11 @@
entry: python3 scripts/replace_words.py
language: system
files: \.(md|py)$
+ - id: clean-changelog-fragments
+ name: Clean Changelog Fragments
+ entry: python3 scripts/clean_changelog_fragments.py
+ language: system
+ files: ^changelog\.d/.*\.md$
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v3.2.0
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/AGENTS.md
new/inline_snapshot-0.34.2/AGENTS.md
--- old/inline_snapshot-0.33.0/AGENTS.md 1970-01-01 01:00:00.000000000
+0100
+++ new/inline_snapshot-0.34.2/AGENTS.md 2020-02-02 01:00:00.000000000
+0100
@@ -0,0 +1,91 @@
+# AGENTS.md
+
+## Project Overview
+
+`inline-snapshot` is a Python snapshot/approval testing library for pytest.
Its core feature is storing expected values directly in source code through
APIs such as `snapshot()`, `snapshot_arg()`, `external()`, and `outsource()`.
The package also ships a pytest plugin that can report, review, create, update,
trim, and fix snapshots.
+
+The project supports Python 3.9 through 3.14 and PyPy where possible. CI runs
across Linux, macOS, Windows, CPython, PyPy, and both Pydantic 1 and 2
dependency sets.
+
+## Repository Layout
+
+- `src/inline_snapshot/`: package source.
+- `src/inline_snapshot/pytest_plugin.py`: pytest entry point and CLI flag
handling.
+- `src/inline_snapshot/_inline_snapshot.py`, `_snapshot_arg.py`,
`_get_snapshot_value.py`: main public snapshot behavior.
+- `src/inline_snapshot/_snapshot/`: snapshot value implementations such as
equality, dict, min/max, collection, and undecided values.
+- `src/inline_snapshot/_customize/`: code-generation customization support.
+- `src/inline_snapshot/_external/`: external snapshot files, formats, storage,
diffing, and outsourcing.
+- `src/inline_snapshot/plugin/`: first-party plugin hook specification and
default plugin.
+- `src/inline_snapshot/testing/_example.py`: preferred test harness for new
behavior tests.
+- `tests/`: pytest suite. Adapter tests live in `tests/adapter/`; external
snapshot tests live in `tests/external/`.
+- `docs/`: MkDocs Material documentation.
+- `changelog.d/`: scriv changelog fragments. Do not edit `CHANGELOG.md`
directly.
+- `.github/workflows/ci.yml`: CI matrix and coverage enforcement.
+
+## Development Commands
+
+The project is configured around `uv` and Hatch.
+
+- Install/run ad hoc commands: `uv run --group dev ...`
+- Run the normal test suite: `uv run --group dev pytest`
+- Run a focused test: `uv run --group dev pytest tests/test_file.py::test_name`
+- Run tests with coverage locally: `hatch test -acp`
+- Run the full Hatch test matrix: `hatch test`
+- Run one Hatch Python version with pytest args: `hatch test -py 3.10 -- --sw`
+- Run mypy like CI: `uv run --with pip --group dev -p 3.12 mypy
--non-interactive --install-types src/inline_snapshot tests`
+- Build docs strictly: `hatch run docs:build`
+- Serve docs: `hatch run docs:serve`
+- Run pre-commit on all files: `pre-commit run -a`
+
+If dependencies are missing, prefer `uv run --group dev ...` before adding new
tooling.
+
+## Testing Guidance
+
+New tests should usually use `inline_snapshot.testing.Example` from
`src/inline_snapshot/testing/_example.py`. This is also called out in
`CONTRIBUTING.md` as the preferred style.
+
+- Use `Example(...).run_inline(...)` for fast in-process tests of snapshot
behavior and source rewrites.
+- Use `Example(...).run_pytest(...)` when behavior depends on the real pytest
plugin, assertion rewriting, subprocess execution, terminal output, or pytest
reports.
+- Use `snapshot_arg()` in tests when expected values themselves should be
snapshot-managed.
+- Many tests compare changed files, report text, stderr, outcomes, or raised
exceptions; keep these assertions explicit.
+- CPython-only rewriting tests are skipped on PyPy unless marked with
`@pytest.mark.no_rewriting`.
+- The suite has a hard 100% coverage requirement in CI. Add tests with code
changes, and use `# pragma: no cover` only for genuinely untestable paths.
+
+Snapshot-changing tests may rewrite files. Review diffs carefully after
running tests with update flags such as
`--inline-snapshot=create,fix,update,trim` or shortcuts from
`[tool.inline-snapshot]`.
+
+## Formatting and Style
+
+- Black and isort are used; isort is configured with `profile = "black"` and
`force_single_line = true`.
+- Pre-commit also runs pyupgrade, autoflake, blacken-docs, YAML formatting,
actionlint, typos, and pyproject validation.
+- Keep imports in the existing single-import-per-line style.
+- The public API is exported from `src/inline_snapshot/__init__.py`; update
`__all__` when adding public symbols.
+- `py.typed` is present, so public typing quality matters.
+
+## Pytest Plugin and Configuration Notes
+
+- The pytest plugin is registered through `[project.entry-points.pytest11]` as
`inline_snapshot = "inline_snapshot.pytest_plugin"`.
+- The main CLI option is `--inline-snapshot=` with flags including `disable`,
`short-report`, `report`, `review`, `create`, `update`, `trim`, `fix`, and
insider-only `fix-assert`.
+- Project configuration is read from `[tool.inline-snapshot]` in
`pyproject.toml`.
+- Custom shortcut options may be generated from inline-snapshot config.
+- xdist is detected and affects snapshot session behavior.
+- Assertion rewriting is registered for `inline_snapshot.extra` and
`inline_snapshot.testing._example`.
+
+## Documentation
+
+Docs are built with MkDocs Material. The nav and plugins are configured in
`mkdocs.yml`.
+
+- Source docs live under `docs/`.
+- The docs build watches `CONTRIBUTING.md`, `CHANGELOG.md`, `README.md`,
`src/inline_snapshot`, and `changelog.d`.
+- Use `hatch run docs:build` before touching docs-heavy changes when feasible.
+
+## Changelog and Release Notes
+
+For user-visible changes, create a scriv fragment:
+
+```bash
+uvx scriv create --add
+```
+
+Fill in only the relevant headings in the generated `changelog.d/*.md` file.
Do not edit `CHANGELOG.md` manually; it is assembled by `scriv collect`.
+
+## Current Workspace Caution
+
+At the time this file was created, `src/inline_snapshot/_adapter_context.py`
already had uncommitted changes. Treat unrelated local modifications as user
work and do not revert them.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/CHANGELOG.md
new/inline_snapshot-0.34.2/CHANGELOG.md
--- old/inline_snapshot-0.33.0/CHANGELOG.md 2020-02-02 01:00:00.000000000
+0100
+++ new/inline_snapshot-0.34.2/CHANGELOG.md 2020-02-02 01:00:00.000000000
+0100
@@ -1,4 +1,29 @@
+<a id='changelog-0.34.2'></a>
+# 0.34.2 — 2026-06-19
+
+## Fixed
+
+- Fixed snapshot updates when pytest reuses stale assertion-rewrite cache
files after a test folder is moved, which could leave cached code objects
pointing at the old source path
([#369](https://github.com/15r10nk/inline-snapshot/issues/369)).
+
+<a id='changelog-0.34.1'></a>
+# 0.34.1 — 2026-06-05
+
+## Fixed
+
+- Fixed `snapshot_arg()` to use the `fix` category (instead of `create`) when
creating an argument with an existing non-ellipsis default argument value.
+
+<a id='changelog-0.34.0'></a>
+# 0.34.0 — 2026-05-29
+
+## Added
+
+- `get_snapshot_value()` now accepts a `which` parameter (`"new"` or `"old"`)
to select whether to return the new (just-compared) or the old (previously
stored) snapshot value
([#336](https://github.com/15r10nk/inline-snapshot/issues/336)).
+
+## Fixed
+
+- `Example.run_pytest`: deterministic test order by using `-p no:ranodmly`
+
<a id='changelog-0.33.0'></a>
# 0.33.0 — 2026-05-12
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/PKG-INFO
new/inline_snapshot-0.34.2/PKG-INFO
--- old/inline_snapshot-0.33.0/PKG-INFO 2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/PKG-INFO 2020-02-02 01:00:00.000000000 +0100
@@ -1,6 +1,6 @@
Metadata-Version: 2.4
Name: inline-snapshot
-Version: 0.33.0
+Version: 0.34.2
Summary: golden master/snapshot/approval testing library which puts the values
right into your source code
Project-URL: Changelog,
https://15r10nk.github.io/inline-snapshot/latest/changelog/
Project-URL: Discussions,
https://github.com/15r10nk/inline-snapshots/discussions
@@ -128,7 +128,7 @@
The following examples show how you can use inline-snapshot in your tests.
Take a look at the
[documentation](https://15r10nk.github.io/inline-snapshot/latest) if you want
to know more.
-<!-- inline-snapshot: create fix trim first_block outcome-passed=1 -->
+<!-- inline-snapshot: create fix trim first_block outcome-passed=1
outcome-errors=1 -->
``` python
from inline_snapshot import external, outsource, snapshot
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/README.md
new/inline_snapshot-0.34.2/README.md
--- old/inline_snapshot-0.33.0/README.md 2020-02-02 01:00:00.000000000
+0100
+++ new/inline_snapshot-0.34.2/README.md 2020-02-02 01:00:00.000000000
+0100
@@ -87,7 +87,7 @@
The following examples show how you can use inline-snapshot in your tests.
Take a look at the
[documentation](https://15r10nk.github.io/inline-snapshot/latest) if you want
to know more.
-<!-- inline-snapshot: create fix trim first_block outcome-passed=1 -->
+<!-- inline-snapshot: create fix trim first_block outcome-passed=1
outcome-errors=1 -->
``` python
from inline_snapshot import external, outsource, snapshot
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/docs/categories.md
new/inline_snapshot-0.34.2/docs/categories.md
--- old/inline_snapshot-0.33.0/docs/categories.md 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/docs/categories.md 2020-02-02
01:00:00.000000000 +0100
@@ -80,7 +80,7 @@
assert 8 == s["key"]
```
-<!-- inline-snapshot: fix outcome-passed=1 -->
+<!-- inline-snapshot: fix outcome-passed=1 outcome-errors=1 -->
``` python hl_lines="5 7 9 11"
from inline_snapshot import snapshot
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/docs/eq_snapshot.md
new/inline_snapshot-0.34.2/docs/eq_snapshot.md
--- old/inline_snapshot-0.33.0/docs/eq_snapshot.md 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/docs/eq_snapshot.md 2020-02-02
01:00:00.000000000 +0100
@@ -37,7 +37,7 @@
```
=== "--inline-snapshot=fix"
- <!-- inline-snapshot: fix outcome-passed=1 -->
+ <!-- inline-snapshot: fix outcome-passed=1 outcome-errors=1 -->
``` python hl_lines="5"
from inline_snapshot import snapshot
@@ -181,7 +181,7 @@
Re-running the test with `--inline-snapshot=fix` will update the snapshot to
match the new value of `payload`, while keeping the `date` as a dirty-equals
expression:
-<!-- inline-snapshot: fix outcome-passed=1 -->
+<!-- inline-snapshot: fix outcome-passed=1 outcome-errors=1 -->
``` python hl_lines="17"
import datetime
from dirty_equals import IsNow
@@ -277,7 +277,7 @@
```
=== "--inline-snapshot=fix"
- <!-- inline-snapshot: fix outcome-passed=1 -->
+ <!-- inline-snapshot: fix outcome-passed=1 outcome-errors=1 -->
``` python hl_lines="6"
from inline_snapshot import Is, snapshot
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/docs/external/external.md
new/inline_snapshot-0.34.2/docs/external/external.md
--- old/inline_snapshot-0.33.0/docs/external/external.md 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/docs/external/external.md 2020-02-02
01:00:00.000000000 +0100
@@ -73,7 +73,7 @@
)
```
-<!-- inline-snapshot: create fix outcome-passed=1 -->
+<!-- inline-snapshot: create fix outcome-passed=1 outcome-errors=1 -->
``` python hl_lines="6 7 8 9 10 11 12 13"
from inline_snapshot import external, snapshot
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/docs/howto/parametrize.md
new/inline_snapshot-0.34.2/docs/howto/parametrize.md
--- old/inline_snapshot-0.33.0/docs/howto/parametrize.md 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/docs/howto/parametrize.md 2020-02-02
01:00:00.000000000 +0100
@@ -1,6 +1,9 @@
inline-snapshot can also be used with `pytest.mark.parametrize`.
-All you have to do is to use `snapshot()` as an parameter for your test
+
+## One parametrize
+
+You can use `snapshot()` as a parameter for your test.
<!-- inline-snapshot: first_block outcome-passed=2 outcome-errors=2 -->
``` python
@@ -19,7 +22,7 @@
assert a + b == result
```
-and the missing value will be created for each run.
+The missing values will be created on the next run.
<!-- inline-snapshot: create outcome-passed=2 outcome-errors=2 -->
``` python hl_lines="8 9"
@@ -37,3 +40,91 @@
def test_param(a, b, result):
assert a + b == result
```
+
+## Multiple parametrize
+
+Stacking `@pytest.mark.parametrize` creates a cross-product of all
combinations, so `snapshot()` can no longer be used as an argument.
+Instead, use a single snapshot object that stores all combinations indexed by
a stable key.
+
+<!-- inline-snapshot: first_block outcome-passed=9 outcome-errors=9 -->
+``` python
+import pytest
+from inline_snapshot import snapshot
+
+snapshot_results = snapshot()
+
+
[email protected]("a", [1, 2, 3])
[email protected]("b", [10, 20, 30])
+def test_parametrize_stack(a, b):
+ assert snapshot_results[f"{a}+{b}"] == a + b
+```
+
+Once the snapshots are created, it looks like this:
+
+<!-- inline-snapshot: create outcome-passed=9 outcome-errors=9 -->
+``` python hl_lines="4 5 6 7 8 9 10 11 12 13 14 15 16"
+import pytest
+from inline_snapshot import snapshot
+
+snapshot_results = snapshot(
+ {
+ "1+10": 11,
+ "2+10": 12,
+ "3+10": 13,
+ "1+20": 21,
+ "2+20": 22,
+ "3+20": 23,
+ "1+30": 31,
+ "2+30": 32,
+ "3+30": 33,
+ }
+)
+
+
[email protected]("a", [1, 2, 3])
[email protected]("b", [10, 20, 30])
+def test_parametrize_stack(a, b):
+ assert snapshot_results[f"{a}+{b}"] == a + b
+```
+
+## Store values externally
+
+You can use `outsource()` when you want to store larger values.
+
+<!-- inline-snapshot: first_block outcome-passed=4 outcome-errors=4 -->
+``` python
+import pytest
+from inline_snapshot import external, outsource, snapshot
+
+external_snapshots = snapshot()
+
+
[email protected]("a", [1, 2])
[email protected]("b", [10, 20])
+def test_parametrize_stack_external(a, b):
+ assert external_snapshots[f"[{a}]*{b}"] == outsource([a] * b)
+```
+
+The values will be stored in external JSON files when you run pytest.
+
+<!-- inline-snapshot: create outcome-passed=4 outcome-errors=4 -->
+``` python hl_lines="4 5 6 7 8 9 10 11"
+import pytest
+from inline_snapshot import external, outsource, snapshot
+
+external_snapshots = snapshot(
+ {
+ "[1]*10": external("uuid:e443df78-9558-467f-9ba9-1faf7a024204.json"),
+ "[2]*10": external("uuid:23a7711a-8133-4876-b7eb-dcd9e87a1613.json"),
+ "[1]*20": external("uuid:1846d424-c17c-4279-a3c6-612f48268673.json"),
+ "[2]*20": external("uuid:fcbd04c3-4021-4ef7-8ca5-a5a19e4d6e3c.json"),
+ }
+)
+
+
[email protected]("a", [1, 2])
[email protected]("b", [10, 20])
+def test_parametrize_stack_external(a, b):
+ assert external_snapshots[f"[{a}]*{b}"] == outsource([a] * b)
+```
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/docs/index.md
new/inline_snapshot-0.34.2/docs/index.md
--- old/inline_snapshot-0.33.0/docs/index.md 2020-02-02 01:00:00.000000000
+0100
+++ new/inline_snapshot-0.34.2/docs/index.md 2020-02-02 01:00:00.000000000
+0100
@@ -89,7 +89,7 @@
=== "--inline-snapshot=fix"
- <!-- inline-snapshot: fix outcome-passed=1 -->
+ <!-- inline-snapshot: fix outcome-passed=1 outcome-errors=1 -->
``` python hl_lines="9"
from inline_snapshot import snapshot
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/docs/plugin.md
new/inline_snapshot-0.34.2/docs/plugin.md
--- old/inline_snapshot-0.33.0/docs/plugin.md 2020-02-02 01:00:00.000000000
+0100
+++ new/inline_snapshot-0.34.2/docs/plugin.md 2020-02-02 01:00:00.000000000
+0100
@@ -218,7 +218,7 @@
return builder.create_external(value)
```
-<!-- inline-snapshot: create fix first_block outcome-passed=1 -->
+<!-- inline-snapshot: create fix first_block outcome-passed=1 outcome-errors=1
-->
``` python title="test_long_strings.py"
from inline_snapshot import external, snapshot
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/docs/snapshot_arg.md
new/inline_snapshot-0.34.2/docs/snapshot_arg.md
--- old/inline_snapshot-0.33.0/docs/snapshot_arg.md 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/docs/snapshot_arg.md 2020-02-02
01:00:00.000000000 +0100
@@ -1,4 +1,3 @@
-
# snapshot_arg(...)
`snapshot_arg` lets you embed snapshot assertions inside a helper function, so
callers don't need to pass `snapshot()` at every call site.
@@ -86,10 +85,10 @@
2. Asserting this snapshot ensures it gets reset when `expr` stops returning a
value.
-We are using `None` as the default because we want to omit the argument when
its value matches the default. Using `...` would force inline-snapshot to
always create it.
-Running with `--inline-snapshot=create` fills in only the arguments whose
value differs from the default:
+We are using `None` as the default because we want to omit the argument when
its value matches the default.
+Running with `--inline-snapshot=fix` fills in only the arguments whose value
differs from the default:
-<!-- inline-snapshot: create outcome-passed=1 outcome-errors=1 -->
+<!-- inline-snapshot: fix outcome-passed=1 outcome-errors=1 -->
``` python hl_lines="17 18"
from inline_snapshot import snapshot_arg
@@ -140,7 +139,7 @@
1. New style — no `snapshot()` needed.
2. Old style — `snapshot()` is now redundant and can be removed.
-<!-- inline-snapshot: create outcome-passed=1 outcome-errors=1 -->
+<!-- inline-snapshot: create fix outcome-passed=1 outcome-errors=1 -->
``` python hl_lines="6 9"
from inline_snapshot import snapshot
from inline_snapshot.extra import prints
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/docs/testing.md
new/inline_snapshot-0.34.2/docs/testing.md
--- old/inline_snapshot-0.33.0/docs/testing.md 2020-02-02 01:00:00.000000000
+0100
+++ new/inline_snapshot-0.34.2/docs/testing.md 2020-02-02 01:00:00.000000000
+0100
@@ -27,7 +27,7 @@
Inline-snapshot will then populate the empty snapshots.
-<!-- inline-snapshot: create outcome-passed=1 outcome-errors=1 -->
+<!-- inline-snapshot: create fix outcome-passed=1 outcome-errors=1 -->
``` python hl_lines="17 18 19 20 21 22 23 24 25 26 27"
from inline_snapshot import snapshot
from inline_snapshot.testing import Example
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/scripts/clean_changelog_fragments.py
new/inline_snapshot-0.34.2/scripts/clean_changelog_fragments.py
--- old/inline_snapshot-0.33.0/scripts/clean_changelog_fragments.py
1970-01-01 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/scripts/clean_changelog_fragments.py
2020-02-02 01:00:00.000000000 +0100
@@ -0,0 +1,29 @@
+import re
+import sys
+
+
+def clean_changelog_fragment(file_path):
+ with open(file_path, encoding="utf-8", newline="") as file:
+ content = original_content = file.read()
+
+ content = content.replace("\r\n", "\n").replace("\r", "\n")
+
+ # Remove HTML comments (both single-line and multi-line)
+ content = re.sub(r"<!--.*?-->", "", content, flags=re.DOTALL)
+
+ # Remove excess blank lines left behind (more than two consecutive
newlines)
+ content = re.sub(r"\n{3,}", "\n\n", content)
+
+ content = content.strip()
+ if content:
+ content += "\n"
+
+ if original_content != content:
+ with open(file_path, "w", encoding="utf-8", newline="\n") as file:
+ print("change:", file_path)
+ file.write(content)
+
+
+if __name__ == "__main__":
+ for file_path in sys.argv[1:]:
+ clean_changelog_fragment(file_path)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_change.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_change.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/_change.py 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/_change.py 2020-02-02
01:00:00.000000000 +0100
@@ -5,7 +5,6 @@
from dataclasses import dataclass
from pathlib import Path
from typing import TYPE_CHECKING
-from typing import Any
from typing import DefaultDict
from typing import Tuple
from typing import cast
@@ -125,7 +124,6 @@
@dataclass()
class Delete(Change):
node: ast.AST | None
- old_value: Any
@dataclass()
@@ -134,7 +132,6 @@
position: int
new_code: list[str]
- new_values: list[Any]
def __post_init__(self):
self.new_code = [self.file.format_expression(v) for v in self.new_code]
@@ -146,7 +143,6 @@
position: int
new_code: list[tuple[str, str]]
- new_values: list[tuple[Any, Any]]
def __post_init__(self):
self.new_code = [
@@ -160,8 +156,6 @@
node: ast.AST
new_code: str
- old_value: Any
- new_value: Any
def apply(self, recorder: ChangeRecorder):
change = recorder.new_change()
@@ -179,7 +173,6 @@
arg_name: str | None
new_code: str
- new_value: Any
def __post_init__(self):
self.new_code = self.file.format_expression(self.new_code)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_exceptions.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_exceptions.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/_exceptions.py
2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/_exceptions.py
2020-02-02 01:00:00.000000000 +0100
@@ -1,2 +1,6 @@
class UsageError(Exception):
pass
+
+
+class ValueNotFound(Exception):
+ pass
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_external/_external.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_external/_external.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/_external/_external.py
2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/_external/_external.py
2020-02-02 01:00:00.000000000 +0100
@@ -11,6 +11,7 @@
from inline_snapshot._external._external_base import ExternalBase
from inline_snapshot._external._format._protocol import get_format_handler
from inline_snapshot._external._format._protocol import
get_format_handler_from_suffix
+from inline_snapshot._external._storage._protocol import StorageLookupError
from inline_snapshot._global_state import state
from inline_snapshot._inline_snapshot import create_snapshot
from inline_snapshot._types import SnapshotRefBase
@@ -94,7 +95,6 @@
0,
None,
f'"{new_name}"',
- new_name,
)
else:
@@ -107,8 +107,6 @@
self._context.file,
node.args[0] if node else None,
f'"{new_name}"',
- self._original_name,
- new_name,
)
yield from super()._changes()
@@ -142,8 +140,21 @@
format.encode(other, self._tmp_file)
self._location = self.storage.new_location(self._location,
self._tmp_file)
- def _load_value(self):
- return self._load_value_from_location(self._original_location)
+ def _load_value(self, which):
+ if which == "new":
+ if self._tmp_file:
+ format = get_format_handler_from_suffix(self._location.suffix)
+ return format.decode(self._tmp_file)
+ else:
+ raise StorageLookupError("no new value", files=[])
+ if which == "old":
+ location = self._original_location
+ if not location.exists():
+ raise StorageLookupError("no old value", files=[])
+
+ return self._load_value_from_location(location)
+
+ assert False, f"which has to be new or old but is {which!r}"
@classmethod
def _load_value_from_location(cls, location: ExternalLocation) -> object:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_external/_external_base.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_external/_external_base.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/_external/_external_base.py
2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/_external/_external_base.py
2020-02-02 01:00:00.000000000 +0100
@@ -37,7 +37,7 @@
def _assign(self, value):
raise NotImplementedError()
- def _load_value(self):
+ def _load_value(self, which):
raise NotImplementedError()
def __eq__(self, other):
@@ -77,7 +77,7 @@
return False
try:
- value = self._load_value()
+ value = self._load_value("old")
except StorageLookupError as error:
if not error.files and state().update_flags.fix:
self._original_location = ExternalLocation.from_name("")
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_external/_external_file.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_external/_external_file.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/_external/_external_file.py
2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/_external/_external_file.py
2020-02-02 01:00:00.000000000 +0100
@@ -41,13 +41,20 @@
path = filename
return f"external_file({str(path)!r})"
- def _load_value(self):
- try:
- return self._format.decode(self._filename)
- except FileNotFoundError:
- raise StorageLookupError(
- f"cannot read {self._filename}", files=[self._filename]
- )
+ def _load_value(self, which):
+ if which == "new":
+ if self._tmp_file:
+ format = get_format_handler_from_suffix(self._location.suffix)
+ return format.decode(self._tmp_file)
+ else:
+ raise StorageLookupError("no new value", files=[])
+ if which == "old":
+ try:
+ return self._format.decode(self._filename)
+ except FileNotFoundError:
+ raise StorageLookupError("old value not found", files=[])
+
+ assert False
def external_file(path: Union[Path, str], *, format: Optional[str] = None):
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_external/_storage/_protocol.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_external/_storage/_protocol.py
---
old/inline_snapshot-0.33.0/src/inline_snapshot/_external/_storage/_protocol.py
2020-02-02 01:00:00.000000000 +0100
+++
new/inline_snapshot-0.34.2/src/inline_snapshot/_external/_storage/_protocol.py
2020-02-02 01:00:00.000000000 +0100
@@ -4,10 +4,12 @@
from pathlib import Path
from typing import Generator
+from inline_snapshot._exceptions import ValueNotFound
+
from .._external_location import ExternalLocation
-class StorageLookupError(Exception):
+class StorageLookupError(ValueNotFound):
def __init__(self, msg, files):
super().__init__(msg)
self.files = files
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_get_snapshot_value.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_get_snapshot_value.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/_get_snapshot_value.py
2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/_get_snapshot_value.py
2020-02-02 01:00:00.000000000 +0100
@@ -1,39 +1,61 @@
+from typing import Any
+from typing import Literal
+from typing import Tuple
from typing import TypeVar
+from typing import Union
+
+from inline_snapshot._customize._custom import Custom
from ._exceptions import UsageError
+from ._exceptions import ValueNotFound
from ._external._external import External
from ._external._external_file import ExternalFile
from ._external._outsource import Outsourced
-from ._external._storage._protocol import StorageLookupError
from ._global_state import state
from ._is import Is
from ._snapshot.generic_value import GenericValue
from ._types import Snapshot
+options = {
+ "new": ["new", "old"],
+ "old": ["old"],
+}
+
+
+def unwrap(value, which) -> Tuple[Any, bool]:
+ if isinstance(value, (External, ExternalFile, GenericValue)):
+ for w in options[which]:
+ try:
+ v = value._load_value(w)
+ except ValueNotFound:
+ continue
+ return unwrap(v, which)[0], True
+ return (..., True)
+
+ if isinstance(value, Custom):
+
+ def unwrap_child(value):
+ return unwrap(value, which)[0]
-def unwrap(value):
- if isinstance(value, GenericValue):
- return value._visible_value()._map(lambda v: unwrap(v)[0]), True
+ return value._map(unwrap_child), True
if isinstance(value, Outsourced):
return (value.data, True)
- if isinstance(value, (External, Outsourced, ExternalFile)):
- try:
- return unwrap(value._load_value())[0], True
- except (UsageError, StorageLookupError):
- return (None, False)
-
- if isinstance(value, Is):
- return value.value, True
+ if isinstance(value, Is): # type: ignore
+ return unwrap(value.value, which)[0], True
return value, False
T = TypeVar("T", covariant=True)
+EllipsisType = type(...)
+
-def get_snapshot_value(snapshot_value: Snapshot[T]) -> T:
+def get_snapshot_value(
+ snapshot_value: Snapshot[T], which: Literal["new", "old"] = "new"
+) -> Union[T, EllipsisType]: # type: ignore[valid-type]
"""
Extracts and returns the raw value stored inside a snapshot, removing all
inline-snapshot-specific
wrappers such as those generated by `external()`, `Is()`, or `snapshot()`.
@@ -43,7 +65,10 @@
Args:
snapshot_value: The snapshot object from which to extract the value.
+ which: can be:
+ - `"old"`: the value which is "visible" in the source is returned
+ - `"new"`: the current value is returned
Returns:
The unwrapped value contained in the snapshot.
@@ -64,7 +89,10 @@
<!-- TODO: Find a way to test this code in the docs -->
"""
+ if which not in ("old", "new"):
+ raise UsageError("which must be 'old' or 'new'")
+
if state().active:
- return unwrap(snapshot_value)[0]
+ return unwrap(snapshot_value, which)[0]
else:
return snapshot_value # type: ignore
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_inline_snapshot.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_inline_snapshot.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/_inline_snapshot.py
2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/_inline_snapshot.py
2020-02-02 01:00:00.000000000 +0100
@@ -127,7 +127,6 @@
arg_pos=0,
arg_name=None,
new_code=new_code,
- new_value=self._value._new_value,
)
else:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_new_adapter.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_new_adapter.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/_new_adapter.py
2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/_new_adapter.py
2020-02-02 01:00:00.000000000 +0100
@@ -222,8 +222,6 @@
file=self.context.file,
new_code=new_code,
flag=flag,
- old_value=old_value._eval(),
- new_value=new_value,
)
return new_value
@@ -264,27 +262,20 @@
new_value_element = next(new)
new_code = yield from
new_value_element._code_repr(self.context)
result.append(new_value_element)
- to_insert[old_position].append((new_code, new_value_element))
+ to_insert[old_position].append(new_code)
elif c == "d":
old_value_element, old_node_element = next(old)
yield Delete(
"fix",
self.context.file,
old_node_element,
- old_value_element,
)
old_position += 1
else:
assert False
for position, code_values in to_insert.items():
- yield ListInsert(
- "fix",
- self.context.file,
- old_node,
- position,
- *zip(*code_values), # type: ignore
- )
+ yield ListInsert("fix", self.context.file, old_node, position,
code_values)
return type(new_value)(result)
@@ -310,22 +301,23 @@
result.append(v)
# delete surplus old elements
- for old_elem, old_node_elem in zip(old_elts[common:],
old_nodes[common:]):
- yield Delete("fix", self.context.file, old_node_elem, old_elem)
+ for old_node_elem in old_nodes[common:]:
+ yield Delete("fix", self.context.file, old_node_elem)
# insert extra new elements
if len(new_elts) > common:
to_insert = []
for new_elem in new_elts[common:]:
new_code = yield from new_elem._code_repr(self.context)
- to_insert.append((new_code, new_elem))
+ to_insert.append(new_code)
result.append(new_elem)
+
yield ListInsert(
"fix",
self.context.file,
old_node,
common,
- *zip(*to_insert), # type: ignore
+ to_insert,
)
return CustomTuple(result)
@@ -360,7 +352,7 @@
):
if key2 not in new_value.value:
# delete entries
- yield Delete("fix", self.context.file, node2,
old_value.value[key2])
+ yield Delete("fix", self.context.file, node2)
to_insert = []
insert_pos = 0
@@ -392,7 +384,6 @@
old_node,
insert_pos,
new_code,
- to_insert,
)
to_insert = []
@@ -416,7 +407,6 @@
old_node,
len(old_value.value),
new_code,
- to_insert,
)
return CustomDict(value=result)
@@ -465,7 +455,6 @@
flag,
self.context.file,
node,
- old_value.argument(arg_pos),
)
if old_args_len < len(new_args):
@@ -478,7 +467,6 @@
arg_pos=insert_pos,
arg_name=None,
new_code=new_code,
- new_value=insert_value,
)
result_args.append(insert_value)
@@ -504,7 +492,6 @@
),
self.context.file,
kw_value,
- old_value.argument(kw_arg),
)
to_insert = []
@@ -535,7 +522,6 @@
arg_pos=insert_pos,
arg_name=insert_key,
new_code=new_code,
- new_value=value,
)
to_insert = []
@@ -553,7 +539,6 @@
arg_pos=None,
arg_name=key,
new_code=new_code,
- new_value=value,
)
return CustomCall(
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_snapshot/collection_value.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_snapshot/collection_value.py
---
old/inline_snapshot-0.33.0/src/inline_snapshot/_snapshot/collection_value.py
2020-02-02 01:00:00.000000000 +0100
+++
new/inline_snapshot-0.34.2/src/inline_snapshot/_snapshot/collection_value.py
2020-02-02 01:00:00.000000000 +0100
@@ -55,7 +55,6 @@
flag="trim",
file=self._file,
node=old_node,
- old_value=old_value,
)
continue
@@ -71,17 +70,13 @@
file=self._file,
new_code=new_code,
flag="update",
- old_value=old_value,
- new_value=old_value,
)
new_codes = []
- new_values = []
for v in self._new_value.value:
if v not in self._old_value.value:
new_code = yield from v._code_repr(self._context)
new_codes.append(new_code)
- new_values.append(v._eval())
if new_codes:
yield ListInsert(
@@ -90,5 +85,4 @@
node=self._ast_node,
position=len(self._old_value.value),
new_code=new_codes,
- new_values=new_values,
)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_snapshot/dict_value.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_snapshot/dict_value.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/_snapshot/dict_value.py
2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/_snapshot/dict_value.py
2020-02-02 01:00:00.000000000 +0100
@@ -84,20 +84,18 @@
yield from self._new_value.value[key]._get_changes() # type:
ignore
else:
# delete entries
- yield Delete("trim", self._file, node,
self._old_value.value[key])
+ yield Delete("trim", self._file, node)
to_insert = []
- to_insert_values = []
for key, new_value_element in self._new_value.value.items():
if key not in self._old_value.value and not isinstance(
new_value_element, UndecidedValue
):
# add new values
- new_value = yield from new_value_element._new_code() # type:
ignore
+ new_code = yield from new_value_element._new_code() # type:
ignore
new_key = yield from key._code_repr(self._context)
- to_insert.append((new_key, new_value))
- to_insert_values.append((key, new_value_element))
+ to_insert.append((new_key, new_code))
if to_insert:
yield DictInsert(
@@ -106,5 +104,4 @@
self._ast_node,
len(self._old_value.value),
to_insert,
- to_insert_values,
)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_snapshot/generic_value.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_snapshot/generic_value.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/_snapshot/generic_value.py
2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/_snapshot/generic_value.py
2020-02-02 01:00:00.000000000 +0100
@@ -7,6 +7,7 @@
from inline_snapshot._customize._builder import Builder
from inline_snapshot._customize._custom import Custom
from inline_snapshot._customize._custom_undefined import CustomUndefined
+from inline_snapshot._exceptions import ValueNotFound
from inline_snapshot._new_adapter import reeval
from .._change import ChangeBase
@@ -45,6 +46,15 @@
return new_result
return result
+ def _load_value(self, which) -> Custom:
+
+ if which == "new" and not isinstance(self._new_value, CustomUndefined):
+ return self._new_value
+ elif which == "old" and not isinstance(self._old_value,
CustomUndefined):
+ return self._old_value
+
+ raise ValueNotFound
+
@property
def _file(self):
return self._context.file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_snapshot/min_max_value.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_snapshot/min_max_value.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/_snapshot/min_max_value.py
2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/_snapshot/min_max_value.py
2020-02-02 01:00:00.000000000 +0100
@@ -53,8 +53,6 @@
file=self._file,
new_code=new_code,
flag=flag,
- old_value=self._old_value._eval(),
- new_value=self._new_value._eval(),
)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_snapshot_arg.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_snapshot_arg.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/_snapshot_arg.py
2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/_snapshot_arg.py
2020-02-02 01:00:00.000000000 +0100
@@ -280,36 +280,36 @@
if is_default:
return
- new_code = yield from with_flag(self._value._new_code(), "create")
+ flag = "create" if self._default_value is ... else "fix"
+
+ new_code = yield from with_flag(self._value._new_code(), flag)
# The first positional argument can be inserted positionally;
# any later position requires keyword form to avoid leaving gaps.
if self._arg_pos == 0:
yield CallArg(
- flag="create",
+ flag=flag,
file=self._value._file,
node=self._context.expr.node,
arg_pos=0,
arg_name=None,
new_code=new_code,
- new_value=self._value._new_value,
)
else:
yield CallArg(
- flag="create",
+ flag=flag,
file=self._value._file,
node=self._context.expr.node,
arg_pos=None,
arg_name=self._name,
new_code=new_code,
- new_value=self._value._new_value,
)
else:
changes = list(self._value._get_changes())
if is_default and not isinstance(self._value._old_value,
CustomUnmanaged):
yield Delete(
- "fix" if changes else "trim", self._value._file,
self._node, None
+ "fix" if changes else "trim", self._value._file, self._node
)
else:
yield from changes
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/_snapshot_session.py
new/inline_snapshot-0.34.2/src/inline_snapshot/_snapshot_session.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/_snapshot_session.py
2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/_snapshot_session.py
2020-02-02 01:00:00.000000000 +0100
@@ -17,6 +17,7 @@
from inline_snapshot._external._storage import default_storages
from inline_snapshot._utils import category_link
from inline_snapshot._utils import link
+from inline_snapshot.fix_pytest_cache import fix_pytest_cache
from . import _config
from ._change import ChangeBase
@@ -381,6 +382,7 @@
def fix_libraries(self):
pydantic_fix()
fix_pytest_diff()
+ fix_pytest_cache()
def show_report(self, con: Console):
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/src/inline_snapshot/extra.py
new/inline_snapshot-0.34.2/src/inline_snapshot/extra.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/extra.py 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/extra.py 2020-02-02
01:00:00.000000000 +0100
@@ -118,9 +118,9 @@
print("some error", file=sys.stderr)
```
- === "--inline-snapshot=create"
+ === "--inline-snapshot=fix"
- <!-- inline-snapshot: create outcome-passed=1 outcome-errors=1 -->
+ <!-- inline-snapshot: fix outcome-passed=1 outcome-errors=1 -->
``` python hl_lines="7"
import sys
from inline_snapshot import snapshot
@@ -210,7 +210,7 @@
=== "--inline-snapshot=create"
- <!-- inline-snapshot: create fix outcome-passed=1 -->
+ <!-- inline-snapshot: create fix outcome-passed=1 outcome-errors=1 -->
``` python hl_lines="7"
from warnings import warn
from inline_snapshot import snapshot
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/fix_pytest_cache.py
new/inline_snapshot-0.34.2/src/inline_snapshot/fix_pytest_cache.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/fix_pytest_cache.py
1970-01-01 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/fix_pytest_cache.py
2020-02-02 01:00:00.000000000 +0100
@@ -0,0 +1,47 @@
+import types
+from pathlib import Path
+from typing import Callable
+from typing import Optional
+
+import _pytest.assertion.rewrite
+
+fixed = False
+
+
+def fix_pytest_cache():
+ # keep this fix until https://github.com/pytest-dev/pytest/pull/14551 is
merged
+ global fixed
+
+ if fixed:
+ return
+
+ _original_read_pyc = _pytest.assertion.rewrite._read_pyc
+
+ def _read_pyc(
+ source: Path, pyc: Path, trace: Callable[[str], None] = lambda x: None
+ ) -> Optional[types.CodeType]:
+
+ co = _original_read_pyc(source, pyc, trace)
+
+ if co is not None:
+ source_str = str(source)
+ if co.co_filename != source_str:
+ co = _replace_code_filenames(co, source_str)
+ return co
+
+ _pytest.assertion.rewrite._read_pyc = _read_pyc
+ fixed = True
+
+
+def _replace_code_filenames(co: types.CodeType, filename: str) ->
types.CodeType:
+ return co.replace(
+ co_filename=filename,
+ co_consts=tuple(
+ (
+ _replace_code_filenames(const, filename)
+ if isinstance(const, types.CodeType)
+ else const
+ )
+ for const in co.co_consts
+ ),
+ )
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/pytest_plugin.py
new/inline_snapshot-0.34.2/src/inline_snapshot/pytest_plugin.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/pytest_plugin.py
2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/pytest_plugin.py
2020-02-02 01:00:00.000000000 +0100
@@ -226,8 +226,8 @@
fix_assert(frame, left, right)
results = []
- left, left_unwrapped = unwrap(left)
- right, right_unwrapped = unwrap(right)
+ left, left_unwrapped = unwrap(left, "old")
+ right, right_unwrapped = unwrap(right, "old")
if left_unwrapped or right_unwrapped:
results = config.hook.pytest_assertrepr_compare(
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/testing/_example.py
new/inline_snapshot-0.34.2/src/inline_snapshot/testing/_example.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/testing/_example.py
2020-02-02 01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/testing/_example.py
2020-02-02 01:00:00.000000000 +0100
@@ -565,7 +565,7 @@
self._write_files(tmp_path)
- cmd = [sys.executable, "-m", "pytest", *args]
+ cmd = [sys.executable, "-m", "pytest", "-p", "no:randomly", *args]
command_env = dict(os.environ)
command_env["TERM"] = "unknown"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/src/inline_snapshot/version.py
new/inline_snapshot-0.34.2/src/inline_snapshot/version.py
--- old/inline_snapshot-0.33.0/src/inline_snapshot/version.py 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/src/inline_snapshot/version.py 2020-02-02
01:00:00.000000000 +0100
@@ -2,7 +2,7 @@
insider_version = ""
-__version__ = "0.33.0"
+__version__ = "0.34.2"
if is_insider:
__version__ += "." + insider_version
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/tests/external/test_external.py
new/inline_snapshot-0.34.2/tests/external/test_external.py
--- old/inline_snapshot-0.33.0/tests/external/test_external.py 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/tests/external/test_external.py 2020-02-02
01:00:00.000000000 +0100
@@ -203,11 +203,8 @@
returncode=1,
error="""\
> assert outsource("test2") == s
-E AssertionError: assert 'test2' == 'test'
-E \n\
-E - test
-E + test2
-E ? +
+E AssertionError: assert Outsourced(data='test2', suffix=None,
storage=None) == 'test'
+E + where Outsourced(data='test2', suffix=None, storage=None) =
outsource('test2')
""",
changed_files={
"tests/__inline_snapshot__/test_something/test_a/f728b4fa-4248-4e3a-8a5d-2f346baa9455.txt":
"test",
@@ -252,9 +249,8 @@
error=(
snapshot("""\
> assert outsource(b"test2") == s
-E AssertionError: assert b'test2' == b'test'
-E \n\
-E Use -v to get more diff
+E AssertionError: assert Outsourced(data=b'test2', suffix=None,
storage=None) == b'test'
+E + where Outsourced(data=b'test2', suffix=None, storage=None) =
outsource(b'test2')
""")
if sys.version_info >= (3, 11)
else snapshot("""\
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/tests/test_change.py
new/inline_snapshot-0.34.2/tests/test_change.py
--- old/inline_snapshot-0.33.0/tests/test_change.py 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/tests/test_change.py 2020-02-02
01:00:00.000000000 +0100
@@ -54,8 +54,6 @@
file=source,
node=call.args[0],
new_code="22",
- old_value=0,
- new_value=0,
)
],
snapshot("f(22,b=2)"),
@@ -68,7 +66,6 @@
flag="fix",
file=source,
node=call.args[0],
- old_value=0,
)
],
snapshot("f(b=2)"),
@@ -84,7 +81,6 @@
arg_pos=0,
arg_name=None,
new_code="22",
- new_value=22,
)
],
snapshot("f(22, a,b=2)"),
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/tests/test_docs.py
new/inline_snapshot-0.34.2/tests/test_docs.py
--- old/inline_snapshot-0.33.0/tests/test_docs.py 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/tests/test_docs.py 2020-02-02
01:00:00.000000000 +0100
@@ -431,8 +431,9 @@
)
if "fix" in flags:
- example.run_pytest(outcomes=(outcomes := Store()))
- assert "errors" not in outcomes.value
+ next_outcomes: Store[Dict[str, int]]
+ example.run_pytest(outcomes=(next_outcomes := Store()))
+ assert "errors" not in next_outcomes.value
print("flags:", flags, repr(block.block_options))
@@ -476,7 +477,7 @@
if changed_lines:
block.block_options["hl_lines"] = " ".join(changed_lines)
else:
- assert False, "no lines changed"
+ pass # pragma: no cover
if "first_block" not in options:
new_code = re.sub(r" *# *\(\d+\)\!?", "", new_code)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/inline_snapshot-0.33.0/tests/test_get_snapshot_value.py
new/inline_snapshot-0.34.2/tests/test_get_snapshot_value.py
--- old/inline_snapshot-0.33.0/tests/test_get_snapshot_value.py 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/tests/test_get_snapshot_value.py 2020-02-02
01:00:00.000000000 +0100
@@ -1,3 +1,5 @@
+from dataclasses import dataclass
+
import pytest
from inline_snapshot import Is
@@ -7,6 +9,8 @@
from inline_snapshot import snapshot
from inline_snapshot._global_state import snapshot_env
from inline_snapshot._global_state import state
+from inline_snapshot.extra import raises
+from inline_snapshot.testing._example import Example
def inspect(value):
@@ -48,12 +52,133 @@
assert inspect(get_snapshot_value(s)) == snapshot("[0, 5]")
-def test_external(try_snapshot_disable):
- s = external("hash:ef2d127de37b*.json")
+def test_external():
- assert s == 5
+ Example("""\
+from inline_snapshot import external,snapshot,get_snapshot_value
- assert inspect(get_snapshot_value(s)) == snapshot("5")
+def inspect(v):
+ return f"{type(v).__name__}: {v!r}"
+
+def test_external():
+ s = external()
+
+ assert inspect(get_snapshot_value(s,"new")) == snapshot()
+ assert inspect(get_snapshot_value(s,"old")) == snapshot()
+
+ assert s == "5"
+
+ assert inspect(get_snapshot_value(s,"new")) == snapshot()
+ assert inspect(get_snapshot_value(s,"old")) == snapshot()
+""").run_inline(
+ ["--inline-snapshot=create"],
+ changed_files={
+
"tests/__inline_snapshot__/test_something/test_external/e3e70682-c209-4cac-a29f-6fbed82c07cd.txt":
"5",
+ "tests/test_something.py": """\
+from inline_snapshot import external,snapshot,get_snapshot_value
+
+def inspect(v):
+ return f"{type(v).__name__}: {v!r}"
+
+def test_external():
+ s = external("uuid:e3e70682-c209-4cac-a29f-6fbed82c07cd.txt")
+
+ assert inspect(get_snapshot_value(s,"new")) == snapshot("ellipsis:
Ellipsis")
+ assert inspect(get_snapshot_value(s,"old")) == snapshot("ellipsis:
Ellipsis")
+
+ assert s == "5"
+
+ assert inspect(get_snapshot_value(s,"new")) == snapshot("str: '5'")
+ assert inspect(get_snapshot_value(s,"old")) == snapshot("ellipsis:
Ellipsis")
+""",
+ },
+ ).run_inline(
+ ["--inline-snapshot=fix"],
+ changed_files={"tests/test_something.py": """\
+from inline_snapshot import external,snapshot,get_snapshot_value
+
+def inspect(v):
+ return f"{type(v).__name__}: {v!r}"
+
+def test_external():
+ s = external("uuid:e3e70682-c209-4cac-a29f-6fbed82c07cd.txt")
+
+ assert inspect(get_snapshot_value(s,"new")) == snapshot("str: '5'")
+ assert inspect(get_snapshot_value(s,"old")) == snapshot("str: '5'")
+
+ assert s == "5"
+
+ assert inspect(get_snapshot_value(s,"new")) == snapshot("str: '5'")
+ assert inspect(get_snapshot_value(s,"old")) == snapshot("str: '5'")
+"""},
+ ).run_inline(
+ ["--inline-snapshot=disable"], reported_categories=set()
+ )
+
+
+def test_external_file():
+
+ Example("""\
+from inline_snapshot import external_file,snapshot,get_snapshot_value
+
+def inspect(v):
+ return f"{type(v).__name__}: {v!r}"
+
+def test_external():
+ s = external_file("file.txt")
+
+ assert inspect(get_snapshot_value(s,"new")) == snapshot()
+ assert inspect(get_snapshot_value(s,"old")) == snapshot()
+
+ assert s == "5"
+
+ assert inspect(get_snapshot_value(s,"new")) == snapshot()
+ assert inspect(get_snapshot_value(s,"old")) == snapshot()
+""").run_inline(
+ ["--inline-snapshot=create"],
+ changed_files={
+ "tests/file.txt": "5",
+ "tests/test_something.py": """\
+from inline_snapshot import external_file,snapshot,get_snapshot_value
+
+def inspect(v):
+ return f"{type(v).__name__}: {v!r}"
+
+def test_external():
+ s = external_file("file.txt")
+
+ assert inspect(get_snapshot_value(s,"new")) == snapshot("ellipsis:
Ellipsis")
+ assert inspect(get_snapshot_value(s,"old")) == snapshot("ellipsis:
Ellipsis")
+
+ assert s == "5"
+
+ assert inspect(get_snapshot_value(s,"new")) == snapshot("str: '5'")
+ assert inspect(get_snapshot_value(s,"old")) == snapshot("ellipsis:
Ellipsis")
+""",
+ },
+ reported_categories={"create", "fix"},
+ ).run_inline(
+ ["--inline-snapshot=fix"],
+ changed_files={"tests/test_something.py": """\
+from inline_snapshot import external_file,snapshot,get_snapshot_value
+
+def inspect(v):
+ return f"{type(v).__name__}: {v!r}"
+
+def test_external():
+ s = external_file("file.txt")
+
+ assert inspect(get_snapshot_value(s,"new")) == snapshot("str: '5'")
+ assert inspect(get_snapshot_value(s,"old")) == snapshot("str: '5'")
+
+ assert s == "5"
+
+ assert inspect(get_snapshot_value(s,"new")) == snapshot("str: '5'")
+ assert inspect(get_snapshot_value(s,"old")) == snapshot("str: '5'")
+"""},
+ ).run_inline(
+ ["--inline-snapshot=disable"], reported_categories=set()
+ )
def test_snapshot_is(try_snapshot_disable):
@@ -72,7 +197,23 @@
assert inspect(get_snapshot_value(s)) == snapshot("[0, 5]")
-from dataclasses import dataclass
+def test_get_snapshot_value_defined():
+ s = snapshot(5)
+
+ assert get_snapshot_value(s, "new") == 5
+ assert get_snapshot_value(s, "old") == 5
+
+
+def test_get_snapshot_value_undefined():
+ with snapshot_env():
+ s = snapshot()
+
+ assert get_snapshot_value(s, "new") == ...
+ assert get_snapshot_value(s, "old") == ...
+ assert s == 5
+
+ assert get_snapshot_value(s, "new") == 5
+ assert get_snapshot_value(s, "old") == ...
@dataclass
@@ -87,3 +228,9 @@
assert s == A(a=outsource(5), b=2)
assert inspect(get_snapshot_value(s)) == snapshot("A(a=5, b=2)")
+
+
+def test_error_message():
+ s = snapshot(0)
+ with raises("UsageError: which must be 'old' or 'new'"):
+ get_snapshot_value(s, "wrong")
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/tests/test_pytest_diff_fix.py
new/inline_snapshot-0.34.2/tests/test_pytest_diff_fix.py
--- old/inline_snapshot-0.33.0/tests/test_pytest_diff_fix.py 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/tests/test_pytest_diff_fix.py 2020-02-02
01:00:00.000000000 +0100
@@ -16,29 +16,29 @@
def test_dict_report():
- usd = snapshot({"name": "US Dollar", "code": "USD", "symbol": "$"})
+ usd = snapshot({"code": "USD", "name": "US Dollar", "symbol": "$"})
usd2 = Is([1,2])
price = {
"amount": 1,
+ "b":[1,2],
"currency": {
"code": "USD",
"name": "US Dollar",
"symbol": "$",
},
- "b":[1,2]
}
assert price == snapshot({
"amount": 2,
+ "b":usd2,
"currency": usd,
- "b":usd2
})
""").run_pytest(
["--inline-snapshot=report", "-vv"],
error=snapshot("""\
> assert price == snapshot({
-E AssertionError: assert {'amount': 1, 'currency': {'code': 'USD',
'name': 'US Dollar', 'symbol': '$'}, 'b': [1, 2]} == {'amount': 2, 'currency':
{'name': 'US Dollar', 'code': 'USD', 'symbol': '$'}, 'b': [1, 2]}
+E AssertionError: assert {'amount': 1, 'b': [1, 2], 'currency': {'code':
'USD', 'name': 'US Dollar', 'symbol': '$'}} == {'amount': 2, 'b': [1, 2],
'currency': {'code': 'USD', 'name': 'US Dollar', 'symbol': '$'}}
E \n\
E Common items:
E {'b': [1, 2], 'currency': {'code': 'USD', 'name': 'US Dollar',
'symbol': '$'}}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/tests/test_pytester.py
new/inline_snapshot-0.34.2/tests/test_pytester.py
--- old/inline_snapshot-0.33.0/tests/test_pytester.py 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/tests/test_pytester.py 2020-02-02
01:00:00.000000000 +0100
@@ -1,3 +1,6 @@
+import shutil
+import sys
+
from inline_snapshot import snapshot
from inline_snapshot.testing._example import Example
@@ -34,3 +37,58 @@
).run_pytest(
["--inline-snapshot=disable"], outcomes={"passed": 2}
)
+
+
+def test_pytester_moved_folder_with_stale_pyc(pytester, monkeypatch):
+ monkeypatch.delenv("PYTEST_XDIST_WORKER", raising=False)
+
+ original = pytester.path / "original"
+ moved = pytester.path / "moved"
+ original.mkdir()
+
+ (original / "test_snapshot.py").write_text(
+ """\
+from inline_snapshot import snapshot
+
+
+def test_snapshot():
+ assert "value" == snapshot()
+""",
+ encoding="utf-8",
+ )
+
+ result = pytester.run(
+ sys.executable,
+ "-m",
+ "pytest",
+ "--inline-snapshot=disable",
+ "-q",
+ str(original),
+ )
+
+ assert result.ret == 1
+
+ shutil.move(original, moved)
+
+ result = pytester.run(
+ sys.executable,
+ "-m",
+ "pytest",
+ "--inline-snapshot=create",
+ "-q",
+ str(moved),
+ )
+
+ assert result.ret == 1
+ result.stdout.fnmatch_lines(["*1 passed*"])
+ result.stderr.no_fnmatch_line("*AssertionError:*")
+
+ result = pytester.run(
+ sys.executable,
+ "-m",
+ "pytest",
+ "--inline-snapshot=disable",
+ "-q",
+ str(moved),
+ )
+ assert result.ret == 0
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/inline_snapshot-0.33.0/tests/test_snapshot_arg.py
new/inline_snapshot-0.34.2/tests/test_snapshot_arg.py
--- old/inline_snapshot-0.33.0/tests/test_snapshot_arg.py 2020-02-02
01:00:00.000000000 +0100
+++ new/inline_snapshot-0.34.2/tests/test_snapshot_arg.py 2020-02-02
01:00:00.000000000 +0100
@@ -57,7 +57,7 @@
check_value(4)
check_value(8,8)
""").run_inline(
- ["--inline-snapshot=fix,create,trim"],
+ ["--inline-snapshot=fix,trim"],
changed_files=snapshot({"tests/test_something.py": """\
from inline_snapshot._snapshot_arg import snapshot_arg
@@ -84,7 +84,7 @@
check_value(4)
check_value(8,expected=8)
""").run_inline(
- ["--inline-snapshot=fix,create,trim"],
+ ["--inline-snapshot=fix,trim"],
changed_files=snapshot({"tests/test_something.py": """\
from inline_snapshot._snapshot_arg import snapshot_arg