|
| 1 | +from collections.abc import Iterable |
| 2 | +from dataclasses import dataclass |
| 3 | +from pathlib import Path |
| 4 | + |
1 | 5 | import pytest |
2 | 6 |
|
3 | 7 | import noxconfig |
| 8 | +from exasol.toolbox.config import BaseConfig |
4 | 9 | from exasol.toolbox.nox._shared import ( |
5 | 10 | DEFAULT_PATH_FILTERS, |
| 11 | + check_for_config_attribute, |
6 | 12 | python_files, |
7 | 13 | ) |
8 | 14 |
|
@@ -52,3 +58,35 @@ def test_python_files( |
52 | 58 | actual = python_files(tmp_directory) |
53 | 59 | assert len(actual) == 1 |
54 | 60 | 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