Skip to content

Commit

Permalink
Run mypy in strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Jul 18, 2023
1 parent 992b94f commit 956506a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
# Python type checking
mypy = {
attrs.nativeBuildInputs = [ pythonEnv ];
check = "mypy .";
check = "mypy --strict .";
};

# Python linter
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dev = [
"pytest-parallel>=0.1.1",
"black>=23.7.0",
"mypy>=1.4.1",
"pytest-watch>=4.2.0",
]

[tool.black]
Expand Down
16 changes: 7 additions & 9 deletions tests/test_nix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
import subprocess
from typing import (
Any,
Dict,
Iterator,
List,
Optional,
Set,
cast,
)

import pytest
Expand All @@ -17,8 +15,8 @@ def assert_deepequals(
a: Any,
b: Any,
ignore_paths: Optional[Set[str]] = None,
_path: Optional[tuple[str]] = None,
):
_path: Optional[tuple[str, ...]] = None,
) -> None:
"""Compare objects a and b keeping track of object path for error reporting.
Keyword arguments:
Expand All @@ -38,13 +36,13 @@ def assert_deepequals(
}, ignore_paths=set(["metadata.poetry-version"]))
"""

_path = cast(tuple[str], (_path if _path else ()))
_path = _path if _path else ()
ignore_paths = ignore_paths if ignore_paths else set()
path = ".".join(_path)
err = ValueError("{}: {} != {}".format(path, a, b))

def make_path(entry):
return (*_path, str(entry))
def make_path(entry: Any) -> tuple[str, ...]:
return (*_path, str(entry)) # type: ignore:misc

if isinstance(a, list):
if not isinstance(b, list) or len(a) != len(b):
Expand All @@ -71,7 +69,7 @@ def make_path(entry):
raise err


def nix_eval(attr: str) -> Dict:
def nix_eval(attr: str) -> Any:
cmd: List[str] = [
"nix-instantiate",
"--eval",
Expand Down Expand Up @@ -111,7 +109,7 @@ def gen_checks() -> Iterator[str]:


@pytest.mark.parametrize("check", gen_checks())
def test_attrs(check) -> None:
def test_attrs(check: str) -> None:
"""Automatically generate pytest tests from Nix attribute set"""
result = nix_eval(f"tests.{check}")
assert_deepequals(result["output"], result["expected"])

0 comments on commit 956506a

Please sign in to comment.