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

some fixes #136

Merged
merged 4 commits into from
Nov 13, 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 "15r10nk@users.noreply.github.com"
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 "15r10nk@users.noreply.github.com"
git fetch origin gh-pages --depth=1
hatch run docs:mike deploy --push development
hatch run docs:build
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.

-->
6 changes: 6 additions & 0 deletions src/inline_snapshot/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def pytest_configure(config):
f"--inline-snapshot={','.join(flags)} can not be combined with xdist"
)

unknown_flags = flags - categories - {"disable", "review", "report", "short-report"}
if unknown_flags:
raise pytest.UsageError(
f"--inline-snapshot={','.join(sorted(unknown_flags))} is a unknown flag"
)

if "disable" in flags and flags != {"disable"}:
raise pytest.UsageError(
f"--inline-snapshot=disable can not be combined with other flags ({', '.join(flags-{'disable'})})"
Expand Down
13 changes: 12 additions & 1 deletion src/inline_snapshot/testing/_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def run_inline(

self._write_files(tmp_path)

raised_exception = None
with snapshot_env():
with ChangeRecorder().activate() as recorder:
_inline_snapshot._update_flags = Flags({*flags})
Expand All @@ -160,7 +161,7 @@ def run_inline(
if k.startswith("test_") and callable(v):
v()
except Exception as e:
assert raises == f"{type(e).__name__}:\n" + str(e)
raised_exception = e

finally:
_inline_snapshot._active = False
Expand All @@ -182,6 +183,11 @@ def run_inline(
if reported_categories is not None:
assert sorted(snapshot_flags) == reported_categories

if raised_exception is not None:
assert raises == f"{type(raised_exception).__name__}:\n" + str(
raised_exception
)

recorder.fix_all()

if changed_files is not None:
Expand All @@ -201,6 +207,7 @@ def run_pytest(
env: dict[str, str] = {},
changed_files: Snapshot[dict[str, str]] | None = None,
report: Snapshot[str] | None = None,
stderr: Snapshot[str] | None = None,
returncode: Snapshot[int] | None = None,
) -> Example:
"""Run pytest with the given args and env variables in an seperate
Expand All @@ -213,6 +220,7 @@ def run_pytest(
env: dict of environment variables
changed_files: snapshot of files which are changed by this run.
report: snapshot of the report at the end of the pytest run.
stderr: pytest stderr output
returncode: snapshot of the pytest returncode.

Returns:
Expand Down Expand Up @@ -247,6 +255,9 @@ def run_pytest(
if returncode is not None:
assert result.returncode == returncode

if stderr is not None:
assert result.stderr.decode() == stderr

if report is not None:

report_list = []
Expand Down
34 changes: 34 additions & 0 deletions tests/test_code_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,37 @@ def __repr__(self):
return "FakeTuple()"

assert code_repr(FakeTuple()) == snapshot("FakeTuple()")


def test_invalid_repr(check_update):
assert (
check_update(
"""\
class Thing:
def __repr__(self):
return "+++"

def __eq__(self,other):
if not isinstance(other,Thing):
return NotImplemented
return True

assert Thing() == snapshot()
""",
flags="create",
)
== snapshot(
"""\
class Thing:
def __repr__(self):
return "+++"

def __eq__(self,other):
if not isinstance(other,Thing):
return NotImplemented
return True

assert Thing() == snapshot(HasRepr(Thing, "+++"))
"""
)
)
Loading