Skip to content

Commit c3f3c20

Browse files
committed
Add test for new check_for_config_attribute function
1 parent d00fb6a commit c3f3c20

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/unit/nox/_shared_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
from collections.abc import Iterable
2+
from dataclasses import dataclass
3+
from pathlib import Path
4+
15
import pytest
26

37
import noxconfig
8+
from exasol.toolbox.config import BaseConfig
49
from exasol.toolbox.nox._shared import (
510
DEFAULT_PATH_FILTERS,
11+
check_for_config_attribute,
612
python_files,
713
)
814

@@ -52,3 +58,35 @@ def test_python_files(
5258
actual = python_files(tmp_directory)
5359
assert len(actual) == 1
5460
assert "toolbox-dummy" in actual[0]
61+
62+
63+
@dataclass(frozen=True)
64+
class PreviousConfig:
65+
root: Path = Path(__file__).parent
66+
doc: Path = Path(__file__).parent / "doc"
67+
source: Path = Path("exasol/toolbox")
68+
version_file: Path = Path(__file__).parent / "exasol" / "toolbox" / "version.py"
69+
path_filters: Iterable[str] = ()
70+
pyupgrade_args: Iterable[str] = ("--py310-plus",)
71+
plugins = []
72+
73+
74+
# attributes + properties
75+
MIGRATED_VALUES = [
76+
*BaseConfig.model_fields.keys(),
77+
*BaseConfig.model_computed_fields.keys(),
78+
]
79+
80+
81+
class TestCheckForConfigAttribute:
82+
83+
@pytest.mark.parametrize("attribute", MIGRATED_VALUES)
84+
def test_old_implementation_raises_error(self, attribute):
85+
with pytest.raises(
86+
AttributeError, match="from `exasol.toolbox.config.BaseConfig`"
87+
):
88+
check_for_config_attribute(PreviousConfig(), attribute=attribute)
89+
90+
@pytest.mark.parametrize("attribute", MIGRATED_VALUES)
91+
def test_current_implementation_passes(self, attribute):
92+
check_for_config_attribute(BaseConfig(), attribute=attribute)

0 commit comments

Comments
 (0)