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

Run mypy on tests #43

Merged
merged 7 commits into from
Aug 14, 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ lint: $(VENV)/pyvenv.cfg
. $(VENV_BIN)/activate && \
ruff format --check $(ALL_PY_SRCS) && \
ruff check $(ALL_PY_SRCS) && \
mypy
mypy src/ test/
. $(VENV_BIN)/activate && \
interrogate -c pyproject.toml .

Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ lint = [
"types-requests",
"types-toml",
"interrogate",
# linting relies on test deps, since we also typecheck our test suite
"pypi-attestations[test]",
]
dev = ["pypi-attestations[doc,test,lint]", "twine", "wheel", "build"]
dev = ["pypi-attestations[doc,test,lint]", "build"]


[project.urls]
Expand All @@ -54,6 +56,7 @@ omit = ["src/pypi_attestations/_cli.py", "src/pypi_attestations/__main__.py"]
[tool.mypy]
mypy_path = "src"
packages = "pypi_attestations"
plugins = ["pydantic.mypy"]
allow_redefinition = true
check_untyped_defs = true
disallow_incomplete_defs = true
Expand Down Expand Up @@ -88,6 +91,7 @@ ignore = ["ANN101", "ANN102", "D203", "D213", "COM812", "ISC001"]
"D", # no docstrings in tests
"S101", # asserts are expected in tests
"SLF001", # private APIs are expected in tests
"ANN401", # dynamic types are OK in tests
]

[tool.interrogate]
Expand Down
11 changes: 6 additions & 5 deletions test/test_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
from hashlib import sha256
from pathlib import Path
from typing import Any

import pretend
import pypi_attestations._impl as impl
Expand Down Expand Up @@ -75,7 +76,7 @@ def test_roundtrip(self, id_token: IdentityToken) -> None:
def test_wrong_predicate_raises_exception(self, monkeypatch: pytest.MonkeyPatch) -> None:
def dummy_predicate(self_: StatementBuilder, _: str) -> StatementBuilder:
# wrong type here to have a validation error
self_._predicate_type = False
self_._predicate_type = False # type: ignore[assignment]
return self_

monkeypatch.setattr(sigstore.dsse.StatementBuilder, "predicate_type", dummy_predicate)
Expand All @@ -100,7 +101,7 @@ def in_validity_period(_: IdentityToken) -> bool:
def test_multiple_signatures(
self, id_token: IdentityToken, monkeypatch: pytest.MonkeyPatch
) -> None:
def get_bundle(*_) -> Bundle: # noqa: ANN002
def get_bundle(*_: Any) -> Bundle:
# Duplicate the signature to trigger a Conversion error
bundle = Bundle.from_json(gh_signed_dist_bundle_path.read_bytes())
bundle._inner.dsse_envelope.signatures.append(bundle._inner.dsse_envelope.signatures[0])
Expand Down Expand Up @@ -468,15 +469,15 @@ def test_ultranormalize_dist_filename_invalid(input: str) -> None:
class TestPublisher:
def test_discriminator(self) -> None:
gh_raw = {"kind": "GitHub", "repository": "foo/bar", "workflow": "publish.yml"}
gh = TypeAdapter(impl.Publisher).validate_python(gh_raw)
gh: impl.Publisher = TypeAdapter(impl.Publisher).validate_python(gh_raw)

assert isinstance(gh, impl.GitHubPublisher)
assert gh.repository == "foo/bar"
assert gh.workflow == "publish.yml"
assert TypeAdapter(impl.Publisher).validate_json(json.dumps(gh_raw)) == gh

gl_raw = {"kind": "GitLab", "repository": "foo/bar/baz", "environment": "publish"}
gl = TypeAdapter(impl.Publisher).validate_python(gl_raw)
gl: impl.Publisher = TypeAdapter(impl.Publisher).validate_python(gl_raw)
assert isinstance(gl, impl.GitLabPublisher)
assert gl.repository == "foo/bar/baz"
assert gl.environment == "publish"
Expand All @@ -499,7 +500,7 @@ def test_claims(self) -> None:
"this-too": 123,
},
}
pub = TypeAdapter(impl.Publisher).validate_python(raw)
pub: impl.Publisher = TypeAdapter(impl.Publisher).validate_python(raw)

assert pub.claims == {
"this": "is-preserved",
Expand Down