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

Make pytest-snapshot closer to kotest #336

Merged
merged 48 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c0f76ed
Port selfie-settings API to pytest.
nedtwigg Apr 17, 2024
f988891
Alphabetize selfie_lib's package init.
nedtwigg Apr 17, 2024
f6a3540
Port mode.
nedtwigg Apr 17, 2024
3725faf
Implement and use `calc_mode`.
nedtwigg Apr 17, 2024
f8ec3e7
Fix circular imports.
nedtwigg Apr 18, 2024
bc88c8d
Structure `PytestSnapshotSystem` to be more similar to kotest.
nedtwigg Apr 18, 2024
a550ad4
Renamed methods to match spec.
nedtwigg Apr 18, 2024
e07be20
Implement more of FS since Python has fewer runtimes than Kotlin.
nedtwigg Apr 18, 2024
5ea8803
Give ArrayMap a `ListBackedSet` to represent its keys
nedtwigg Apr 18, 2024
f92f6ea
Add an `_ArrayMapEntries` class.
nedtwigg Apr 18, 2024
6dade3b
Port `WithinTestGC`.
nedtwigg Apr 18, 2024
81503c0
No reason for a default arg.
nedtwigg Apr 18, 2024
ceece8d
Add the `TodoStub` stuff to literals.
nedtwigg Apr 18, 2024
5a7e069
Move SnapshotFile to be closer to Kotest.
nedtwigg Apr 18, 2024
341c971
Move `DiskSelfie` to be an exact port of Kotlin.
nedtwigg Apr 18, 2024
34702fb
More minor tweaks to SnapshotFile.
nedtwigg Apr 19, 2024
1c155eb
StringSelfie is now an exact match to the Kotln also.
nedtwigg Apr 19, 2024
9035b3e
Minor move-around.
nedtwigg Apr 19, 2024
c7a081e
Make methods private.
nedtwigg Apr 19, 2024
7aa144d
Fix unused import.
nedtwigg Apr 19, 2024
ec61be7
Move the `replace_todo` stuff out of `plugin` into its own file.
nedtwigg Apr 19, 2024
d9fb203
More fixup.
nedtwigg Apr 19, 2024
8e26d4b
Add missing exports from `selfie-lib`.
nedtwigg Apr 20, 2024
950ef66
Missing APIs in selfie-lib.
nedtwigg Apr 20, 2024
6ff5104
Add `AtomicReference`
nedtwigg Apr 20, 2024
1093b82
Adapt `SelfieSettingsAPI` to pytest.
nedtwigg Apr 20, 2024
95d83ff
Major overhaul of the plugin.
nedtwigg Apr 20, 2024
fa8cf45
Fix CamelCase to snake_case.
nedtwigg Apr 20, 2024
ae6e463
Hook for inline snapshot writing.
nedtwigg Apr 20, 2024
933479f
Hook for comment removal.
nedtwigg Apr 20, 2024
a2ef035
plugin with no local type errors
nedtwigg Apr 20, 2024
176b430
Getting close to life.
nedtwigg Apr 20, 2024
2d5e233
FIx more `_snapshots`.
nedtwigg Apr 22, 2024
d8776f0
Finish the hooks.
nedtwigg Apr 22, 2024
cd42b5c
Fix private functions that were getting mangled.
nedtwigg Apr 22, 2024
b5d4d6e
Fix `expect_selfie` assertions.
nedtwigg Apr 22, 2024
2b29229
Give up on running tests using pytester.
nedtwigg Apr 22, 2024
e6dd669
Split `Simple_test` into its pieces.
nedtwigg Apr 22, 2024
ea94c81
Update our GitHub action.
nedtwigg Apr 22, 2024
9c4515a
Fixup the test structure a bit.
nedtwigg Apr 22, 2024
f61ef9e
Do a bit of plumbing for DiskStoragePytest.
nedtwigg Apr 22, 2024
2cc6072
More plumbing.
nedtwigg Apr 22, 2024
a742ad9
Merge branch 'main' into feat/snapshot-system
nedtwigg Apr 23, 2024
db41d40
Update dependency lockfiles.
nedtwigg Apr 23, 2024
e2c6128
More tests.
nedtwigg Apr 23, 2024
b2db9eb
Remove unneeded arg from WriteTracker.
nedtwigg Apr 23, 2024
0626fc1
Filter recordCall to only apply to user code.
nedtwigg Apr 23, 2024
337ed7c
Fix pyright warning.
nedtwigg Apr 23, 2024
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
34 changes: 20 additions & 14 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,35 @@ jobs:
with:
python-version-file: "python/selfie-lib/pyproject.toml"
cache: "poetry"
- run: poetry install
- name: selfie-lib - poetry install
run: poetry install
working-directory: python/selfie-lib
- run: poetry run pytest -vv
- name: selfie-lib - pytest
run: poetry run pytest -vv
working-directory: python/selfie-lib
- run: poetry run pyright
- name: selfie-lib - pyright
run: poetry run pyright
working-directory: python/selfie-lib
- run: poetry run ruff format --check
- name: selfie-lib - ruff
run: poetry run ruff format --check
working-directory: python/selfie-lib
- run: poetry install
- name: pytest-selfie - poetry install
run: poetry install
working-directory: python/pytest-selfie
- run: poetry run pytest -vv
- name: pytest-selfie - pyright
run: poetry run pyright
working-directory: python/pytest-selfie
- run: poetry run tox -e py
- name: pytest-selfie - ruff
run: poetry run ruff format --check
working-directory: python/pytest-selfie
- run: poetry run pyright
working-directory: python/pytest-selfie
- run: poetry run ruff format --check
working-directory: python/pytest-selfie
- run: poetry install
- name: example-pytest-selfie - poetry install
run: poetry install
working-directory: python/example-pytest-selfie
# - run: poetry run pytest -vv
# working-directory: python/example-pytest-selfie
- run: poetry run pyright
- name: example-pytest-selfie - pyright
run: poetry run pyright
working-directory: python/example-pytest-selfie
- run: poetry run ruff format --check
- name: example-pytest-selfie - ruff
run: poetry run ruff format --check
working-directory: python/example-pytest-selfie
12 changes: 6 additions & 6 deletions python/example-pytest-selfie/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 0 additions & 25 deletions python/example-pytest-selfie/tests/Simple_test.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from selfie_lib.Selfie import expect_selfie


def test_comment_removal(): # selfieonce
expect_selfie("no op").to_be("no op")
13 changes: 13 additions & 0 deletions python/example-pytest-selfie/tests/simple_inline_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from selfie_lib.Selfie import expect_selfie


# def test_read_pass():
# expect_selfie("A").to_be("A")


# def test_read_fail():
# expect_selfie("A").to_be("B")


def test_write():
expect_selfie("B").to_be_TODO()
9 changes: 9 additions & 0 deletions python/example-pytest-selfie/tests/simple_ondisk_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from selfie_lib.Selfie import expect_selfie


def test_write():
expect_selfie("A").to_match_disk()


def test_read():
expect_selfie("B").to_match_disk_TODO()
12 changes: 6 additions & 6 deletions python/pytest-selfie/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions python/pytest-selfie/pytest_selfie/SelfieSettingsAPI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
from pathlib import Path
import re
from typing import Optional
from selfie_lib import Mode
import pytest


class SelfieSettingsAPI:
"""API for configuring the selfie plugin, you can set its values like this https://docs.pytest.org/en/7.1.x/reference/customize.html#configuration-file-formats"""

def __init__(self, config: pytest.Config):
self.root_dir = config.rootpath

@property
def allow_multiple_equivalent_writes_to_one_location(self) -> bool:
"""Allow multiple equivalent writes to one location."""
return True

@property
def snapshot_folder_name(self) -> Optional[str]:
"""Defaults to None, which means that snapshots are stored right next to the test that created them."""
return None

@property
def root_folder(self) -> Path:
"""Returns the root folder for storing snapshots. Set by https://docs.pytest.org/en/7.1.x/reference/customize.html#finding-the-rootdir"""
return self.root_dir

def calc_mode(self) -> Mode:
override = os.getenv("selfie") or os.getenv("SELFIE")
if override:
# Convert the mode to lowercase and match it with the Mode enum
try:
return Mode[override.lower()]
except KeyError:
raise ValueError(f"No such mode: {override}")

ci = os.getenv("ci") or os.getenv("CI")
if ci and ci.lower() == "true":
return Mode.readonly
else:
return Mode.interactive


class SelfieSettingsSmuggleError(SelfieSettingsAPI):
def __init__(self, error: BaseException):
self.error = error
1 change: 1 addition & 0 deletions python/pytest-selfie/pytest_selfie/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .SelfieSettingsAPI import SelfieSettingsAPI as SelfieSettingsAPI
Loading