simple-module-test 0.0.48__tar.gz → 0.0.50__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. {simple_module_test-0.0.48 → simple_module_test-0.0.50}/PKG-INFO +5 -5
  2. {simple_module_test-0.0.48 → simple_module_test-0.0.50}/pyproject.toml +5 -5
  3. {simple_module_test-0.0.48 → simple_module_test-0.0.50}/simple_module_test/__init__.py +12 -12
  4. simple_module_test-0.0.50/simple_module_test/_schema.py +13 -0
  5. simple_module_test-0.0.50/simple_module_test/app/__init__.py +1 -0
  6. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/app}/_dotenv.py +2 -2
  7. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/app}/app_factory.py +2 -2
  8. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/app}/fixtures.py +10 -10
  9. simple_module_test-0.0.50/simple_module_test/app/layout.py +182 -0
  10. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/app}/process_state.py +5 -5
  11. simple_module_test-0.0.50/simple_module_test/database.py +13 -0
  12. simple_module_test-0.0.50/simple_module_test/db/__init__.py +1 -0
  13. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/db}/_compile_cache.py +2 -2
  14. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/db}/_schema.py +7 -7
  15. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/db}/database.py +14 -10
  16. simple_module_test-0.0.50/simple_module_test/fakes/__init__.py +1 -0
  17. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/fakes}/mail.py +2 -2
  18. simple_module_test-0.0.50/simple_module_test/fixtures.py +13 -0
  19. simple_module_test-0.0.50/simple_module_test/inertia.py +13 -0
  20. simple_module_test-0.0.50/simple_module_test/layout.py +13 -0
  21. simple_module_test-0.0.50/simple_module_test/mail.py +13 -0
  22. {simple_module_test-0.0.48 → simple_module_test-0.0.50}/simple_module_test/plugin.py +12 -12
  23. simple_module_test-0.0.50/simple_module_test/session_cookie.py +13 -0
  24. simple_module_test-0.0.50/simple_module_test/setup_wizard.py +13 -0
  25. simple_module_test-0.0.50/simple_module_test/tenant_client.py +13 -0
  26. simple_module_test-0.0.50/simple_module_test/web/__init__.py +1 -0
  27. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/web}/inertia.py +1 -1
  28. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/web}/setup_wizard.py +2 -2
  29. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/web}/tenant_client.py +3 -3
  30. simple_module_test-0.0.50/tests/app/test_testing_layout_shims.py +85 -0
  31. simple_module_test-0.0.50/tests/app/test_testing_module_layout.py +118 -0
  32. {simple_module_test-0.0.48/tests → simple_module_test-0.0.50/tests/app}/test_testing_process_state.py +12 -12
  33. {simple_module_test-0.0.48/tests → simple_module_test-0.0.50/tests/app}/test_testing_project_isolation.py +3 -3
  34. simple_module_test-0.0.50/tests/db/test_schema_reuse_pg.py +185 -0
  35. {simple_module_test-0.0.48/tests → simple_module_test-0.0.50/tests/db}/test_shared_compile_cache.py +4 -3
  36. {simple_module_test-0.0.48/tests → simple_module_test-0.0.50/tests/db}/test_sqlite_schema_template.py +2 -2
  37. {simple_module_test-0.0.48/tests → simple_module_test-0.0.50/tests/db}/test_worker_database.py +1 -1
  38. {simple_module_test-0.0.48/tests → simple_module_test-0.0.50/tests/web}/test_testing_inertia_headers.py +2 -2
  39. {simple_module_test-0.0.48/tests → simple_module_test-0.0.50/tests/web}/test_testing_inertia_page.py +1 -1
  40. simple_module_test-0.0.48/simple_module_test/layout.py +0 -87
  41. simple_module_test-0.0.48/tests/test_schema_reuse_pg.py +0 -75
  42. simple_module_test-0.0.48/tests/test_testing_module_layout.py +0 -31
  43. {simple_module_test-0.0.48 → simple_module_test-0.0.50}/.gitignore +0 -0
  44. {simple_module_test-0.0.48 → simple_module_test-0.0.50}/LICENSE +0 -0
  45. {simple_module_test-0.0.48 → simple_module_test-0.0.50}/README.md +0 -0
  46. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/app}/routes.py +0 -0
  47. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/app}/waiting.py +0 -0
  48. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/db}/_sqlite_template.py +0 -0
  49. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/db}/redis_server.py +0 -0
  50. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/fakes}/fake_events.py +0 -0
  51. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/fakes}/oidc_issuer.py +0 -0
  52. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/web}/inertia_page.py +0 -0
  53. {simple_module_test-0.0.48/simple_module_test → simple_module_test-0.0.50/simple_module_test/web}/session_cookie.py +0 -0
  54. {simple_module_test-0.0.48/tests → simple_module_test-0.0.50/tests/app}/test_app_factory.py +0 -0
  55. {simple_module_test-0.0.48/tests → simple_module_test-0.0.50/tests/app}/test_plugin_fixtures.py +0 -0
  56. {simple_module_test-0.0.48/tests → simple_module_test-0.0.50/tests/app}/test_waiting_helpers.py +0 -0
  57. {simple_module_test-0.0.48/tests → simple_module_test-0.0.50/tests/fakes}/test_fake_events.py +0 -0
  58. {simple_module_test-0.0.48/tests → simple_module_test-0.0.50/tests/fakes}/test_testing_oidc_issuer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: simple_module_test
3
- Version: 0.0.48
3
+ Version: 0.0.50
4
4
  Summary: Shared pytest fixtures (app, client, db_session, authenticated_client) for writing simple_module module tests
5
5
  Project-URL: Homepage, https://github.com/antosubash/simple_module_python
6
6
  Project-URL: Repository, https://github.com/antosubash/simple_module_python
@@ -28,10 +28,10 @@ Requires-Dist: pydantic-settings<3,>=2.4
28
28
  Requires-Dist: pyjwt[crypto]<3,>=2.8
29
29
  Requires-Dist: pytest-asyncio<2,>=0.24
30
30
  Requires-Dist: pytest<10,>=8.0
31
- Requires-Dist: simple-module-core==0.0.48
32
- Requires-Dist: simple-module-db==0.0.48
33
- Requires-Dist: simple-module-hosting==0.0.48
34
- Requires-Dist: simple-module-inertia==0.0.48
31
+ Requires-Dist: simple-module-core==0.0.50
32
+ Requires-Dist: simple-module-db==0.0.50
33
+ Requires-Dist: simple-module-hosting==0.0.50
34
+ Requires-Dist: simple-module-inertia==0.0.50
35
35
  Requires-Dist: sqlalchemy<3,>=2.0
36
36
  Description-Content-Type: text/markdown
37
37
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "simple_module_test"
3
- version = "0.0.48"
3
+ version = "0.0.50"
4
4
  description = "Shared pytest fixtures (app, client, db_session, authenticated_client) for writing simple_module module tests"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -30,10 +30,10 @@ dependencies = [
30
30
  "pydantic-settings>=2.4,<3",
31
31
  "pytest>=8.0,<10",
32
32
  "pytest-asyncio>=0.24,<2",
33
- "simple_module_core==0.0.48",
34
- "simple_module_db==0.0.48",
35
- "simple_module_hosting==0.0.48",
36
- "simple_module_inertia==0.0.48",
33
+ "simple_module_core==0.0.50",
34
+ "simple_module_db==0.0.50",
35
+ "simple_module_hosting==0.0.50",
36
+ "simple_module_inertia==0.0.50",
37
37
  "sqlalchemy>=2.0,<3",
38
38
  ]
39
39
 
@@ -21,26 +21,26 @@ The pytest plugin auto-registers these fixtures (no imports needed):
21
21
  ``engine``, ``db_session``, ``app``, ``client``, and ``authenticated_client``.
22
22
  ``redis_server`` starts a throwaway ``redis-server`` for the tests that need a
23
23
  real broker (cross-worker cache invalidation) and skips when the binary is absent.
24
- See ``simple_module_test.plugin`` (and ``simple_module_test.fixtures``) for
24
+ See ``simple_module_test.plugin`` (and ``simple_module_test.app.fixtures``) for
25
25
  their definitions. ``authenticated_client`` additionally requires the ``users``
26
26
  module to be installed — it seeds an admin via ``users.core.bootstrap``.
27
27
  ``tenant_client`` (``users`` + ``tenants``) is a factory yielding a client signed
28
28
  in as an ``owner``/``admin``/``member`` of a real tenant — see
29
- ``simple_module_test.tenant_client``. ``oidc_test_issuer`` is an in-process
29
+ ``simple_module_test.web.tenant_client``. ``oidc_test_issuer`` is an in-process
30
30
  OpenID Connect issuer (:class:`OidcTestIssuer`: signing key, JWKS, discovery
31
31
  document and ``sign(claims)``) for testing an OIDC sign-in without an IdP.
32
32
  """
33
33
 
34
- from simple_module_test.app_factory import build_test_app
35
- from simple_module_test.fake_events import FakeEventBus, RecordedEvent
36
- from simple_module_test.inertia import inertia_headers
37
- from simple_module_test.inertia_page import InertiaPage, inertia_page
38
- from simple_module_test.layout import assert_module_layout
39
- from simple_module_test.oidc_issuer import OidcTestIssuer
40
- from simple_module_test.routes import effective_route_paths
41
- from simple_module_test.session_cookie import forge_session_cookie
42
- from simple_module_test.tenant_client import TenantClient
43
- from simple_module_test.waiting import wait_for, wait_for_sync
34
+ from simple_module_test.app.app_factory import build_test_app
35
+ from simple_module_test.app.layout import assert_module_layout
36
+ from simple_module_test.app.routes import effective_route_paths
37
+ from simple_module_test.app.waiting import wait_for, wait_for_sync
38
+ from simple_module_test.fakes.fake_events import FakeEventBus, RecordedEvent
39
+ from simple_module_test.fakes.oidc_issuer import OidcTestIssuer
40
+ from simple_module_test.web.inertia import inertia_headers
41
+ from simple_module_test.web.inertia_page import InertiaPage, inertia_page
42
+ from simple_module_test.web.session_cookie import forge_session_cookie
43
+ from simple_module_test.web.tenant_client import TenantClient
44
44
 
45
45
  __all__ = [
46
46
  "FakeEventBus",
@@ -0,0 +1,13 @@
1
+ """Deprecated alias for simple_module_test.db._schema."""
2
+
3
+ import sys
4
+ from importlib import import_module
5
+
6
+ from simple_module_core.runtime.deprecation import deprecated_module
7
+
8
+ deprecated_module(
9
+ "simple_module_test._schema",
10
+ remove_in="0.0.52",
11
+ use="simple_module_test.db._schema",
12
+ )
13
+ sys.modules[__name__] = import_module("simple_module_test.db._schema")
@@ -0,0 +1 @@
1
+ """App test helpers."""
@@ -8,8 +8,8 @@ from pathlib import Path
8
8
 
9
9
  import pytest
10
10
  from pydantic_settings import DotEnvSettingsSource
11
- from simple_module_core import dotenv
12
- from simple_module_hosting import _preapp_config
11
+ from simple_module_core.settings import dotenv
12
+ from simple_module_hosting.config import _preapp_config
13
13
 
14
14
 
15
15
  def isolate_project_dotenv(config: pytest.Config) -> None:
@@ -4,8 +4,8 @@ from __future__ import annotations
4
4
 
5
5
  from fastapi import FastAPI
6
6
  from simple_module_core import ModuleBase
7
- from simple_module_hosting._module_routes import wire_fallback_routes
8
- from simple_module_hosting.app_builder import wire_module_routes
7
+ from simple_module_hosting.boot._module_routes import wire_fallback_routes
8
+ from simple_module_hosting.boot.app_builder import wire_module_routes
9
9
 
10
10
 
11
11
  def build_test_app(module: ModuleBase | type[ModuleBase]) -> FastAPI:
@@ -25,15 +25,15 @@ from collections.abc import AsyncGenerator, Iterator
25
25
 
26
26
  import httpx
27
27
  import pytest
28
- from simple_module_core.discovery import DEFAULT_AUTH_PROVIDER
29
- from simple_module_db.session import DatabaseState, init_db
30
- from simple_module_hosting.settings import Settings
28
+ from simple_module_core.modules.discovery import DEFAULT_AUTH_PROVIDER
29
+ from simple_module_db.engine.session import DatabaseState, init_db
30
+ from simple_module_hosting.config.settings import Settings
31
31
  from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession
32
32
 
33
- from simple_module_test._schema import _create_all_tables
34
- from simple_module_test.database import begin_test, database_url_for_tests, init_db_kwargs
35
- from simple_module_test.inertia import inertia_headers
36
- from simple_module_test.session_cookie import forge_session_cookie
33
+ from simple_module_test.db._schema import _create_all_tables
34
+ from simple_module_test.db.database import begin_test, database_url_for_tests, init_db_kwargs
35
+ from simple_module_test.web.inertia import inertia_headers
36
+ from simple_module_test.web.session_cookie import forge_session_cookie
37
37
 
38
38
  _AUTH_PROVIDER_ENV = "SM_AUTH_PROVIDER"
39
39
 
@@ -68,7 +68,7 @@ def fresh_test_database(request: pytest.FixtureRequest) -> None:
68
68
  """Let the first fixture of each test empty the Postgres schema, and no later one.
69
69
 
70
70
  A no-op on the default in-memory SQLite, where every engine is already
71
- its own empty database (see ``simple_module_test.database``).
71
+ its own empty database (see ``simple_module_test.db.database``).
72
72
  """
73
73
  begin_test(request.node)
74
74
 
@@ -99,7 +99,7 @@ def settings() -> Settings:
99
99
  @pytest.fixture
100
100
  async def db_state() -> AsyncGenerator[DatabaseState, None]:
101
101
  """Create a fresh in-memory DatabaseState with listeners registered."""
102
- from simple_module_db.listeners import register_listeners
102
+ from simple_module_db.models.listeners import register_listeners
103
103
 
104
104
  url = database_url_for_tests()
105
105
  state = init_db(url, **init_db_kwargs(url))
@@ -157,7 +157,7 @@ async def _seed_setup_admin(application) -> None:
157
157
 
158
158
 
159
159
  async def _build_app(settings: Settings, *, seed_admin: bool):
160
- from simple_module_hosting.app_builder import create_app
160
+ from simple_module_hosting.boot.app_builder import create_app
161
161
 
162
162
  # Process-wide state is reset per test by the autouse fixture in
163
163
  # ``process_state``, not here: a second app built inside one test must not
@@ -0,0 +1,182 @@
1
+ """Public pytest assertion for the standard module package and test layout."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import ast
6
+ import tomllib
7
+ from collections.abc import Collection
8
+ from pathlib import Path
9
+
10
+ ALLOWED_ROOT = frozenset(
11
+ {
12
+ "__init__.py",
13
+ "__main__.py",
14
+ "py.typed",
15
+ "module.py",
16
+ "models.py",
17
+ "models",
18
+ "tasks.py",
19
+ "task_config.py",
20
+ "contracts",
21
+ "pages",
22
+ "locales",
23
+ "theme.css",
24
+ "styles.css",
25
+ "cli.py",
26
+ "core",
27
+ "web",
28
+ "ui",
29
+ }
30
+ )
31
+
32
+
33
+ def is_docstring_only_init(init_path: Path) -> bool:
34
+ """Return True when an initializer has at most a module docstring."""
35
+ try:
36
+ tree = ast.parse(init_path.read_text(encoding="utf-8"), filename=str(init_path))
37
+ except SyntaxError:
38
+ return False
39
+ if not tree.body:
40
+ return True
41
+ if len(tree.body) == 1 and isinstance(tree.body[0], ast.Expr):
42
+ val = tree.body[0].value
43
+ return isinstance(val, ast.Constant) and isinstance(val.value, str)
44
+ return False
45
+
46
+
47
+ def _is_deprecation_warning_arg(node: ast.expr) -> bool:
48
+ return (isinstance(node, ast.Name) and node.id == "DeprecationWarning") or (
49
+ isinstance(node, ast.Attribute) and node.attr == "DeprecationWarning"
50
+ )
51
+
52
+
53
+ def _is_deprecation_call(call: ast.Call) -> bool:
54
+ fn = call.func
55
+ name = fn.id if isinstance(fn, ast.Name) else (fn.attr if isinstance(fn, ast.Attribute) else "")
56
+ if name == "deprecated_module":
57
+ return True
58
+ if name != "warn":
59
+ return False
60
+ pos_dep = len(call.args) >= 2 and _is_deprecation_warning_arg(call.args[1])
61
+ kw_dep = any(
62
+ kw.arg == "category" and _is_deprecation_warning_arg(kw.value) for kw in call.keywords
63
+ )
64
+ return pos_dep or kw_dep
65
+
66
+
67
+ def _is_sys_modules_target(target: ast.expr) -> bool:
68
+ return (
69
+ isinstance(target, ast.Subscript)
70
+ and isinstance(target.value, ast.Attribute)
71
+ and isinstance(target.value.value, ast.Name)
72
+ and target.value.value.id == "sys"
73
+ and target.value.attr == "modules"
74
+ and isinstance(target.slice, ast.Name)
75
+ and target.slice.id == "__name__"
76
+ )
77
+
78
+
79
+ def is_layout_shim_source(text: str, *, filename: str = "<string>") -> bool:
80
+ """Return True when top-level statements declare a deprecation and sys.modules alias."""
81
+ try:
82
+ tree = ast.parse(text, filename=filename)
83
+ except SyntaxError:
84
+ return False
85
+ has_dep = False
86
+ has_alias = False
87
+ for stmt in tree.body:
88
+ if isinstance(stmt, ast.Expr) and isinstance(stmt.value, ast.Call):
89
+ if _is_deprecation_call(stmt.value):
90
+ has_dep = True
91
+ elif isinstance(stmt, ast.Assign) and any(
92
+ _is_sys_modules_target(target) for target in stmt.targets
93
+ ):
94
+ has_alias = True
95
+ return has_dep and has_alias
96
+
97
+
98
+ def is_layout_shim(path: Path) -> bool:
99
+ """A moved module's old path: a deprecated alias, allowed until its remove_in."""
100
+ return is_layout_shim_source(path.read_text(encoding="utf-8"), filename=str(path))
101
+
102
+
103
+ def only_bytecode(path: Path) -> bool:
104
+ """A non-empty directory holding only ``__pycache__`` subtrees."""
105
+ children = list(path.iterdir())
106
+ if not children:
107
+ return False
108
+ for child in children:
109
+ if child.is_symlink() or not child.is_dir():
110
+ return False
111
+ if child.name != "__pycache__" and not only_bytecode(child):
112
+ return False
113
+ return True
114
+
115
+
116
+ def is_shim_package(path: Path) -> bool:
117
+ """An old package path kept only for aliases and optional docstring initializers."""
118
+ has_shim = False
119
+ for child in path.iterdir():
120
+ if child.is_symlink():
121
+ return False
122
+ if child.is_dir():
123
+ if child.name == "__pycache__" or only_bytecode(child):
124
+ continue
125
+ if not is_shim_package(child):
126
+ return False
127
+ has_shim = True
128
+ continue
129
+ if not child.is_file() or child.suffix != ".py":
130
+ return False
131
+ if child.name == "__init__.py":
132
+ if is_layout_shim(child):
133
+ has_shim = True
134
+ elif not is_docstring_only_init(child):
135
+ return False
136
+ elif is_layout_shim(child):
137
+ has_shim = True
138
+ else:
139
+ return False
140
+ return has_shim
141
+
142
+
143
+ def assert_module_layout(
144
+ project: Path,
145
+ package_name: str,
146
+ *,
147
+ domain_areas: Collection[str] = (),
148
+ deprecated_root: Collection[str] = (),
149
+ ) -> None:
150
+ """Check a module project (package + tests + pyproject.toml).
151
+
152
+ Pass named domain directories and any temporary deprecated root files.
153
+ Test basenames may repeat: the plugin defaults to importlib mode.
154
+ """
155
+ package = project / package_name
156
+ assert package.is_dir(), f"Missing package for {package_name}"
157
+ entries = {
158
+ p.name
159
+ for p in package.iterdir()
160
+ if (p.is_file() and p.suffix == ".py" and not is_layout_shim(p))
161
+ or (
162
+ p.is_dir()
163
+ and p.name != "__pycache__"
164
+ and not only_bytecode(p)
165
+ and not is_shim_package(p)
166
+ )
167
+ }
168
+ deprecated = frozenset(deprecated_root)
169
+ assert deprecated <= {p.name for p in package.iterdir()}, (
170
+ f"{package_name}: remove expired DEPRECATED_ROOT entries"
171
+ )
172
+ allowed = ALLOWED_ROOT | frozenset(domain_areas) | deprecated
173
+ assert not entries - allowed, f"{package_name}: unexpected roots {entries - allowed}"
174
+ if (package / "cli.py").is_file():
175
+ metadata = tomllib.loads((project / "pyproject.toml").read_text())["project"]
176
+ targets = [
177
+ value for group in metadata.get("entry-points", {}).values() for value in group.values()
178
+ ]
179
+ assert any(value.split(":")[0] == f"{package_name}.cli" for value in targets)
180
+ # Tests mirror the package areas: tests/<area>/<feature>/test_*.py.
181
+ assert not list((project / "tests").glob("test_*.py")), package_name
182
+ assert not list((project / "tests").rglob("__init__.py")), package_name
@@ -3,11 +3,11 @@
3
3
  from collections.abc import Iterator
4
4
 
5
5
  import pytest
6
- from simple_module_core.leases import reset_lease_backend
7
- from simple_module_core.mail import reset_mail_sender
8
- from simple_module_core.settings_hydrate import env_supplied_fields
9
- from simple_module_hosting._api_version import default_api_version
10
- from simple_module_hosting.sentry import reset_sentry
6
+ from simple_module_core.mailer.mail import reset_mail_sender
7
+ from simple_module_core.runtime.leases import reset_lease_backend
8
+ from simple_module_core.settings.settings_hydrate import env_supplied_fields
9
+ from simple_module_hosting.config._api_version import default_api_version
10
+ from simple_module_hosting.observability.sentry import reset_sentry
11
11
 
12
12
 
13
13
  def reset_process_state() -> None:
@@ -0,0 +1,13 @@
1
+ """Deprecated alias for simple_module_test.db.database."""
2
+
3
+ import sys
4
+ from importlib import import_module
5
+
6
+ from simple_module_core.runtime.deprecation import deprecated_module
7
+
8
+ deprecated_module(
9
+ "simple_module_test.database",
10
+ remove_in="0.0.52",
11
+ use="simple_module_test.db.database",
12
+ )
13
+ sys.modules[__name__] = import_module("simple_module_test.db.database")
@@ -0,0 +1 @@
1
+ """Db test helpers."""
@@ -26,7 +26,7 @@ from sqlalchemy.engine import URL
26
26
  from sqlalchemy.ext.asyncio import AsyncEngine
27
27
  from sqlalchemy.util import LRUCache
28
28
 
29
- from simple_module_test._sqlite_template import is_memory_sqlite
29
+ from simple_module_test.db._sqlite_template import is_memory_sqlite
30
30
 
31
31
  # Engine options that change only how a connection is opened or logged, not the
32
32
  # dialect, so engines differing in them can share one.
@@ -46,7 +46,7 @@ def _dialect_key(engine: Any, options: dict[str, Any]) -> tuple | None:
46
46
  def share_sqlite_compile_cache() -> None:
47
47
  if os.environ.get("SM_TEST_SEPARATE_COMPILE_CACHES"):
48
48
  return
49
- import simple_module_db.session as session
49
+ import simple_module_db.engine.session as session
50
50
 
51
51
  original = session.create_async_engine
52
52
 
@@ -1,6 +1,6 @@
1
1
  """Schema construction for the plugin's app fixtures.
2
2
 
3
- Split out of :mod:`simple_module_test.fixtures` so that module declares
3
+ Split out of :mod:`simple_module_test.app.fixtures` so that module declares
4
4
  fixtures and this one holds the machinery underneath them: importing every
5
5
  installed module's models, resolving the migration heads, creating the tables
6
6
  and stamping ``alembic_version`` so the boot-time migration check passes.
@@ -12,15 +12,15 @@ import contextlib
12
12
  import importlib
13
13
  from functools import lru_cache
14
14
 
15
- from simple_module_core.discovery import discover_modules
16
- from simple_module_db.base import all_module_bases
15
+ from simple_module_core.modules.discovery import discover_modules
16
+ from simple_module_db.models.base import all_module_bases
17
17
 
18
18
 
19
19
  @lru_cache(maxsize=1)
20
20
  def _ensure_models_imported() -> list:
21
21
  """Import all module models so all_module_bases is populated (cached)."""
22
- import simple_module_db.leases # framework-owned table (#539)
23
- import simple_module_db.stored_settings # noqa: F401 framework-owned table (#500)
22
+ import simple_module_db.engine.leases # framework-owned table (#539)
23
+ import simple_module_db.queries.stored_settings # noqa: F401 framework-owned table (#500)
24
24
 
25
25
  for mod in discover_modules():
26
26
  pkg = type(mod).__module__.split(".")[0]
@@ -48,7 +48,7 @@ def _alembic_heads() -> tuple[str, ...]:
48
48
  test app behind the setup gate.
49
49
  """
50
50
  global _heads_cache
51
- from simple_module_hosting.migrations import resolve_head_revisions
51
+ from simple_module_hosting.boot.migrations import resolve_head_revisions
52
52
 
53
53
  if _heads_cache is None:
54
54
  heads = resolve_head_revisions()
@@ -68,7 +68,7 @@ async def _create_all_tables(engine) -> None:
68
68
  """
69
69
  from sqlalchemy import text
70
70
 
71
- from simple_module_test.database import prepare_schema_once
71
+ from simple_module_test.db.database import prepare_schema_once
72
72
 
73
73
  bases = _ensure_models_imported()
74
74
  heads = _alembic_heads()
@@ -23,7 +23,7 @@ from sqlalchemy import text
23
23
  from sqlalchemy.engine import make_url
24
24
  from sqlalchemy.pool import NullPool
25
25
 
26
- from simple_module_test._sqlite_template import build_from_template, is_memory_sqlite
26
+ from simple_module_test.db._sqlite_template import build_from_template, is_memory_sqlite
27
27
 
28
28
  TEST_DATABASE_ENV = "SM_TEST_DATABASE_URL"
29
29
  SQLITE_MEMORY = "sqlite+aiosqlite:///:memory:"
@@ -93,8 +93,8 @@ async def reset_schema(engine: Any) -> None:
93
93
 
94
94
 
95
95
  def _create_declared_extensions(sync_conn: Any) -> None:
96
- from simple_module_core.discovery import discover_modules
97
- from simple_module_db.extensions import ensure_db_extensions
96
+ from simple_module_core.modules.discovery import discover_modules
97
+ from simple_module_db.models.extensions import ensure_db_extensions
98
98
 
99
99
  ensure_db_extensions(sync_conn, discover_modules())
100
100
 
@@ -152,8 +152,8 @@ async def prepare_schema_once(engine: Any, tables: list[Any], build: Any) -> Non
152
152
  per-process copy of the first build (``_sqlite_template``), a file one runs
153
153
  ``build(engine)``.
154
154
  Postgres: when this process already built the schema and the catalog still
155
- matches it, delete every row and restart the sequences (~0.03 s) instead of
156
- dropping and rebuilding it (~0.25 s). Anything else (the first test, a
155
+ matches it, empty the tables with one TRUNCATE and restart the sequences
156
+ instead of dropping and rebuilding it. Anything else (the first test, a
157
157
  direct ``reset_schema`` call, a test's own DDL) resets and rebuilds.
158
158
  """
159
159
  global _reset_for, _built_schema
@@ -181,13 +181,17 @@ async def _fingerprint(engine: Any) -> str:
181
181
 
182
182
 
183
183
  async def _empty_tables(engine: Any, tables: list[Any]) -> None:
184
- from sqlalchemy.schema import sort_tables
184
+ """Empty a reused Postgres schema; SQLite is handled before this call."""
185
185
 
186
186
  async with engine.begin() as conn:
187
- quote = conn.dialect.identifier_preparer.format_table
188
- # Children first, so no foreign key refuses a parent's delete.
189
- for table in reversed(sort_tables(tables)):
190
- await conn.execute(text(f"DELETE FROM {quote(table)}"))
187
+ # A leaked reader must fail setup instead of waiting forever for TRUNCATE.
188
+ await conn.execute(text("SET LOCAL lock_timeout = '5s'"))
189
+ if tables:
190
+ quote = conn.dialect.identifier_preparer.format_table
191
+ names = ", ".join(quote(table) for table in tables)
192
+ # Refuse foreign-key dependants outside the caller's reset boundary.
193
+ await conn.execute(text(f"TRUNCATE {names} RESTART IDENTITY RESTRICT"))
194
+ # RESTART IDENTITY excludes unowned sequences; preserve their reset too.
191
195
  await conn.execute(_RESTART_SEQUENCES)
192
196
 
193
197
 
@@ -0,0 +1 @@
1
+ """Fakes test helpers."""
@@ -1,6 +1,6 @@
1
1
  """Mail fixtures: capture what the app sends, and never leak a sender between tests.
2
2
 
3
- The process mail sender (``simple_module_core.mail``) is module-level state that
3
+ The process mail sender (``simple_module_core.mailer.mail``) is module-level state that
4
4
  an app's ``mail`` module installs on startup, so a test that boots an app would
5
5
  otherwise hand its SMTP sender to the next test in the same worker.
6
6
  """
@@ -10,7 +10,7 @@ from __future__ import annotations
10
10
  from collections.abc import Iterator
11
11
 
12
12
  import pytest
13
- from simple_module_core.mail import MailMessage, install_mail_sender
13
+ from simple_module_core.mailer.mail import MailMessage, install_mail_sender
14
14
 
15
15
 
16
16
  class CapturedMail:
@@ -0,0 +1,13 @@
1
+ """Deprecated alias for simple_module_test.app.fixtures."""
2
+
3
+ import sys
4
+ from importlib import import_module
5
+
6
+ from simple_module_core.runtime.deprecation import deprecated_module
7
+
8
+ deprecated_module(
9
+ "simple_module_test.fixtures",
10
+ remove_in="0.0.52",
11
+ use="simple_module_test.app.fixtures",
12
+ )
13
+ sys.modules[__name__] = import_module("simple_module_test.app.fixtures")
@@ -0,0 +1,13 @@
1
+ """Deprecated alias for simple_module_test.web.inertia."""
2
+
3
+ import sys
4
+ from importlib import import_module
5
+
6
+ from simple_module_core.runtime.deprecation import deprecated_module
7
+
8
+ deprecated_module(
9
+ "simple_module_test.inertia",
10
+ remove_in="0.0.52",
11
+ use="simple_module_test.web.inertia",
12
+ )
13
+ sys.modules[__name__] = import_module("simple_module_test.web.inertia")
@@ -0,0 +1,13 @@
1
+ """Deprecated alias for simple_module_test.app.layout."""
2
+
3
+ import sys
4
+ from importlib import import_module
5
+
6
+ from simple_module_core.runtime.deprecation import deprecated_module
7
+
8
+ deprecated_module(
9
+ "simple_module_test.layout",
10
+ remove_in="0.0.52",
11
+ use="simple_module_test.app.layout",
12
+ )
13
+ sys.modules[__name__] = import_module("simple_module_test.app.layout")
@@ -0,0 +1,13 @@
1
+ """Deprecated alias for simple_module_test.fakes.mail."""
2
+
3
+ import sys
4
+ from importlib import import_module
5
+
6
+ from simple_module_core.runtime.deprecation import deprecated_module
7
+
8
+ deprecated_module(
9
+ "simple_module_test.mail",
10
+ remove_in="0.0.52",
11
+ use="simple_module_test.fakes.mail",
12
+ )
13
+ sys.modules[__name__] = import_module("simple_module_test.fakes.mail")
@@ -13,16 +13,14 @@ import os
13
13
 
14
14
  import pytest
15
15
 
16
- from simple_module_test._compile_cache import share_sqlite_compile_cache
17
- from simple_module_test.app_factory import build_test_app as _build_test_app
18
- from simple_module_test.fake_events import FakeEventBus
16
+ from simple_module_test.app.app_factory import build_test_app as _build_test_app
19
17
 
20
18
  # Re-export the headline app/db/client fixtures the README advertises. pytest
21
19
  # collects fixture-decorated attributes of the plugin module, so importing them
22
20
  # here registers them for every test run that installs simple_module_test —
23
21
  # without a per-consumer conftest. Treat this surface like a public API: deleting
24
22
  # one breaks external modules' suites. See GH #200.
25
- from simple_module_test.fixtures import ( # noqa: F401
23
+ from simple_module_test.app.fixtures import ( # noqa: F401
26
24
  app,
27
25
  authenticated_client,
28
26
  client,
@@ -34,11 +32,13 @@ from simple_module_test.fixtures import ( # noqa: F401
34
32
  settings,
35
33
  setup_pending_app,
36
34
  )
37
- from simple_module_test.mail import captured_mail # noqa: F401
38
- from simple_module_test.oidc_issuer import oidc_test_issuer # noqa: F401
39
- from simple_module_test.process_state import _reset_process_state # noqa: F401
40
- from simple_module_test.redis_server import redis_server # noqa: F401
41
- from simple_module_test.tenant_client import tenant_client # noqa: F401
35
+ from simple_module_test.app.process_state import _reset_process_state # noqa: F401
36
+ from simple_module_test.db._compile_cache import share_sqlite_compile_cache
37
+ from simple_module_test.db.redis_server import redis_server # noqa: F401
38
+ from simple_module_test.fakes.fake_events import FakeEventBus
39
+ from simple_module_test.fakes.mail import captured_mail # noqa: F401
40
+ from simple_module_test.fakes.oidc_issuer import oidc_test_issuer # noqa: F401
41
+ from simple_module_test.web.tenant_client import tenant_client # noqa: F401
42
42
 
43
43
 
44
44
  def pytest_configure(config: pytest.Config) -> None:
@@ -56,8 +56,8 @@ def pytest_load_initial_conftests(early_config, parser, args) -> None:
56
56
  conftest is imported (``pytest_configure`` runs after), so a conftest or
57
57
  test helper that reads the URL at import time already sees the worker's.
58
58
  """
59
- from simple_module_test._dotenv import isolate_project_dotenv
60
- from simple_module_test.database import isolate_worker_database
59
+ from simple_module_test.app._dotenv import isolate_project_dotenv
60
+ from simple_module_test.db.database import isolate_worker_database
61
61
 
62
62
  isolate_project_dotenv(early_config)
63
63
  if not any(arg == "--import-mode" or arg.startswith("--import-mode=") for arg in args):
@@ -68,7 +68,7 @@ def pytest_load_initial_conftests(early_config, parser, args) -> None:
68
68
 
69
69
  def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None:
70
70
  """Skip ``@pytest.mark.postgres`` tests unless the test database is Postgres."""
71
- from simple_module_test.database import database_is_postgres
71
+ from simple_module_test.db.database import database_is_postgres
72
72
 
73
73
  if database_is_postgres():
74
74
  return