-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make pytest-snapshot closer to kotest (#336)
- Loading branch information
Showing
30 changed files
with
1,290 additions
and
524 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
python/example-pytest-selfie/tests/simple_comment_removal_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .SelfieSettingsAPI import SelfieSettingsAPI as SelfieSettingsAPI |
Oops, something went wrong.