Skip to content
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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "uv_build"

[project]
name = "python-ort"
version = "0.8.4"
version = "0.8.5"
description = "A Python Ort model serialization library"
readme = "README.md"
license = "MIT"
Expand Down Expand Up @@ -40,7 +40,7 @@ dev = [
"pytest>=9.0.2",
"rich>=14.3.3",
"ruff>=0.15.6",
"ty>=0.0.22",
"ty>=0.0.23",
"types-pyyaml>=6.0.12.20250915",
]

Expand Down
19 changes: 18 additions & 1 deletion src/ort/utils/validated_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,21 @@ def validate(value: Any) -> ValidatedIntEnum:
return cls(value)
raise ValueError(f"Invalid value for {cls.__name__}: {value}")

return core_schema.no_info_plain_validator_function(validate)
enum_names = [member.name for member in cls]

return core_schema.no_info_wrap_validator_function(
lambda value, handler: validate(value),
core_schema.str_schema(),
Comment on lines +36 to +38
serialization=core_schema.plain_serializer_function_ser_schema(
lambda v: v.name,
info_arg=False,
),
metadata={
"pydantic_js_functions": [
lambda _schema, handler: {
"type": "string",
"enum": enum_names,
}
Comment on lines +45 to +48
]
},
)
11 changes: 11 additions & 0 deletions tests/data/repo_config/bad_license_choices.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
excludes:
scopes:
- pattern: "devDependencies"
reason: "DEV_DEPENDENCY_OF"
comment: "Packages for development only."
license_choices:
package_license_choice:
- package_id: "NPM::promised-io:0.3.6"
license_choices:
- given: AFL-2.1 OR BSD-3-Clause
choice: BSD-3-Clause
11 changes: 11 additions & 0 deletions tests/data/repo_config/license_choices.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
excludes:
scopes:
- pattern: "devDependencies"
reason: "DEV_DEPENDENCY_OF"
comment: "Packages for development only."
license_choices:
package_license_choices:
- package_id: "NPM::promised-io:0.3.6"
license_choices:
- given: AFL-2.1 OR BSD-3-Clause
choice: BSD-3-Clause
2 changes: 1 addition & 1 deletion tests/test_advisor_capability.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <dev@heliocastro.info>
# SPDX-License-Identifier: MIT

import pytest
Expand Down
2 changes: 1 addition & 1 deletion tests/test_advisor_details.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <dev@heliocastro.info>
# SPDX-License-Identifier: MIT

import pytest
Expand Down
2 changes: 1 addition & 1 deletion tests/test_advisor_result.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <dev@heliocastro.info>
# SPDX-License-Identifier: MIT

from datetime import datetime, timezone
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cvss_ratings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <dev@heliocastro.info>
# SPDX-License-Identifier: MIT

import pytest
Expand Down
2 changes: 1 addition & 1 deletion tests/test_evaluator_run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <dev@heliocastro.info>
# SPDX-License-Identifier: MIT

from datetime import datetime, timezone
Expand Down
2 changes: 1 addition & 1 deletion tests/test_package_configuration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <dev@heliocastro.info>
# SPDX-License-Identifier: MIT


Expand Down
2 changes: 1 addition & 1 deletion tests/test_package_curation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <dev@heliocastro.info>
# SPDX-License-Identifier: MIT


Expand Down
2 changes: 1 addition & 1 deletion tests/test_repo_config_curations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <dev@heliocastro.info>
# SPDX-License-Identifier: MIT


Expand Down
16 changes: 14 additions & 2 deletions tests/test_repo_config_files.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <dev@heliocastro.info>
# SPDX-License-Identifier: MIT

from pathlib import Path
Expand All @@ -11,8 +11,12 @@

REPO_CONFIG_DIR = Path(__file__).parent / "data" / "repo_config"

# Files that are expected to FAIL validation
_KNOWN_INVALID = {"only_include_reason_fail.yml", "bad_license_choices.yml"}

# Collect all YAML files that are expected to be valid RepositoryConfiguration documents
_VALID_FILES = [f for f in REPO_CONFIG_DIR.glob("*.yml") if f.name != "only_include_reason_fail.yml"]
_VALID_FILES = [f for f in REPO_CONFIG_DIR.glob("*.yml") if f.name not in _KNOWN_INVALID]
_INVALID_FILES = [f for f in REPO_CONFIG_DIR.glob("*.yml") if f.name in _KNOWN_INVALID]


@pytest.mark.parametrize("config_file", _VALID_FILES, ids=lambda f: f.name)
Expand All @@ -24,3 +28,11 @@ def test_repo_config_file_loads_without_validation_error(config_file: Path) -> N
RepositoryConfiguration.model_validate(data or {})
except ValidationError as exc:
pytest.fail(f"{config_file.name} raised ValidationError: {exc}")


@pytest.mark.parametrize("config_file", _INVALID_FILES, ids=lambda f: f.name)
def test_repo_config_file_raises_validation_error(config_file: Path) -> None:
"""Known-invalid files must raise a pydantic ValidationError."""
data = yaml.safe_load(config_file.read_text())
with pytest.raises(ValidationError):
RepositoryConfiguration.model_validate(data or {})
82 changes: 82 additions & 0 deletions tests/test_repo_config_license_choices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <dev@heliocastro.info>
# SPDX-License-Identifier: MIT


import pytest
from pydantic import ValidationError

from ort.models.config.repository_configuration import RepositoryConfiguration
from tests.utils.load_yaml_config import load_yaml_config


def test_license_choices_yml_loads_without_validation_error():
"""
Test that license_choices.yml loads into RepositoryConfiguration without raising a ValidationError.
"""
config_data = load_yaml_config(filename="license_choices.yml", data_dir="repo_config")
try:
RepositoryConfiguration.model_validate(config_data or {})
except ValidationError as exc:
pytest.fail(f"license_choices.yml raised ValidationError: {exc}")


def test_license_choices_yml_excludes_scopes():
"""
Test that the excludes.scopes section in license_choices.yml is parsed correctly.
"""
config_data = load_yaml_config(filename="license_choices.yml", data_dir="repo_config")
repo_config = RepositoryConfiguration.model_validate(config_data)

if repo_config.excludes is None:
pytest.fail("excludes section is missing")
scopes = repo_config.excludes.scopes
if len(scopes) != 1:
pytest.fail(f"Expected 1 scope exclude, got {len(scopes)}")

if scopes[0].pattern != "devDependencies":
pytest.fail(f"Unexpected pattern: {scopes[0].pattern}")
if scopes[0].reason.name != "DEV_DEPENDENCY_OF":
pytest.fail(f"Unexpected reason: {scopes[0].reason.name}")
if scopes[0].comment != "Packages for development only.":
pytest.fail(f"Unexpected comment: {scopes[0].comment}")


def test_license_choices_yml_package_license_choices():
"""
Test that the license_choices.package_license_choices section is parsed correctly,
including the package ID and the SPDX license choice.
"""
config_data = load_yaml_config(filename="license_choices.yml", data_dir="repo_config")
repo_config = RepositoryConfiguration.model_validate(config_data)

if repo_config.license_choices is None:
pytest.fail("license_choices section is missing")

package_choices = repo_config.license_choices.package_license_choices
if len(package_choices) != 1:
pytest.fail(f"Expected 1 package license choice, got {len(package_choices)}")

if str(package_choices[0].package_id) != "NPM::promised-io:0.3.6":
pytest.fail(f"Unexpected package_id: {package_choices[0].package_id}")

choices = package_choices[0].license_choices
if len(choices) != 1:
pytest.fail(f"Expected 1 license choice, got {len(choices)}")

if choices[0].given != "AFL-2.1 OR BSD-3-Clause":
pytest.fail(f"Unexpected given: {choices[0].given}")
if choices[0].choice != "BSD-3-Clause":
pytest.fail(f"Unexpected choice: {choices[0].choice}")


def test_bad_license_choices_yml_raises_validation_error():
"""
Test that bad_license_choices.yml raises a ValidationError due to an invalid field name
(package_license_choice instead of package_license_choices).
"""
config_data = load_yaml_config(filename="bad_license_choices.yml", data_dir="repo_config")
try:
RepositoryConfiguration.model_validate(config_data or {})
pytest.fail("bad_license_choices.yml should have raised ValidationError")
except ValidationError:
pass
2 changes: 1 addition & 1 deletion tests/test_repository_analyzer_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <dev@heliocastro.info>
# SPDX-License-Identifier: MIT


Expand Down
2 changes: 1 addition & 1 deletion tests/test_repository_configuration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <dev@heliocastro.info>
# SPDX-License-Identifier: MIT


Expand Down
2 changes: 1 addition & 1 deletion tests/test_scan_result.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <dev@heliocastro.info>
# SPDX-License-Identifier: MIT

from datetime import datetime, timezone
Expand Down
Loading
Loading