Merge pull request 'AURORA-1677: поправил тесты, ruff и mypy' (#1) from statements-library-packaging-checks into main

Reviewed-on: #1
This commit is contained in:
tsygankoviva 2026-10-26 18:12:52 +03:00
commit d64d2a885b
7 changed files with 72 additions and 24 deletions

View File

@ -16,7 +16,7 @@ install: ## Установить или переустановить библи
lint: ## ruff check, ruff format --check, mypy lint: ## ruff check, ruff format --check, mypy
$(BIN)/ruff check . $(BIN)/ruff check .
$(BIN)/ruff format --check . $(BIN)/ruff format --check .
$(BIN)/mypy pylib_ai_arm_statements $(BIN)/mypy arm_statements
test: ## pytest test: ## pytest
$(BIN)/pytest $(BIN)/pytest

View File

@ -6,7 +6,7 @@ target-version = "py311"
select = ["E", "F", "I", "UP", "B", "PL"] select = ["E", "F", "I", "UP", "B", "PL"]
[tool.ruff.lint.isort] [tool.ruff.lint.isort]
known-first-party = ["pylib_ai_arm_statements"] known-first-party = ["arm_statements"]
[tool.mypy] [tool.mypy]
python_version = "3.11" python_version = "3.11"

View File

@ -1,6 +1,3 @@
pandas>=2.0.0
numpy>=1.24.0
build>=0.10.0 build>=0.10.0
twine>=4.0.0 twine>=4.0.0
ruff==0.16.10 ruff==0.16.10

View File

@ -1,4 +1,2 @@
# Пример зависимостей для работы с данными # Пример зависимостей для работы с данными
pandas>=2.0.0
numpy>=1.24.0
PyYAML==6.0.3 PyYAML==6.0.3

View File

@ -1,31 +1,31 @@
from setuptools import setup, find_packages
import os import os
from setuptools import find_packages, setup
version_file = os.path.join(os.path.dirname(__file__), 'VERSION') version_file = os.path.join(os.path.dirname(__file__), "VERSION")
with open(version_file, 'r') as f: with open(version_file) as f:
version = f.read().strip() version = f.read().strip()
with open('requirements.txt') as f: with open("requirements.txt") as f:
requirements = [line.strip() for line in f if line.strip() and not line.startswith('#')] requirements = [line.strip() for line in f if line.strip() and not line.startswith("#")]
with open('README.md', encoding='utf-8') as f: with open("README.md", encoding="utf-8") as f:
long_description = f.read() long_description = f.read()
setup( setup(
name="pylib-ai-arm-statements", name="pylib-ai-arm-statements",
version=version, version=version,
author='tsygankov-iva', author="tsygankov-iva",
description='Библиотека нормализации форм ББ/ОФР для ДКБ АРМКА', description="Библиотека нормализации форм ББ/ОФР для ДКБ АРМКА",
long_description=long_description, long_description=long_description,
long_description_content_type='text/markdown', long_description_content_type="text/markdown",
packages=find_packages(exclude=['tests', 'tests.*']), packages=find_packages(exclude=["tests", "tests.*"]),
install_requires=requirements, install_requires=requirements,
python_requires='>=3.10', python_requires=">=3.11",
classifiers=[ classifiers=[
'Development Status :: 3 - Alpha', "Development Status :: 3 - Alpha",
'Intended Audience :: Developers', "Intended Audience :: Developers",
'Programming Language :: Python :: 3.10', # 'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11', "Programming Language :: Python :: 3.11",
], ],
) )

View File

@ -9,7 +9,7 @@ from arm_statements.issues import WarningCode, make_warning
from arm_statements.loader import LABEL_KEYS, Rules, RulesError, load_rules from arm_statements.loader import LABEL_KEYS, Rules, RulesError, load_rules
from arm_statements.model import DocumentType, Edition, FormVariant, Severity from arm_statements.model import DocumentType, Edition, FormVariant, Severity
RULES_DIR = Path(__file__).resolve().parent.parent / "pylib_ai_arm_statements" / "rules" RULES_DIR = Path(__file__).resolve().parent.parent / "arm_statements" / "rules"
SPEC_WARNINGS = { SPEC_WARNINGS = {
"JSON_FAILED": ("error", "file"), "JSON_FAILED": ("error", "file"),

View File

@ -1,5 +1,9 @@
from importlib.metadata import PackageNotFoundError
from pathlib import Path from pathlib import Path
import pytest
import arm_statements.version as version_module
from arm_statements.version import statements_version from arm_statements.version import statements_version
FULL_HASH = "abc1234def5678abc1234def5678abc1234def56" FULL_HASH = "abc1234def5678abc1234def5678abc1234def56"
@ -19,3 +23,52 @@ def test_version_empty_file_is_none(tmp_path: Path) -> None:
marker = tmp_path / "VERSION" marker = tmp_path / "VERSION"
marker.write_text(" \n", encoding="utf-8") marker.write_text(" \n", encoding="utf-8")
assert statements_version(marker) is None assert statements_version(marker) is None
@pytest.mark.parametrize("contents", [None, " \n"])
def test_default_marker_falls_back_to_distribution(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, contents: str | None
) -> None:
marker = tmp_path / "VERSION"
if contents is not None:
marker.write_text(contents, encoding="utf-8")
monkeypatch.setattr(version_module, "_DEFAULT_MARKER", marker)
monkeypatch.setattr(version_module, "version", lambda name: "0.1.1" if name == "pylib-ai-arm-statements" else None)
assert statements_version() == "0.1.1"
def test_default_marker_takes_priority(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
marker = tmp_path / "VERSION"
marker.write_text(f" {FULL_HASH}\n", encoding="utf-8")
monkeypatch.setattr(version_module, "_DEFAULT_MARKER", marker)
def unexpected_metadata_lookup(name: str) -> str:
raise AssertionError(f"Unexpected metadata lookup: {name}")
monkeypatch.setattr(version_module, "version", unexpected_metadata_lookup)
assert statements_version() == FULL_HASH
def test_default_version_without_metadata_is_none(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(version_module, "_DEFAULT_MARKER", tmp_path / "VERSION")
def missing_distribution(name: str) -> str:
raise PackageNotFoundError(name)
monkeypatch.setattr(version_module, "version", missing_distribution)
assert statements_version() is None
@pytest.mark.parametrize("contents", [None, " \n"])
def test_explicit_marker_does_not_use_distribution(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, contents: str | None
) -> None:
marker = tmp_path / "VERSION"
if contents is not None:
marker.write_text(contents, encoding="utf-8")
def unexpected_metadata_lookup(name: str) -> str:
raise AssertionError(f"Unexpected metadata lookup: {name}")
monkeypatch.setattr(version_module, "version", unexpected_metadata_lookup)
assert statements_version(marker) is None