88 """apply_instrumentation() instruments each element of a list and preserves the type."""
89 old_enabled = _ud.INSTRUMENTATION_ENABLED
90 old_level = _ud.DEBUG_LEVELS.get(
"INSTRUMENTATION", 0)
91 _ud.INSTRUMENTATION_ENABLED =
True
92 _ud.DEBUG_LEVELS[
"INSTRUMENTATION"] = 9
94 comps = [html.Button(
"A", id=
"btn-a"), html.Div(
"B", id=
"div-b")]
95 result = apply_instrumentation(comps)
96 assert isinstance(result, list), f
"Expected list, got {type(result)}"
97 assert result[0].id == {
"event":
"btn-a"}, (
98 f
"Expected instrumented ID for list[0], got: {result[0].id!r}"
100 assert result[1].id == {
"event":
"div-b"}, (
101 f
"Expected instrumented ID for list[1], got: {result[1].id!r}"
104 _ud.INSTRUMENTATION_ENABLED = old_enabled
105 _ud.DEBUG_LEVELS[
"INSTRUMENTATION"] = old_level
113 """apply_instrumentation() instruments each element of a tuple and preserves the type."""
114 old_enabled = _ud.INSTRUMENTATION_ENABLED
115 old_level = _ud.DEBUG_LEVELS.get(
"INSTRUMENTATION", 0)
116 _ud.INSTRUMENTATION_ENABLED =
True
117 _ud.DEBUG_LEVELS[
"INSTRUMENTATION"] = 9
119 comps = (html.Button(
"X", id=
"btn-x"),)
120 result = apply_instrumentation(comps)
121 assert isinstance(result, tuple), f
"Expected tuple, got {type(result)}"
122 assert result[0].id == {
"event":
"btn-x"}, (
123 f
"Expected instrumented ID for tuple[0], got: {result[0].id!r}"
126 _ud.INSTRUMENTATION_ENABLED = old_enabled
127 _ud.DEBUG_LEVELS[
"INSTRUMENTATION"] = old_level
135 """apply_instrumentation() rewrites the ID of a single component."""
136 old_enabled = _ud.INSTRUMENTATION_ENABLED
137 old_level = _ud.DEBUG_LEVELS.get(
"INSTRUMENTATION", 0)
138 _ud.INSTRUMENTATION_ENABLED =
True
139 _ud.DEBUG_LEVELS[
"INSTRUMENTATION"] = 9
141 comp = html.Button(
"Solo", id=
"solo-btn")
142 result = apply_instrumentation(comp)
143 assert result.id == {
"event":
"solo-btn"}, (
144 f
"Expected instrumented ID, got: {result.id!r}"
147 _ud.INSTRUMENTATION_ENABLED = old_enabled
148 _ud.DEBUG_LEVELS[
"INSTRUMENTATION"] = old_level
156 """apply_instrumentation() does not re-wrap a component whose ID is already a dict."""
157 old_enabled = _ud.INSTRUMENTATION_ENABLED
158 old_level = _ud.DEBUG_LEVELS.get(
"INSTRUMENTATION", 0)
159 _ud.INSTRUMENTATION_ENABLED =
True
160 _ud.DEBUG_LEVELS[
"INSTRUMENTATION"] = 9
162 already_wrapped_id = {
"event":
"already-wrapped"}
163 comp = html.Button(
"Wrapped", id=already_wrapped_id)
164 result = apply_instrumentation(comp)
165 assert result.id == already_wrapped_id, (
166 f
"Dict ID must not be double-wrapped, got: {result.id!r}"
169 _ud.INSTRUMENTATION_ENABLED = old_enabled
170 _ud.DEBUG_LEVELS[
"INSTRUMENTATION"] = old_level