Skip to content

Commit

Permalink
enable flake8-pytest-style linter (#281)
Browse files Browse the repository at this point in the history
* enable flake8-pytest-style linter

Signed-off-by: Spencer Schrock <sschrock@google.com>

* fix broad exception matching

Signed-off-by: Spencer Schrock <sschrock@google.com>

---------

Signed-off-by: Spencer Schrock <sschrock@google.com>
  • Loading branch information
spencerschrock authored Aug 12, 2024
1 parent 22f4071 commit 7429f1e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
pip install -r model_signing/install/requirements_test_Linux.txt
pip install -r model_signing/install/requirements_dev_Linux.txt
# TODO: https://github.com/sigstore/model-transparency/issues/231 - Support all repo
pytype --keep-going model_signing/{hashing,manifest,serialization,signature,signing}
pytype --keep-going model_signing/{conftest.py,hashing,manifest,serialization,signature,signing}
ruff-lint:
runs-on: ubuntu-latest
Expand All @@ -86,4 +86,4 @@ jobs:
pip install -r model_signing/install/requirements_test_Linux.txt
pip install -r model_signing/install/requirements_dev_Linux.txt
# TODO: https://github.com/sigstore/model-transparency/issues/231 - Support all repo
ruff check model_signing/{hashing,manifest,serialization,signature,signing}
ruff check model_signing/{conftest.py,hashing,manifest,serialization,signature,signing}
5 changes: 4 additions & 1 deletion model_signing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import os
import pathlib

import pytest

from model_signing import test_support
Expand Down Expand Up @@ -106,7 +107,9 @@ def deep_model_folder(tmp_path_factory):
return model_root

@pytest.fixture
def symlink_model_folder(tmp_path_factory: pytest.TempPathFactory) -> pathlib.Path:
def symlink_model_folder(
tmp_path_factory: pytest.TempPathFactory
) -> pathlib.Path:
"""A model folder with a symlink to an external file."""
external_file = tmp_path_factory.mktemp("external") / "file"
external_file.write_bytes(test_support.KNOWN_MODEL_TEXT)
Expand Down
5 changes: 4 additions & 1 deletion model_signing/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ line-length = 80
target-version = "py311"

[tool.ruff.lint]
select = ["B", "E", "F", "I", "N", "PLC", "PLE", "SIM", "W"]
select = ["B", "E", "F", "I", "N", "PLC", "PLE", "PT", "SIM", "W"]
ignore = ["B024"]

[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false

[tool.ruff.lint.isort]
force-single-line = true
force-sort-within-sections = true
Expand Down
8 changes: 6 additions & 2 deletions model_signing/serialization/serialize_by_file_shard_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ def test_symlinks_disallowed_by_default(self, symlink_model_folder):
serializer = serialize_by_file_shard.DigestSerializer(
self._hasher_factory, memory.SHA256()
)
with pytest.raises(ValueError):
with pytest.raises(
ValueError, match="Cannot use '.+' because it is a symlink."
):
_ = serializer.serialize(symlink_model_folder)

def test_ignore_list_respects_directories(self, sample_model_folder):
Expand Down Expand Up @@ -679,7 +681,9 @@ def test_symlinks_disallowed_by_default(self, symlink_model_folder):
serializer = serialize_by_file_shard.ManifestSerializer(
self._hasher_factory
)
with pytest.raises(ValueError):
with pytest.raises(
ValueError, match="Cannot use '.+' because it is a symlink."
):
_ = serializer.serialize(symlink_model_folder)

def test_shard_to_string(self):
Expand Down
8 changes: 6 additions & 2 deletions model_signing/serialization/serialize_by_file_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ def test_symlinks_disallowed_by_default(self, symlink_model_folder):
serializer = serialize_by_file.DigestSerializer(
file_hasher, memory.SHA256
)
with pytest.raises(ValueError):
with pytest.raises(
ValueError, match="Cannot use '.+' because it is a symlink."
):
_ = serializer.serialize(symlink_model_folder)

def test_ignore_list_respects_directories(self, sample_model_folder):
Expand Down Expand Up @@ -565,7 +567,9 @@ def test_max_workers_does_not_change_digest(self, sample_model_folder):

def test_symlinks_disallowed_by_default(self, symlink_model_folder):
serializer = serialize_by_file.ManifestSerializer(self._hasher_factory)
with pytest.raises(ValueError):
with pytest.raises(
ValueError, match="Cannot use '.+' because it is a symlink."
):
_ = serializer.serialize(symlink_model_folder)

def test_ignore_list_respects_directories(self, sample_model_folder):
Expand Down

0 comments on commit 7429f1e

Please sign in to comment.