Skip to content

Commit b17aa6d

Browse files
committed
Merge PR 828: fix: import caldav.testing.registry on its own
#828 Importing caldav.testing.registry before anything else failed because registry and base imported each other; the external server class is now registered in registry itself. A follow-up test finds the checkout without importing caldav. Commits: - d351a5a fix: import caldav.testing.registry on its own - d8222d5 test: find the checkout without importing caldav Assisted-By: Claude Sonnet 5.5 <noreply@anthropic.com> Reviewed-by: Tobias Brox <tobias@redpill-linpro.com>
2 parents 34b05b9 + d8222d5 commit b17aa6d

3 files changed

Lines changed: 30 additions & 13 deletions

File tree

‎caldav/testing/base.py‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -639,13 +639,3 @@ def is_accessible(self) -> bool:
639639
return True
640640
except (OSError, ValueError):
641641
return False
642-
643-
644-
# Deferred registration to avoid circular imports
645-
def _register_external_server() -> None:
646-
from .registry import register_server_class
647-
648-
register_server_class("external", ExternalTestServer)
649-
650-
651-
_register_external_server()

‎caldav/testing/registry.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333

3434
import os
3535

36-
from .base import TestServer
36+
from .base import ExternalTestServer, TestServer
3737

38-
# Server class registry - maps type names to server classes
39-
_SERVER_CLASSES: dict[str, type[TestServer]] = {}
38+
# Server class registry - maps type names to server classes. The external
39+
# class is registered here rather than in base, which must not import this
40+
# module: base is imported first, from here.
41+
_SERVER_CLASSES: dict[str, type[TestServer]] = {"external": ExternalTestServer}
4042

4143

4244
def register_server_class(type_name: str, server_class: type[TestServer]) -> None:

‎tests/test_testing_base.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,28 @@ def test_test_servers_submodules_are_package_attributes(monkeypatch) -> None:
348348
assert tests.test_servers.base is base
349349
monkeypatch.setattr("tests.test_servers.base.DEFAULT_HTTP_TIMEOUT", 1)
350350
assert base.DEFAULT_HTTP_TIMEOUT == 1
351+
352+
353+
@pytest.mark.parametrize(
354+
"module",
355+
[
356+
"caldav.testing",
357+
"caldav.testing.base",
358+
"caldav.testing.config_loader",
359+
"caldav.testing.docker",
360+
"caldav.testing.embedded",
361+
"caldav.testing.helpers",
362+
"caldav.testing.registry",
363+
],
364+
)
365+
def test_each_testing_module_imports_on_its_own(module: str) -> None:
366+
"""A consumer may import any submodule first; none may depend on another having been imported."""
367+
import os
368+
import subprocess
369+
import sys
370+
371+
# This checkout's caldav, not whatever the editable install points at (a worktree's main checkout)
372+
root = str(Path(base.__file__).resolve().parents[2])
373+
env = {**os.environ, "PYTHONPATH": os.pathsep.join([root, os.environ.get("PYTHONPATH", "")])}
374+
code = f"import {module}; from caldav.testing.registry import get_server_class; assert get_server_class('external')"
375+
subprocess.run([sys.executable, "-c", code], check=True, cwd=root, env=env)

0 commit comments

Comments
 (0)