Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 0 additions & 10 deletions caldav/testing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,3 @@ def is_accessible(self) -> bool:
return True
except (OSError, ValueError):
return False


# Deferred registration to avoid circular imports
def _register_external_server() -> None:
from .registry import register_server_class

register_server_class("external", ExternalTestServer)


_register_external_server()
8 changes: 5 additions & 3 deletions caldav/testing/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@

import os

from .base import TestServer
from .base import ExternalTestServer, TestServer

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


def register_server_class(type_name: str, server_class: type[TestServer]) -> None:
Expand Down
27 changes: 27 additions & 0 deletions tests/test_testing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,30 @@ def test_test_servers_submodules_are_package_attributes(monkeypatch) -> None:
assert tests.test_servers.base is base
monkeypatch.setattr("tests.test_servers.base.DEFAULT_HTTP_TIMEOUT", 1)
assert base.DEFAULT_HTTP_TIMEOUT == 1


@pytest.mark.parametrize(
"module",
[
"caldav.testing",
"caldav.testing.base",
"caldav.testing.config_loader",
"caldav.testing.docker",
"caldav.testing.embedded",
"caldav.testing.helpers",
"caldav.testing.registry",
],
)
def test_each_testing_module_imports_on_its_own(module: str) -> None:
"""A consumer may import any submodule first; none may depend on another having been imported."""
import os
import subprocess
import sys

import caldav
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed

# This checkout's caldav, not whatever the editable install points at (a worktree's main checkout)
root = str(Path(caldav.__file__).resolve().parent.parent)
env = {**os.environ, "PYTHONPATH": os.pathsep.join([root, os.environ.get("PYTHONPATH", "")])}
code = f"import {module}; from caldav.testing.registry import get_server_class; assert get_server_class('external')"
subprocess.run([sys.executable, "-c", code], check=True, cwd=root, env=env)
Loading