Option C oc_diagnostics
Loading...
Searching...
No Matches
test_ui_event_logger.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# tests/test_ui_event_logger.py
4
5"""
6Regression Tests — ui_event_logger
7=====================================
8
9Purpose
10-------
11Verify that ``ui_event_logger`` imports cleanly, exposes the required public
12API surface, and registers callbacks correctly with custom event properties.
13
14Responsibilities
15----------------
16- Confirm the module imports without error and exposes ``register_callbacks()``.
17- Confirm ``REQUIRED_STORE_ID`` has the expected constant value.
18- Confirm ``register_callbacks()`` accepts a custom ``UI_EVENT_PROPERTIES``
19 tuple with fewer properties than the default five.
20
21Diagnostics
22-----------
23Domain: TEST
24Levels:
25 L2 — lifecycle
26 L3 — semantic details
27 L4 — deep tracing
28
29Contracts
30---------
31- All tests are skipped automatically when Dash is not installed.
32- Must not permanently modify oc_diagnostics global state.
33- Must restore all patched globals in finally blocks.
34- Must not start servers or require network access.
35- Must run deterministically across repeated invocations.
36"""
37
38import os
39import sys
40
41# ---------------------------------------------------------------------------
42# Ensure oc_diagnostics is importable when run from the project root or the
43# tests/ subdirectory.
44# ---------------------------------------------------------------------------
45_REPO_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))
46if _REPO_ROOT not in sys.path:
47 sys.path.insert(0, _REPO_ROOT)
48
49import pytest
50
51# Skip the entire module when Dash is not installed
52pytest.importorskip("dash", reason="Dash not installed")
53
54from dash import Dash, dcc, html
56import oc_diagnostics.ui_event_logger as _uelog
57from oc_diagnostics.ui_event_logger import register_callbacks, REQUIRED_STORE_ID
58
59
60# ============================================================
61# IMPORT AND PUBLIC API
62# ============================================================
63
65 """ui_event_logger module imports cleanly and exposes register_callbacks()."""
66 assert hasattr(_uelog, "register_callbacks"), (
67 "ui_event_logger must expose register_callbacks()"
68 )
69
70
71# ============================================================
72# REQUIRED_STORE_ID CONSTANT
73# ============================================================
74
76 """REQUIRED_STORE_ID has the expected constant value."""
77 assert REQUIRED_STORE_ID == "debug-settings-data-store", (
78 f"Expected 'debug-settings-data-store', got {REQUIRED_STORE_ID!r}"
79 )
80
81
82# ============================================================
83# CUSTOM UI_EVENT_PROPERTIES (OI-28)
84# ============================================================
85
87 """register_callbacks() accepts UI_EVENT_PROPERTIES with a reduced property set."""
88 old_props = _ud.UI_EVENT_PROPERTIES
89 try:
90 _ud.UI_EVENT_PROPERTIES = ("n_clicks", "value") # 2 props instead of default 5
91 app = Dash(__name__)
92 app.layout = html.Div([
93 dcc.Store(id="debug-settings-data-store", storage_type="memory"),
94 ])
95 register_callbacks(app) # must not raise TypeError
96 assert len(app.callback_map) >= 1, (
97 "Expected at least one registered callback with 2-prop UI_EVENT_PROPERTIES"
98 )
99 finally:
100 _ud.UI_EVENT_PROPERTIES = old_props