From 454c86b96395feed57ec83349d1b4e3d47d842b2 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 28 Nov 2023 12:01:53 -0500 Subject: [PATCH] fix: include int, more coverage in testing Signed-off-by: Henry Schreiner --- src/validate_pyproject/formats.py | 11 ++++-- tests/examples/ruff/modern.toml | 37 +++++++++++++++++++ tests/examples/ruff/test_config.json | 5 +++ .../invalid-examples/ruff/badcode.errors.txt | 1 + tests/invalid-examples/ruff/badcode.toml | 2 + tests/invalid-examples/ruff/test_config.json | 5 +++ .../invalid-examples/ruff/unknown.errors.txt | 1 + tests/invalid-examples/ruff/unknown.toml | 2 + tests/test_cli.py | 8 ++++ 9 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 tests/examples/ruff/modern.toml create mode 100644 tests/examples/ruff/test_config.json create mode 100644 tests/invalid-examples/ruff/badcode.errors.txt create mode 100644 tests/invalid-examples/ruff/badcode.toml create mode 100644 tests/invalid-examples/ruff/test_config.json create mode 100644 tests/invalid-examples/ruff/unknown.errors.txt create mode 100644 tests/invalid-examples/ruff/unknown.toml diff --git a/src/validate_pyproject/formats.py b/src/validate_pyproject/formats.py index 7e47e0f..a79d2c5 100644 --- a/src/validate_pyproject/formats.py +++ b/src/validate_pyproject/formats.py @@ -1,3 +1,4 @@ +import builtins import logging import os import re @@ -275,13 +276,17 @@ def python_entrypoint_reference(value: str) -> bool: return all(python_identifier(i.strip()) for i in identifiers) -def uint8(value: int) -> bool: +def uint8(value: builtins.int) -> bool: return 0 <= value < 2**8 -def uint16(value: int) -> bool: +def uint16(value: builtins.int) -> bool: return 0 <= value < 2**16 -def uint(value: int) -> bool: +def uint(value: builtins.int) -> bool: return 0 <= value < 2**64 + + +def int(value: builtins.int) -> bool: + return -(2**63) <= value < 2**63 diff --git a/tests/examples/ruff/modern.toml b/tests/examples/ruff/modern.toml new file mode 100644 index 0000000..7b84ee5 --- /dev/null +++ b/tests/examples/ruff/modern.toml @@ -0,0 +1,37 @@ +[tool.ruff] +src = ["src"] + +[tool.ruff.lint] +extend-select = [ + "B", # flake8-bugbear + "I", # isort + "ARG", # flake8-unused-arguments + "C4", # flake8-comprehensions + "EM", # flake8-errmsg + "ICN", # flake8-import-conventions + "G", # flake8-logging-format + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # pylint + "PT", # flake8-pytest-style + "PTH", # flake8-use-pathlib + "RET", # flake8-return + "RUF", # Ruff-specific + "SIM", # flake8-simplify + "T20", # flake8-print + "UP", # pyupgrade + "YTT", # flake8-2020 + "EXE", # flake8-executable + "NPY", # NumPy specific rules + "PD", # pandas-vet + "FURB", # refurb + "PYI", # flake8-pyi +] +ignore = [ + "PLR", # Design related pylint codes +] +typing-modules = ["mypackage._compat.typing"] +isort.required-imports = ["from __future__ import annotations"] + +[tool.ruff.lint.per-file-ignores] +"tests/**" = ["T20"] diff --git a/tests/examples/ruff/test_config.json b/tests/examples/ruff/test_config.json new file mode 100644 index 0000000..177306a --- /dev/null +++ b/tests/examples/ruff/test_config.json @@ -0,0 +1,5 @@ +{ + "tools": { + "ruff": "https://json.schemastore.org/ruff.json" + } +} diff --git a/tests/invalid-examples/ruff/badcode.errors.txt b/tests/invalid-examples/ruff/badcode.errors.txt new file mode 100644 index 0000000..3afc976 --- /dev/null +++ b/tests/invalid-examples/ruff/badcode.errors.txt @@ -0,0 +1 @@ +`tool.ruff.lint` cannot be validated by any definition diff --git a/tests/invalid-examples/ruff/badcode.toml b/tests/invalid-examples/ruff/badcode.toml new file mode 100644 index 0000000..c90ea9c --- /dev/null +++ b/tests/invalid-examples/ruff/badcode.toml @@ -0,0 +1,2 @@ +[tool.ruff.lint] +extend-select = ["NOTACODE"] diff --git a/tests/invalid-examples/ruff/test_config.json b/tests/invalid-examples/ruff/test_config.json new file mode 100644 index 0000000..177306a --- /dev/null +++ b/tests/invalid-examples/ruff/test_config.json @@ -0,0 +1,5 @@ +{ + "tools": { + "ruff": "https://json.schemastore.org/ruff.json" + } +} diff --git a/tests/invalid-examples/ruff/unknown.errors.txt b/tests/invalid-examples/ruff/unknown.errors.txt new file mode 100644 index 0000000..6ddedd4 --- /dev/null +++ b/tests/invalid-examples/ruff/unknown.errors.txt @@ -0,0 +1 @@ +`tool.ruff` must not contain {'not-a-real-option'} properties diff --git a/tests/invalid-examples/ruff/unknown.toml b/tests/invalid-examples/ruff/unknown.toml new file mode 100644 index 0000000..d63119d --- /dev/null +++ b/tests/invalid-examples/ruff/unknown.toml @@ -0,0 +1,2 @@ +[tool.ruff] +not-a-real-option = true diff --git a/tests/test_cli.py b/tests/test_cli.py index 7a73abf..7fd30f3 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -190,6 +190,14 @@ def test_missing_toolname(tmp_path, capsys): cli.run(["--tool=http://json.schemastore.org/poetry.toml", str(example)]) +def test_bad_url(tmp_path, capsys): + example = write_example(tmp_path, name="valid-pyproject.toml") + with pytest.raises(ValueError, match="URL must start with 'http:' or 'https:'"): + cli.run( + ["--tool", "poetry=file://json.schemastore.org/poetry.toml", str(example)] + ) + + @pytest.mark.skipif(sys.version_info[:2] < (3, 11), reason="requires 3.11+") def test_parser_is_tomllib(): """Make sure Python >= 3.11 uses tomllib instead of tomli"""