Skip to content

Commit

Permalink
fix: include int, more coverage in testing
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Nov 28, 2023
1 parent 9c31493 commit 454c86b
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/validate_pyproject/formats.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import builtins
import logging
import os
import re
Expand Down Expand Up @@ -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
37 changes: 37 additions & 0 deletions tests/examples/ruff/modern.toml
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 5 additions & 0 deletions tests/examples/ruff/test_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tools": {
"ruff": "https://json.schemastore.org/ruff.json"
}
}
1 change: 1 addition & 0 deletions tests/invalid-examples/ruff/badcode.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`tool.ruff.lint` cannot be validated by any definition
2 changes: 2 additions & 0 deletions tests/invalid-examples/ruff/badcode.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.ruff.lint]
extend-select = ["NOTACODE"]
5 changes: 5 additions & 0 deletions tests/invalid-examples/ruff/test_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tools": {
"ruff": "https://json.schemastore.org/ruff.json"
}
}
1 change: 1 addition & 0 deletions tests/invalid-examples/ruff/unknown.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`tool.ruff` must not contain {'not-a-real-option'} properties
2 changes: 2 additions & 0 deletions tests/invalid-examples/ruff/unknown.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.ruff]
not-a-real-option = true
8 changes: 8 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down

0 comments on commit 454c86b

Please sign in to comment.