-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate test models to reusable test fixtures (#218)
Since we will be writing different routines for testing, it is better to use the same test "models" in testing, so let's reuse the same code. Signed-off-by: Mihai Maruseac <mihaimaruseac@google.com>
- Loading branch information
1 parent
6808ad9
commit 96e52b4
Showing
3 changed files
with
124 additions
and
75 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
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,77 @@ | ||
# Copyright 2024 The Sigstore Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Test fixtures to share between tests. Not part of the public API.""" | ||
|
||
import pytest | ||
|
||
from model_signing.serialization import fixtures_constants | ||
|
||
|
||
# Note: Don't make fixtures with global scope as we are altering the models! | ||
@pytest.fixture | ||
def sample_model_file(tmp_path_factory): | ||
file = tmp_path_factory.mktemp("model") / "file" | ||
file.write_bytes(fixtures_constants.KNOWN_MODEL_TEXT) | ||
return file | ||
|
||
|
||
@pytest.fixture | ||
def empty_model_file(tmp_path_factory): | ||
file = tmp_path_factory.mktemp("model") / "file" | ||
file.write_bytes(b"") | ||
return file | ||
|
||
|
||
@pytest.fixture | ||
def sample_model_folder(tmp_path_factory): | ||
model_root = tmp_path_factory.mktemp("model") / "root" | ||
model_root.mkdir() | ||
|
||
for i in range(2): | ||
root_dir = model_root / f"d{i}" | ||
root_dir.mkdir() | ||
for j in range(3): | ||
dir_file = root_dir / f"f{i}{j}" | ||
dir_file.write_text(f"This is file f{i}{j} in d{i}.") | ||
|
||
for i in range(4): | ||
root_file = model_root / f"f{i}" | ||
root_file.write_text(f"This is file f{i} in root.") | ||
|
||
return model_root | ||
|
||
|
||
@pytest.fixture | ||
def empty_model_folder(tmp_path_factory): | ||
model_root = tmp_path_factory.mktemp("model") / "root" | ||
model_root.mkdir() | ||
return model_root | ||
|
||
|
||
@pytest.fixture | ||
def deep_model_folder(tmp_path_factory): | ||
model_root = tmp_path_factory.mktemp("model") / "root" | ||
model_root.mkdir() | ||
|
||
current = model_root | ||
for i in range(5): | ||
current = current / f"d{i}" | ||
current.mkdir() | ||
|
||
for i in range(4): | ||
file = current / f"f{i}" | ||
file.write_text(f"This is file f{i}.") | ||
|
||
return model_root |
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,18 @@ | ||
# Copyright 2024 The Sigstore Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Constants used in test fixtures and tests. Not part of the public API.""" | ||
|
||
KNOWN_MODEL_TEXT: bytes = b"This is a simple model" | ||
ANOTHER_MODEL_TEXT: bytes = b"This is another simple model" |