-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
73 lines (59 loc) · 2.42 KB
/
Copy pathconftest.py
File metadata and controls
73 lines (59 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Copyright © 2025 Justin K. Lietz, Neuroca, Inc. All Rights Reserved.
This research is protected under a dual-license to foster open academic
research while ensuring commercial applications are aligned with the project's ethical principles.
Commercial use of proprietary VDM code requires written permission from Justin K. Lietz.
See LICENSE file for full terms.
Pytest configuration shim to normalize imports.
- Ensures the repository root is present on sys.path so imports like
`Prometheus_VDM.*` and `vdm_rt.*` resolve reliably during test collection.
"""
import os
import sys
REPO_ROOT = os.path.abspath(os.path.dirname(__file__))
if REPO_ROOT not in sys.path:
sys.path.insert(0, REPO_ROOT)
# Historical import aliases: map Prometheus_VDM.derivation.* -> Derivation.*
import types as _types
import importlib as _importlib
def _alias_module(src: str, dst: str) -> None:
"""Alias module name 'src' to real module 'dst' for import compatibility.
Creates parent chain and sets attributes so deep imports continue to work.
"""
real = _importlib.import_module(dst)
parts = src.split('.')
# Ensure top-level package exists as a package module
top = parts[0]
if top not in sys.modules:
top_mod = _types.ModuleType(top)
top_mod.__path__ = [] # mark as pkg
sys.modules[top] = top_mod
parent_mod = sys.modules[top]
# Walk/build chain and attach real module at the leaf
accum = top
for i in range(1, len(parts)):
subname = parts[i]
accum = f"{accum}.{subname}"
is_leaf = (i == len(parts) - 1)
child = sys.modules.get(accum)
if child is None:
child = real if is_leaf else _types.ModuleType(accum)
if not is_leaf:
child.__path__ = [] # treat as pkg
sys.modules[accum] = child
setattr(parent_mod, subname, child)
parent_mod = child
# Also register the src alias directly
sys.modules[src] = real
# Best-effort aliasing; skip silently if the target package is missing at runtime
for _src, _dst in (
('Prometheus_VDM.derivation', 'Derivation'),
('Prometheus_VDM.derivation.code', 'Derivation.code'),
('Prometheus_VDM.derivation.code.physics', 'Derivation.code.physics'),
('Prometheus_VDM.derivation.code.physics.reaction_diffusion', 'Derivation.code.physics.reaction_diffusion'),
('Prometheus_VDM.derivation.code.physics.fluid_dynamics', 'Derivation.code.physics.fluid_dynamics'),
):
try:
_alias_module(_src, _dst)
except ModuleNotFoundError:
continue