Skip to content
Open
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ classifiers = [
]
requires-python = ">=3.10"
dependencies = [
"beartype",
"beartype>=0.12.0",
"click",
"license_expression",
"ply",
Expand Down
4 changes: 2 additions & 2 deletions src/spdx_tools/common/typing/dataclass_with_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
from dataclasses import dataclass

from beartype import beartype
from beartype import BeartypeConf, beartype
from beartype.roar import BeartypeCallHintParamViolation


Expand All @@ -23,7 +23,7 @@ def dataclass_with_properties(cls):
def make_setter(field_name, field_type):
"""helper method to avoid late binding when generating functions in a for loop"""

@beartype
@beartype(conf=BeartypeConf(is_color=False))
def set_field(self, value: field_type):
setattr(self, f"_{field_name}", value)

Expand Down
36 changes: 36 additions & 0 deletions tests/spdx/model/test_type_error_formatting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SPDX-FileCopyrightText: 2026 spdx contributors
#
# SPDX-License-Identifier: Apache-2.0
import sys

import pytest

from spdx_tools.common.typing.constructor_type_errors import ConstructorTypeErrors
from spdx_tools.spdx.model import Package, SpdxNoAssertion


@pytest.mark.parametrize("is_terminal", [True, False])
def test_constructor_errors_are_plain_text(monkeypatch, is_terminal):
monkeypatch.setattr(sys.stdout, "isatty", lambda: is_terminal)

with pytest.raises(ConstructorTypeErrors) as error:
Package("SPDXRef-Package", "example", SpdxNoAssertion(), attribution_texts="invalid")

messages = error.value.get_messages()
assert len(messages) == 1
assert "attribution_texts" in messages[0]
assert "invalid" in messages[0]
assert "\x1b" not in messages[0]


@pytest.mark.parametrize("is_terminal", [True, False])
def test_setter_errors_are_plain_text(monkeypatch, is_terminal):
monkeypatch.setattr(sys.stdout, "isatty", lambda: is_terminal)
package = Package("SPDXRef-Package", "example", SpdxNoAssertion())

with pytest.raises(TypeError) as error:
package.attribution_texts = "invalid"

assert "attribution_texts" in str(error.value)
assert "invalid" in str(error.value)
assert "\x1b" not in str(error.value)