simple-module-test 0.0.49__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 (57) hide show
  1. {simple_module_test-0.0.49 → simple_module_test-0.0.50}/PKG-INFO +5 -5
  2. {simple_module_test-0.0.49 → simple_module_test-0.0.50}/pyproject.toml +5 -5
  3. {simple_module_test-0.0.49 → 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.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/app}/_dotenv.py +2 -2
  7. {simple_module_test-0.0.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/app}/app_factory.py +2 -2
  8. {simple_module_test-0.0.49/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.49/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.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/db}/_compile_cache.py +2 -2
  14. {simple_module_test-0.0.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/db}/_schema.py +7 -7
  15. {simple_module_test-0.0.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/db}/database.py +3 -3
  16. simple_module_test-0.0.50/simple_module_test/fakes/__init__.py +1 -0
  17. {simple_module_test-0.0.49/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.49 → 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.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/web}/inertia.py +1 -1
  28. {simple_module_test-0.0.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/web}/setup_wizard.py +2 -2
  29. {simple_module_test-0.0.49/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.49/tests → simple_module_test-0.0.50/tests/app}/test_testing_process_state.py +12 -12
  33. {simple_module_test-0.0.49/tests → simple_module_test-0.0.50/tests/app}/test_testing_project_isolation.py +3 -3
  34. {simple_module_test-0.0.49/tests → simple_module_test-0.0.50/tests/db}/test_schema_reuse_pg.py +1 -1
  35. {simple_module_test-0.0.49/tests → simple_module_test-0.0.50/tests/db}/test_shared_compile_cache.py +4 -3
  36. {simple_module_test-0.0.49/tests → simple_module_test-0.0.50/tests/db}/test_sqlite_schema_template.py +2 -2
  37. {simple_module_test-0.0.49/tests → simple_module_test-0.0.50/tests/db}/test_worker_database.py +1 -1
  38. {simple_module_test-0.0.49/tests → simple_module_test-0.0.50/tests/web}/test_testing_inertia_headers.py +2 -2
  39. {simple_module_test-0.0.49/tests → simple_module_test-0.0.50/tests/web}/test_testing_inertia_page.py +1 -1
  40. simple_module_test-0.0.49/simple_module_test/layout.py +0 -88
  41. simple_module_test-0.0.49/tests/test_testing_module_layout.py +0 -32
  42. {simple_module_test-0.0.49 → simple_module_test-0.0.50}/.gitignore +0 -0
  43. {simple_module_test-0.0.49 → simple_module_test-0.0.50}/LICENSE +0 -0
  44. {simple_module_test-0.0.49 → simple_module_test-0.0.50}/README.md +0 -0
  45. {simple_module_test-0.0.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/app}/routes.py +0 -0
  46. {simple_module_test-0.0.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/app}/waiting.py +0 -0
  47. {simple_module_test-0.0.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/db}/_sqlite_template.py +0 -0
  48. {simple_module_test-0.0.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/db}/redis_server.py +0 -0
  49. {simple_module_test-0.0.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/fakes}/fake_events.py +0 -0
  50. {simple_module_test-0.0.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/fakes}/oidc_issuer.py +0 -0
  51. {simple_module_test-0.0.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/web}/inertia_page.py +0 -0
  52. {simple_module_test-0.0.49/simple_module_test → simple_module_test-0.0.50/simple_module_test/web}/session_cookie.py +0 -0
  53. {simple_module_test-0.0.49/tests → simple_module_test-0.0.50/tests/app}/test_app_factory.py +0 -0
  54. {simple_module_test-0.0.49/tests → simple_module_test-0.0.50/tests/app}/test_plugin_fixtures.py +0 -0
  55. {simple_module_test-0.0.49/tests → simple_module_test-0.0.50/tests/app}/test_waiting_helpers.py +0 -0
  56. {simple_module_test-0.0.49/tests → simple_module_test-0.0.50/tests/fakes}/test_fake_events.py +0 -0
  57. {simple_module_test-0.0.49/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.49
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.49
32
- Requires-Dist: simple-module-db==0.0.49
33
- Requires-Dist: simple-module-hosting==0.0.49
34
- Requires-Dist: simple-module-inertia==0.0.49
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.49"
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.49",
34
- "simple_module_db==0.0.49",
35
- "simple_module_hosting==0.0.49",
36
- "simple_module_inertia==0.0.49",
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
 
@@ -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
@@ -0,0 +1,13 @@
1
+ """Deprecated alias for simple_module_test.web.session_cookie."""
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.session_cookie",
10
+ remove_in="0.0.52",
11
+ use="simple_module_test.web.session_cookie",
12
+ )
13
+ sys.modules[__name__] = import_module("simple_module_test.web.session_cookie")
@@ -0,0 +1,13 @@
1
+ """Deprecated alias for simple_module_test.web.setup_wizard."""
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.setup_wizard",
10
+ remove_in="0.0.52",
11
+ use="simple_module_test.web.setup_wizard",
12
+ )
13
+ sys.modules[__name__] = import_module("simple_module_test.web.setup_wizard")
@@ -0,0 +1,13 @@
1
+ """Deprecated alias for simple_module_test.web.tenant_client."""
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.tenant_client",
10
+ remove_in="0.0.52",
11
+ use="simple_module_test.web.tenant_client",
12
+ )
13
+ sys.modules[__name__] = import_module("simple_module_test.web.tenant_client")
@@ -0,0 +1 @@
1
+ """Web test helpers."""
@@ -2,7 +2,7 @@
2
2
 
3
3
  from typing import Any
4
4
 
5
- from simple_module_inertia.config import resolved_version
5
+ from simple_module_inertia.protocol.config import resolved_version
6
6
 
7
7
 
8
8
  def inertia_headers(app: Any) -> dict[str, str]:
@@ -9,9 +9,9 @@ as ``X-CSRF-Token``.
9
9
  from __future__ import annotations
10
10
 
11
11
  import httpx
12
- from simple_module_hosting.csrf import CSRF_HEADER
12
+ from simple_module_hosting.auth.csrf import CSRF_HEADER
13
13
 
14
- from simple_module_test.inertia import inertia_headers
14
+ from simple_module_test.web.inertia import inertia_headers
15
15
 
16
16
 
17
17
  def wizard_client(app) -> httpx.AsyncClient:
@@ -31,10 +31,10 @@ from typing import Any, NamedTuple
31
31
 
32
32
  import httpx
33
33
  import pytest
34
- from simple_module_core.tenancy import TenantRole
34
+ from simple_module_core.access.tenancy import TenantRole
35
35
 
36
- from simple_module_test.inertia import inertia_headers
37
- from simple_module_test.session_cookie import forge_session_cookie
36
+ from simple_module_test.web.inertia import inertia_headers
37
+ from simple_module_test.web.session_cookie import forge_session_cookie
38
38
 
39
39
 
40
40
  class TenantClient(NamedTuple):
@@ -0,0 +1,85 @@
1
+ """Old testing imports preserve identity without shadowing public helpers."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import subprocess
6
+ import sys
7
+ from pathlib import Path
8
+
9
+ import pytest
10
+
11
+
12
+ @pytest.mark.parametrize(
13
+ ("old", "new"),
14
+ [
15
+ ("_schema", "db._schema"),
16
+ ("database", "db.database"),
17
+ ("fixtures", "app.fixtures"),
18
+ ("inertia", "web.inertia"),
19
+ ("layout", "app.layout"),
20
+ ("mail", "fakes.mail"),
21
+ ("session_cookie", "web.session_cookie"),
22
+ ("setup_wizard", "web.setup_wizard"),
23
+ ("tenant_client", "web.tenant_client"),
24
+ ],
25
+ )
26
+ def test_testing_layout_shim_aliases_and_warns(old: str, new: str) -> None:
27
+ package = Path(__file__).resolve().parents[2] / "simple_module_test"
28
+ assert (package / (new.replace(".", "/") + ".py")).is_file()
29
+ result = subprocess.run(
30
+ [
31
+ sys.executable,
32
+ "-c",
33
+ f"""
34
+ import importlib
35
+ import warnings
36
+ from simple_module_core.runtime.deprecation import registered_deprecations
37
+
38
+ new = importlib.import_module('simple_module_test.{new}')
39
+ with warnings.catch_warnings(record=True) as caught:
40
+ warnings.simplefilter('always', DeprecationWarning)
41
+ old = importlib.import_module('simple_module_test.{old}')
42
+ assert old is new
43
+ assert any(
44
+ item.category is DeprecationWarning
45
+ and 'simple_module_test.{old} is deprecated' in str(item.message)
46
+ for item in caught
47
+ )
48
+ entry = next(d for d in registered_deprecations() if d.name == 'simple_module_test.{old}')
49
+ assert entry.remove_in == '0.0.52'
50
+ assert entry.use == 'simple_module_test.{new}'
51
+ """,
52
+ ],
53
+ capture_output=True,
54
+ text=True,
55
+ check=False,
56
+ )
57
+ assert result.returncode == 0, result.stdout + result.stderr
58
+
59
+
60
+ def test_inertia_page_has_no_root_alias_and_stays_callable() -> None:
61
+ package = Path(__file__).resolve().parents[2] / "simple_module_test"
62
+ assert not (package / "inertia_page.py").exists()
63
+ result = subprocess.run(
64
+ [
65
+ sys.executable,
66
+ "-c",
67
+ """
68
+ import importlib
69
+ import importlib.util
70
+ import simple_module_test
71
+
72
+ helper = simple_module_test.inertia_page
73
+ assert callable(helper)
74
+ assert importlib.util.find_spec('simple_module_test.inertia_page') is None
75
+ module = importlib.import_module('simple_module_test.web.inertia_page')
76
+ importlib.import_module('simple_module_test.plugin')
77
+ assert simple_module_test.inertia_page is helper is module.inertia_page
78
+ assert callable(simple_module_test.inertia_page)
79
+ """,
80
+ ],
81
+ capture_output=True,
82
+ text=True,
83
+ check=False,
84
+ )
85
+ assert result.returncode == 0, result.stdout + result.stderr
@@ -0,0 +1,118 @@
1
+ """Consumers can enforce module layout without copying the framework's test."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ import pytest
8
+ from simple_module_test.app.layout import is_layout_shim_source, is_shim_package
9
+
10
+ _VALID_ALIAS_CALLS = (
11
+ 'deprecated_module("old", remove_in="0.0.52", use="new")\nsys.modules[__name__] = target\n',
12
+ 'deprecation.deprecated_module("old", remove_in="0.0.52", use="new")\n'
13
+ "sys.modules[__name__] = target\n",
14
+ 'warnings.warn("old", DeprecationWarning, stacklevel=2)\nsys.modules[__name__] = target\n',
15
+ 'warnings.warn("old", category=DeprecationWarning, stacklevel=2)\n'
16
+ "sys.modules[__name__] = target\n",
17
+ )
18
+ _INVALID_ALIAS_CALLS = (
19
+ 'warnings.warn("old", UserWarning, stacklevel=2)\nsys.modules[__name__] = target\n',
20
+ 'def f():\n return "deprecated_module(x) sys.modules[__name__]"\n',
21
+ 'deprecated_module("old", remove_in="0.0.52", use="new")\n',
22
+ "sys.modules[__name__] = target\n",
23
+ "def broken(:\n",
24
+ )
25
+
26
+
27
+ def test_public_layout_helper_allows_duplicate_test_basenames(tmp_path):
28
+ from simple_module_test import assert_module_layout
29
+
30
+ package = tmp_path / "orders"
31
+ (package / "core").mkdir(parents=True)
32
+ (package / "__main__.py").touch()
33
+ for area in ("core", "web"):
34
+ tests = tmp_path / "tests" / area / "crud"
35
+ tests.mkdir(parents=True)
36
+ (tests / "test_crud.py").touch()
37
+ (package / "fulfillment").mkdir()
38
+ (package / "fulfillment" / "service.py").touch()
39
+ assert_module_layout(tmp_path, "orders", domain_areas={"fulfillment"})
40
+
41
+
42
+ @pytest.mark.parametrize(
43
+ "bad_path", ["orders/service.py", "tests/test_orders.py", "tests/__init__.py"]
44
+ )
45
+ def test_public_layout_helper_rejects_layout_drift(tmp_path, bad_path):
46
+ from simple_module_test import assert_module_layout
47
+
48
+ (tmp_path / "orders").mkdir()
49
+ target = tmp_path / bad_path
50
+ target.parent.mkdir(parents=True, exist_ok=True)
51
+ target.touch()
52
+ with pytest.raises(AssertionError):
53
+ assert_module_layout(tmp_path, "orders")
54
+
55
+
56
+ @pytest.mark.parametrize("extra_file", ["package.json", "tsconfig.json", "index.ts", "README.md"])
57
+ def test_public_layout_helper_allows_non_python_root_files(tmp_path: Path, extra_file: str) -> None:
58
+ from simple_module_test import assert_module_layout
59
+
60
+ pkg = tmp_path / "orders"
61
+ (pkg / "core").mkdir(parents=True)
62
+ (tmp_path / "tests" / "core").mkdir(parents=True)
63
+ (pkg / extra_file).write_text("x\n", encoding="utf-8")
64
+ assert_module_layout(tmp_path, "orders")
65
+
66
+
67
+ @pytest.mark.parametrize("source", _VALID_ALIAS_CALLS)
68
+ def test_is_layout_shim_source_accepts_valid_shims(source: str) -> None:
69
+ assert is_layout_shim_source(source) is True
70
+
71
+
72
+ @pytest.mark.parametrize("source", _INVALID_ALIAS_CALLS)
73
+ def test_is_layout_shim_source_rejects_non_shims(source: str) -> None:
74
+ assert is_layout_shim_source(source) is False
75
+
76
+
77
+ @pytest.mark.parametrize(
78
+ "files",
79
+ [
80
+ {"__init__.py": _VALID_ALIAS_CALLS[0]},
81
+ {"__init__.py": '"""Old package."""\n', "old.py": _VALID_ALIAS_CALLS[3]},
82
+ {
83
+ "__init__.py": '"""Old package."""\n',
84
+ "nested/__init__.py": '""\n',
85
+ "nested/old.py": _VALID_ALIAS_CALLS[0],
86
+ },
87
+ ],
88
+ ids=["init-only-shim", "docstring-init-plus-shim", "nested-shim-pkg"],
89
+ )
90
+ def test_is_shim_package_accepts_valid_trees(tmp_path: Path, files: dict[str, str]) -> None:
91
+ pkg = tmp_path / "old_pkg"
92
+ pkg.mkdir()
93
+ for rel, content in files.items():
94
+ target = pkg / rel
95
+ target.parent.mkdir(parents=True, exist_ok=True)
96
+ target.write_text(content, encoding="utf-8")
97
+ assert is_shim_package(pkg) is True
98
+
99
+
100
+ @pytest.mark.parametrize(
101
+ "files",
102
+ [
103
+ {"__init__.py": "x = 1\n", "old.py": _VALID_ALIAS_CALLS[0]},
104
+ {"__init__.py": '"""Pkg."""\n', "old.py": _VALID_ALIAS_CALLS[0], "sub/impl.py": "x = 1\n"},
105
+ {"__init__.py": _VALID_ALIAS_CALLS[0], "stray.json": "{}\n"},
106
+ {"__init__.py": '"""Only docstring."""\n'},
107
+ {},
108
+ ],
109
+ ids=["exec-init", "nested-non-shim", "non-py-file", "docstring-only-no-shims", "empty-dir"],
110
+ )
111
+ def test_is_shim_package_rejects_invalid_trees(tmp_path: Path, files: dict[str, str]) -> None:
112
+ pkg = tmp_path / "sneaky"
113
+ pkg.mkdir()
114
+ for rel, content in files.items():
115
+ target = pkg / rel
116
+ target.parent.mkdir(parents=True, exist_ok=True)
117
+ target.write_text(content, encoding="utf-8")
118
+ assert is_shim_package(pkg) is False
@@ -2,13 +2,7 @@
2
2
 
3
3
  from unittest.mock import Mock
4
4
 
5
- from simple_module_core.leases import (
6
- InProcessLeaseBackend,
7
- configure_leases,
8
- get_leases,
9
- reset_lease_backend,
10
- )
11
- from simple_module_core.mail import (
5
+ from simple_module_core.mailer.mail import (
12
6
  ConsoleMailSender,
13
7
  current_mail_sender,
14
8
  install_mail_resolver,
@@ -17,9 +11,15 @@ from simple_module_core.mail import (
17
11
  reset_mail_sender,
18
12
  resolve_mail_sender,
19
13
  )
20
- from simple_module_hosting import sentry
21
- from simple_module_test.mail import CapturedMail
22
- from simple_module_test.process_state import reset_process_state
14
+ from simple_module_core.runtime.leases import (
15
+ InProcessLeaseBackend,
16
+ configure_leases,
17
+ get_leases,
18
+ reset_lease_backend,
19
+ )
20
+ from simple_module_hosting.observability import sentry
21
+ from simple_module_test.app.process_state import reset_process_state
22
+ from simple_module_test.fakes.mail import CapturedMail
23
23
 
24
24
 
25
25
  async def test_reset_mail_clears_sender_and_worker_resolver() -> None:
@@ -69,8 +69,8 @@ async def test_plugin_second_app_keeps_first_apps_services(settings, monkeypatch
69
69
  """Resets are per test (autouse fixture), so a second app in one test must not
70
70
  wipe the first app's installed mail sender."""
71
71
  from fastapi import FastAPI
72
- from simple_module_hosting import app_builder
73
- from simple_module_test import fixtures
72
+ from simple_module_hosting.boot import app_builder
73
+ from simple_module_test.app import fixtures
74
74
 
75
75
  def create_app(settings):
76
76
  app = FastAPI()
@@ -35,14 +35,14 @@ def test_plugin_ignores_project_dotenv_before_conftest_and_in_fixtures(tmp_path)
35
35
  "SM_TEST_DOTENV_LEAK=leaked\n"
36
36
  )
37
37
  (tmp_path / "conftest.py").write_text(
38
- "from simple_module_hosting.settings import Settings\n"
38
+ "from simple_module_hosting.config.settings import Settings\n"
39
39
  "assert Settings().vite_dev_url == 'http://localhost:5050'\n"
40
40
  )
41
41
  (tmp_path / "test_settings.py").write_text(
42
42
  "import os\n"
43
43
  "import pytest\n"
44
- "from simple_module_core.dotenv import load_dotenv_into_environ\n"
45
- "from simple_module_hosting.settings import Settings\n"
44
+ "from simple_module_core.settings.dotenv import load_dotenv_into_environ\n"
45
+ "from simple_module_hosting.config.settings import Settings\n"
46
46
  "def test_settings(settings, monkeypatch, tmp_path):\n"
47
47
  " load_dotenv_into_environ()\n"
48
48
  " assert 'SM_TEST_DOTENV_LEAK' not in os.environ\n"
@@ -5,7 +5,7 @@ from __future__ import annotations
5
5
  import asyncio
6
6
 
7
7
  import pytest
8
- from simple_module_test import database
8
+ from simple_module_test.db import database
9
9
  from sqlalchemy import (
10
10
  Column,
11
11
  ForeignKey,
@@ -6,9 +6,10 @@ import json
6
6
  from types import SimpleNamespace
7
7
 
8
8
  import pytest
9
- from simple_module_db import init_db, session
10
- from simple_module_test import _compile_cache
11
- from simple_module_test.database import SQLITE_MEMORY
9
+ from simple_module_db import init_db
10
+ from simple_module_db.engine import session
11
+ from simple_module_test.db import _compile_cache
12
+ from simple_module_test.db.database import SQLITE_MEMORY
12
13
  from sqlalchemy import Column, Integer, MetaData, String, Table, inspect, select
13
14
  from sqlalchemy.engine import make_url
14
15
 
@@ -3,7 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import pytest
6
- from simple_module_test import _sqlite_template, database
6
+ from simple_module_test.db import _sqlite_template, database
7
7
  from sqlalchemy import (
8
8
  Column,
9
9
  Index,
@@ -141,7 +141,7 @@ class TestTheStampTable:
141
141
  """A worker whose first build resolved no Alembic heads (a test pointing
142
142
  ``SM_PROJECT_ROOT`` elsewhere) must not copy a schema without
143
143
  ``alembic_version`` into the tests that do stamp it."""
144
- from simple_module_test import _schema
144
+ from simple_module_test.db import _schema
145
145
 
146
146
  heads = _schema._alembic_heads()
147
147
  assert heads, "the repository has migrations, so heads must resolve here"
@@ -3,7 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import pytest
6
- from simple_module_test import database
6
+ from simple_module_test.db import database
7
7
 
8
8
  _PG = "postgresql+asyncpg://postgres:secret@db.local:5432/sm_test"
9
9
 
@@ -5,8 +5,8 @@ from types import SimpleNamespace
5
5
  import pytest
6
6
  from fastapi import FastAPI
7
7
  from simple_module_test import inertia_headers
8
- from simple_module_test.setup_wizard import wizard_client
9
- from simple_module_test.tenant_client import session_client
8
+ from simple_module_test.web.setup_wizard import wizard_client
9
+ from simple_module_test.web.tenant_client import session_client
10
10
 
11
11
 
12
12
  @pytest.mark.parametrize("version", ["build", lambda: "computed"])
@@ -7,7 +7,7 @@ from fastapi.routing import APIRoute
7
7
  from fastapi.templating import Jinja2Templates
8
8
  from jinja2.utils import htmlsafe_json_dumps
9
9
  from simple_module_core import ModuleBase, ModuleMeta
10
- from simple_module_hosting.inertia_deps import InertiaDep
10
+ from simple_module_hosting.frontend.inertia_deps import InertiaDep
11
11
  from simple_module_inertia import (
12
12
  InertiaConfig,
13
13
  defer,
@@ -1,88 +0,0 @@
1
- """Public pytest assertion for the standard module package and test layout."""
2
-
3
- from __future__ import annotations
4
-
5
- import tomllib
6
- from collections.abc import Collection
7
- from pathlib import Path
8
-
9
- ALLOWED_ROOT = frozenset(
10
- {
11
- "__init__.py",
12
- "__main__.py",
13
- "py.typed",
14
- "module.py",
15
- "models.py",
16
- "models",
17
- "tasks.py",
18
- "task_config.py",
19
- "contracts",
20
- "pages",
21
- "locales",
22
- "theme.css",
23
- "styles.css",
24
- "cli.py",
25
- "core",
26
- "web",
27
- "ui",
28
- }
29
- )
30
-
31
-
32
- def _is_layout_shim(path: Path) -> bool:
33
- """A moved module's old path: a deprecated alias, allowed until its remove_in."""
34
- text = path.read_text(encoding="utf-8")
35
- return "deprecated_module(" in text and "sys.modules[__name__]" in text
36
-
37
-
38
- def _only_bytecode(path: Path) -> bool:
39
- """A directory an older checkout left behind holding only ``__pycache__``."""
40
- return all(child.name == "__pycache__" for child in path.iterdir())
41
-
42
-
43
- def _is_shim_package(path: Path) -> bool:
44
- """An old package path kept only for its aliases: shims plus a docstring __init__."""
45
- files = [f for f in path.glob("*.py") if f.name != "__init__.py"]
46
- return bool(files) and all(_is_layout_shim(f) for f in files)
47
-
48
-
49
- def assert_module_layout(
50
- project: Path,
51
- package_name: str,
52
- *,
53
- domain_areas: Collection[str] = (),
54
- deprecated_root: Collection[str] = (),
55
- ) -> None:
56
- """Check a module project (package + tests + pyproject.toml).
57
-
58
- Pass named domain directories and any temporary deprecated root files.
59
- Test basenames may repeat: the plugin defaults to importlib mode.
60
- """
61
- package = project / package_name
62
- assert package.is_dir(), f"Missing package for {package_name}"
63
- entries = {
64
- p.name
65
- for p in package.iterdir()
66
- if (p.suffix == ".py" and not _is_layout_shim(p))
67
- or (
68
- p.is_dir()
69
- and p.name != "__pycache__"
70
- and not _only_bytecode(p)
71
- and not _is_shim_package(p)
72
- )
73
- }
74
- deprecated = frozenset(deprecated_root)
75
- assert deprecated <= {p.name for p in package.iterdir()}, (
76
- f"{package_name}: remove expired DEPRECATED_ROOT entries"
77
- )
78
- allowed = ALLOWED_ROOT | frozenset(domain_areas) | deprecated
79
- assert not entries - allowed, f"{package_name}: unexpected roots {entries - allowed}"
80
- if (package / "cli.py").is_file():
81
- metadata = tomllib.loads((project / "pyproject.toml").read_text())["project"]
82
- targets = [
83
- value for group in metadata.get("entry-points", {}).values() for value in group.values()
84
- ]
85
- assert any(value.split(":")[0] == f"{package_name}.cli" for value in targets)
86
- # Tests mirror the package areas: tests/<area>/<feature>/test_*.py.
87
- assert not list((project / "tests").glob("test_*.py")), package_name
88
- assert not list((project / "tests").rglob("__init__.py")), package_name
@@ -1,32 +0,0 @@
1
- """Consumers can enforce module layout without copying the framework's test."""
2
-
3
- import pytest
4
-
5
-
6
- def test_public_layout_helper_allows_duplicate_test_basenames(tmp_path):
7
- from simple_module_test import assert_module_layout
8
-
9
- package = tmp_path / "orders"
10
- (package / "core").mkdir(parents=True)
11
- (package / "__main__.py").touch()
12
- for area in ("core", "web"):
13
- tests = tmp_path / "tests" / area / "crud"
14
- tests.mkdir(parents=True)
15
- (tests / "test_crud.py").touch()
16
- (package / "fulfillment").mkdir()
17
- (package / "fulfillment" / "service.py").touch()
18
- assert_module_layout(tmp_path, "orders", domain_areas={"fulfillment"})
19
-
20
-
21
- @pytest.mark.parametrize(
22
- "bad_path", ["orders/service.py", "tests/test_orders.py", "tests/__init__.py"]
23
- )
24
- def test_public_layout_helper_rejects_layout_drift(tmp_path, bad_path):
25
- from simple_module_test import assert_module_layout
26
-
27
- (tmp_path / "orders").mkdir()
28
- target = tmp_path / bad_path
29
- target.parent.mkdir(parents=True, exist_ok=True)
30
- target.touch()
31
- with pytest.raises(AssertionError):
32
- assert_module_layout(tmp_path, "orders")