diff --git a/src/tox/config/loader/api.py b/src/tox/config/loader/api.py index d0437357b..7eee7814a 100644 --- a/src/tox/config/loader/api.py +++ b/src/tox/config/loader/api.py @@ -107,7 +107,7 @@ def found_keys(self) -> set[str]: raise NotImplementedError def __repr__(self) -> str: - return f"{type(self).__name__}" + return f"{self.__class__.__name__}(section={self._section.key}, overrides={self.overrides!r})" def __contains__(self, item: str) -> bool: return item in self.found_keys() diff --git a/src/tox/config/loader/ini/__init__.py b/src/tox/config/loader/ini/__init__.py index 5f0e5eda7..514dfbd4e 100644 --- a/src/tox/config/loader/ini/__init__.py +++ b/src/tox/config/loader/ini/__init__.py @@ -95,6 +95,3 @@ def get_section(self, name: str) -> SectionProxy | None: if self._parser.has_section(name): return self._parser[name] return None - - def __repr__(self) -> str: - return f"{self.__class__.__name__}(section={self._section.key}, overrides={self.overrides!r})" diff --git a/tests/config/loader/ini/test_ini_loader.py b/tests/config/loader/ini/test_ini_loader.py index f05f85041..6b8d5d12f 100644 --- a/tests/config/loader/ini/test_ini_loader.py +++ b/tests/config/loader/ini/test_ini_loader.py @@ -4,7 +4,7 @@ import pytest -from tox.config.loader.api import ConfigLoadArgs, Override +from tox.config.loader.api import ConfigLoadArgs from tox.config.loader.ini import IniLoader from tox.config.source.ini_section import IniSection @@ -18,12 +18,6 @@ def test_ini_loader_keys(mk_ini_conf: Callable[[str], ConfigParser]) -> None: assert loader.found_keys() == {"a", "c"} -def test_ini_loader_repr(mk_ini_conf: Callable[[str], ConfigParser]) -> None: - core = IniSection(None, "tox") - loader = IniLoader(core, mk_ini_conf("\n[tox]\n\na=b\nc=d\n\n"), [Override("tox.a=1")], core_section=core) - assert repr(loader) == "IniLoader(section=tox, overrides={'a': [Override('tox.a=1')]})" - - def test_ini_loader_has_section(mk_ini_conf: Callable[[str], ConfigParser]) -> None: core = IniSection(None, "tox") loader = IniLoader(core, mk_ini_conf("[magic]\n[tox]\n\na=b\nc=d\n\n"), [], core_section=core) diff --git a/tests/config/loader/test_loader.py b/tests/config/loader/test_loader.py index ab8c7d996..5b2290268 100644 --- a/tests/config/loader/test_loader.py +++ b/tests/config/loader/test_loader.py @@ -5,9 +5,12 @@ import pytest from tox.config.cli.parse import get_options -from tox.config.loader.api import Override +from tox.config.loader.api import Loader, Override +from tox.config.loader.section import Section +from tox.config.loader.str_convert import StrConvert if TYPE_CHECKING: + from tox.config.main import Config from tox.pytest import CaptureFixture @@ -62,3 +65,19 @@ def test_override_not_equals_different_type() -> None: def test_override_repr() -> None: assert repr(Override("b.a=c")) == "Override('b.a=c')" + + +class SimpleLoader(StrConvert, Loader[str]): + """Simple loader for tests.""" + + def load_raw(self, key: str, conf: Config | None, env_name: str | None) -> str: # type: ignore[empty-body] + pass + + def found_keys(self) -> set[str]: # type: ignore[empty-body] + pass + + +def test_loader_repr() -> None: + core = Section(None, "tox") + loader = SimpleLoader(core, [Override("tox.a=1")]) + assert repr(loader) == "SimpleLoader(section=tox, overrides={'a': [Override('tox.a=1')]})" diff --git a/tests/config/loader/test_memory_loader.py b/tests/config/loader/test_memory_loader.py index 508566df1..8bd563e2d 100644 --- a/tests/config/loader/test_memory_loader.py +++ b/tests/config/loader/test_memory_loader.py @@ -11,11 +11,6 @@ from tox.config.types import Command, EnvList -def test_memory_loader_repr() -> None: - loader = MemoryLoader(a=1) - assert repr(loader) == "MemoryLoader" - - def test_memory_loader_override() -> None: loader = MemoryLoader(a=1) loader.overrides["a"] = [Override("a=2")]