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"""
6Purpose
7-------
8OI-525 regression tests — ``oct.core.diagnostics`` must provide a single
9``_dbg`` entry point that re-binds ``oc_diagnostics._dbg`` when available
10and falls back to a silent no-op stub otherwise. This eliminates the
11duplicated per-module try/except that previously existed in every
12``oct/git/*.py`` file.
13
14Responsibilities
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
24Diagnostics
25-----------
26Domain: CORE-TESTS
27Levels:
28 L2 — test lifecycle
29 L3 — assertion details
30 L4 — deep tracing
31
32Contracts
33---------
34- Signature must match ``oc_diagnostics._dbg`` so callers can switch
35 transparently.
36"""
37
38import importlib
39import sys
40
41import pytest
42
43
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
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
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