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

Container #121

Merged
merged 14 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions .github/workflows/deploy_development_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: deploy development docs
on:
push:
branches: [main]

jobs:
build:
name: Deploy development docs
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- run: pip install hatch
- name: publish docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "Frank Hoffmann"
git config user.email "[email protected]"
git fetch origin gh-pages --depth=1
hatch run docs:mike deploy --push development
11 changes: 2 additions & 9 deletions .github/workflows/test_docs.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: test docs
on:
pull_request:
push:
branches: [main]

jobs:
build:
Expand All @@ -13,11 +11,6 @@ jobs:
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- run: pip install hatch
- name: publish docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: test docs
run: |
git config user.name "Frank Hoffmann"
git config user.email "[email protected]"
git fetch origin gh-pages --depth=1
hatch run docs:mike deploy --push development
hatch run docs:build
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ pip install inline-snapshot
## Key Features

- **Intuitive Semantics:** `snapshot(x)` mirrors `x` for easy understanding.
- **Versatile Comparison Support:** Equipped with `x == snapshot(...)`, `x <= snapshot(...)`, `x in snapshot(...)`, and `snapshot(...)[key]`.
- **Versatile Comparison Support:** Equipped with
[`x == snapshot(...)`](https://15r10nk.github.io/inline-snapshot/latest/eq_snapshot/),
[`x <= snapshot(...)`](https://15r10nk.github.io/inline-snapshot/latest/cmp_snapshot/),
[`x in snapshot(...)`](https://15r10nk.github.io/inline-snapshot/latest/in_snapshot/), and
[`snapshot(...)[key]`](https://15r10nk.github.io/inline-snapshot/latest/getitem_snapshot/).
- **Enhanced Control Flags:** Utilize various [flags](https://15r10nk.github.io/inline-snapshot/latest/pytest/) for precise control of which snapshots you want to change.
- **Preserved Black Formatting:** Retains formatting consistency with Black formatting.
- **External File Storage:** Store snapshots externally using `outsource(data)`.
- **Seamless Pytest Integration:** Integrated seamlessly with pytest for effortless testing.
- **Customizable:** code generation can be customized with [@customize_repr](https://15r10nk.github.io/inline-snapshot/latest/customize_repr)
- **Nested Snapshot Support:** snapshots can contain [other snapshots](https://15r10nk.github.io/inline-snapshot/eq_snapshot/#inner-snapshots)
- **Fuzzy Matching:** Incorporate [dirty-equals](https://15r10nk.github.io/inline-snapshot/eq_snapshot/#dirty-equals) for flexible comparisons within snapshots.
- **Dynamic Snapshot Content:** snashots can contain [non-constant values](https://15r10nk.github.io/inline-snapshot/eq_snapshot/#is)
- **Comprehensive Documentation:** Access detailed [documentation](https://15r10nk.github.io/inline-snapshot/latest) for complete guidance.


Expand Down
38 changes: 38 additions & 0 deletions changelog.d/20241113_170718_15r10nk-git_fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Removed

- A bullet item for the Removed category.

-->
### Fixed

- inline-snapshot checks now if the given command line flags (`--inline-snapshot=...`) are valid

<!--

- A bullet item for the Changed category.

-->
<!--
### Deprecated

- A bullet item for the Deprecated category.

-->
<!--

- A bullet item for the Fixed category.

-->
<!--
### Security

- A bullet item for the Security category.

-->
39 changes: 39 additions & 0 deletions changelog.d/20241113_170944_15r10nk-git_fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Removed

- A bullet item for the Removed category.

-->
<!--
### Added

- A bullet item for the Added category.

-->
<!--
### Changed

- A bullet item for the Changed category.

-->
<!--
### Deprecated

- A bullet item for the Deprecated category.

-->
### Fixed
- `Example(...).run_pytest(raise=snapshot(...))` uses now the flags from the current run and not the flags from the Example.

<!--
### Security

- A bullet item for the Security category.

-->
62 changes: 62 additions & 0 deletions changelog.d/20241210_063450_15r10nk-git_container.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Removed

- A bullet item for the Removed category.

-->
### Added

- snapshots [inside snapshots](https://15r10nk.github.io/inline-snapshot/latest/eq_snapshot/#inner-snapshots) are now supported.

``` python
assert get_schema() == snapshot(
[
{
"name": "var_1",
"type": snapshot("int") if version < 2 else snapshot("string"),
}
]
)
```

- [runtime values](https://15r10nk.github.io/inline-snapshot/latest/eq_snapshot/#is) can now be part of snapshots.

``` python
from inline_snapshot import snapshot, Is

current_version = "1.5"
assert request() == snapshot(
{"data": "page data", "version": Is(current_version)}
)
```

- [f-strings](https://15r10nk.github.io/inline-snapshot/latest/eq_snapshot/#f-strings) can now also be used within snapshots, but are currently not *fixed* by inline-snapshot.

### Changed

- *dirty-equals* expressions are now treated like *runtime values* or *snapshots* within snapshots and are not modified by inline-snapshot.

<!--
### Deprecated

- A bullet item for the Deprecated category.

-->
<!--
### Fixed

- A bullet item for the Fixed category.

-->
<!--
### Security

- A bullet item for the Security category.

-->
22 changes: 14 additions & 8 deletions docs/customize_repr.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

`repr()` can be used to convert a python object into a source code representation of the object, but this does not work for every type.
Here are some examples:

```pycon
>>> repr(int)
"<class 'int'>"
Expand Down Expand Up @@ -42,7 +43,7 @@ def test_enum():

inline-snapshot comes with a special implementation for the following types:

```python exec="1"
``` python exec="1"
from inline_snapshot._code_repr import code_repr_dispatch, code_repr

for name, obj in sorted(
Expand All @@ -58,16 +59,14 @@ for name, obj in sorted(
print(f"- `{name}`")
```

Container types like `dict` or `dataclass` need a special implementation because it is necessary that the implementation uses `repr()` for the child elements.
!!! note
Container types like `dict`, `list`, `tuple` or `dataclass` are handled in a different way, because inline-snapshot also needs to inspect these types to implement [unmanaged](/eq_snapshot.md#unmanaged-snapshot-values) snapshot values.



```python exec="1" result="python"
print('--8<-- "src/inline_snapshot/_code_repr.py:list"')
```

!!! note
using `#!python f"{obj!r}"` or `#!c PyObject_Repr()` will not work, because inline-snapshot replaces `#!python builtins.repr` during the code generation.

## customize
## customize recursive repr

You can also use `repr()` inside `__repr__()`, if you want to make your own type compatible with inline-snapshot.

Expand Down Expand Up @@ -102,6 +101,13 @@ def test_enum():
assert Pair(E.a, [E.b]) == snapshot(Pair(E.a, [E.b]))
```

!!! note
using `#!python f"{obj!r}"` or `#!c PyObject_Repr()` will not work, because inline-snapshot replaces `#!python builtins.repr` during the code generation. The only way to use the custom repr implementation is to use the `repr()` function.

!!! note
This implementation allows inline-snapshot to use the custom `repr()` recursively, but it does not allow you to use [unmanaged](/eq_snapshot.md#unmanaged-snapshot-parts) snapshot values like `#!python Pair(Is(some_var),5)`


you can also customize the representation of datatypes in other libraries:

``` python
Expand Down
Loading
Loading