Option C Tools
Loading...
Searching...
No Matches
test_diagnostics_stub.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
# tests/tests_core/test_diagnostics_stub.py
4
5
"""
6
Purpose
7
-------
8
OI-525 regression tests — ``oct.core.diagnostics`` must provide a single
9
``_dbg`` entry point that re-binds ``oc_diagnostics._dbg`` when available
10
and falls back to a silent no-op stub otherwise. This eliminates the
11
duplicated per-module try/except that previously existed in every
12
``oct/git/*.py`` file.
13
14
Responsibilities
15
----------------
16
- Importing ``_dbg`` from ``oct.core.diagnostics`` never raises.
17
- The resolved ``_dbg`` is callable with ``(domain, func, msg, level)``
18
and arbitrary kwargs, and returns ``None``.
19
- When ``oc_diagnostics`` is importable, ``_dbg`` is the real callable
20
(``oc_diagnostics._dbg``) or a trivial bind of it — not a no-op shim.
21
- When ``oc_diagnostics`` is unavailable, a re-evaluated module exposes
22
a no-op fallback.
23
24
Diagnostics
25
-----------
26
Domain: CORE-TESTS
27
Levels:
28
L2 — test lifecycle
29
L3 — assertion details
30
L4 — deep tracing
31
32
Contracts
33
---------
34
- Signature must match ``oc_diagnostics._dbg`` so callers can switch
35
transparently.
36
"""
37
38
import
importlib
39
import
sys
40
41
import
pytest
42
43
44
def
test_dbg_importable_and_callable
():
45
from
oct.core.diagnostics
import
_dbg
46
func =
"test_dbg_importable_and_callable"
47
48
assert
callable(_dbg)
49
result = _dbg(
"OCT-CORE"
, func,
"probe message"
, 3, extra=
"ok"
)
50
assert
result
is
None
51
52
53
def
test_dbg_matches_oc_diagnostics_when_available
():
54
try
:
55
from
oc_diagnostics
import
_dbg
as
real_dbg
56
except
ImportError:
57
pytest.skip(
58
"oc_diagnostics._dbg not importable (namespace-package "
59
"shadowing or not installed)"
60
)
61
62
from
oct.core.diagnostics
import
_dbg
63
64
assert
_dbg
is
real_dbg
65
66
67
def
test_dbg_fallback_when_oc_diagnostics_missing
(monkeypatch):
68
func =
"test_dbg_fallback_when_oc_diagnostics_missing"
69
import
oct.core.diagnostics
as
mod
70
71
monkeypatch.setitem(sys.modules,
"oc_diagnostics"
,
None
)
72
sys.modules.pop(
"oct.core.diagnostics"
,
None
)
73
74
try
:
75
reloaded = importlib.import_module(
"oct.core.diagnostics"
)
76
assert
callable(reloaded._dbg)
77
assert
reloaded._dbg(
"X"
, func,
"z"
, 1)
is
None
78
finally
:
79
sys.modules[
"oct.core.diagnostics"
] = mod
tests_core.test_diagnostics_stub.test_dbg_fallback_when_oc_diagnostics_missing
test_dbg_fallback_when_oc_diagnostics_missing(monkeypatch)
Definition
test_diagnostics_stub.py:67
tests_core.test_diagnostics_stub.test_dbg_importable_and_callable
test_dbg_importable_and_callable()
Definition
test_diagnostics_stub.py:44
tests_core.test_diagnostics_stub.test_dbg_matches_oc_diagnostics_when_available
test_dbg_matches_oc_diagnostics_when_available()
Definition
test_diagnostics_stub.py:53
tests
tests_core
test_diagnostics_stub.py
Generated by
1.15.0