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

Migrate tests for model serialization to goldens. #244

Merged
merged 1 commit into from
Jul 22, 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
27 changes: 27 additions & 0 deletions model_signing/serialization/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,36 @@
from model_signing.serialization import test_support


def pytest_addoption(parser):
"""Adds a flag argument to update the goldens."""
parser.addoption(
"--update_goldens",
action="store_true",
default=False,
help="update golden files",
)


# Note: Don't make fixtures with global scope as we are altering the models!
@pytest.fixture
def sample_model_file(tmp_path_factory):
"""A model with just a single file."""
file = tmp_path_factory.mktemp("model") / "file"
file.write_bytes(test_support.KNOWN_MODEL_TEXT)
return file


@pytest.fixture
def empty_model_file(tmp_path_factory):
"""A model with just an empty file."""
file = tmp_path_factory.mktemp("model") / "file"
file.write_bytes(b"")
return file


@pytest.fixture
def sample_model_folder(tmp_path_factory):
"""A model with multiple files and directories."""
model_root = tmp_path_factory.mktemp("model") / "root"
model_root.mkdir()

Expand All @@ -55,13 +68,27 @@ def sample_model_folder(tmp_path_factory):

@pytest.fixture
def empty_model_folder(tmp_path_factory):
"""A model with just an empty directory."""
model_root = tmp_path_factory.mktemp("model") / "root"
model_root.mkdir()
return model_root


@pytest.fixture
def model_folder_with_empty_file(tmp_path_factory):
"""A model with just an empty file, inside a directory."""
model_root = tmp_path_factory.mktemp("model") / "root"
model_root.mkdir()

empty_file = model_root / "empty_file"
empty_file.write_bytes(b"")

return model_root


@pytest.fixture
def deep_model_folder(tmp_path_factory):
"""A model with a deep directory hierarchy."""
model_root = tmp_path_factory.mktemp("model") / "root"
model_root.mkdir()

Expand Down
Loading
Loading