Skip to content

Commit 0df6220

Browse files
committed
ruff format
1 parent 4678d58 commit 0df6220

2 files changed

Lines changed: 44 additions & 93 deletions

File tree

pywry/pywry/__main__.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,7 @@ def _handle_ready_event(ipc: JsonIPC, app_handle: Any) -> None:
803803
ipc.send_ready()
804804

805805

806-
def _handle_close_requested(
807-
ipc: JsonIPC, app_handle: Any, label: str, window_event: Any
808-
) -> None:
806+
def _handle_close_requested(ipc: JsonIPC, app_handle: Any, label: str, window_event: Any) -> None:
809807
"""Handle window close requested event."""
810808
# User clicked X - behavior depends on window mode:
811809
# - SINGLE_WINDOW: Always hide (reuse the window)
@@ -831,16 +829,12 @@ def _handle_close_requested(
831829
window.destroy()
832830
if label in ipc.windows:
833831
del ipc.windows[label]
834-
ipc.send(
835-
{"type": "event", "event_type": "window:closed", "label": label, "data": {}}
836-
)
832+
ipc.send({"type": "event", "event_type": "window:closed", "label": label, "data": {}})
837833
else:
838834
log(f"CloseRequested for '{label}' - hiding")
839835
if window:
840836
window.hide()
841-
ipc.send(
842-
{"type": "event", "event_type": "window:hidden", "label": label, "data": {}}
843-
)
837+
ipc.send({"type": "event", "event_type": "window:hidden", "label": label, "data": {}})
844838

845839

846840
def main() -> int: # pylint: disable=too-many-statements
@@ -883,10 +877,7 @@ def on_run(app_handle: Any, run_event: Any) -> None:
883877
label = run_event.label
884878
if isinstance(window_event, WindowEvent.CloseRequested):
885879
_handle_close_requested(ipc, app_handle, label, window_event)
886-
elif (
887-
isinstance(window_event, WindowEvent.Destroyed)
888-
and label in ipc.windows
889-
):
880+
elif isinstance(window_event, WindowEvent.Destroyed) and label in ipc.windows:
890881
del ipc.windows[label]
891882
log(f"Window '{label}' destroyed, removed from cache")
892883

pywry/tests/test_e2e.py

Lines changed: 40 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -134,47 +134,43 @@ def verify_theme_and_rendering(label: str, expect_dark: bool) -> dict:
134134

135135
# Validate theme coordination
136136
if expect_dark:
137-
assert result[
138-
"windowIsDark"
139-
], f"Window should be DARK! Got: {result['htmlClass']}"
137+
assert result["windowIsDark"], f"Window should be DARK! Got: {result['htmlClass']}"
140138
if result["hasGrid"]:
141-
assert result[
142-
"gridIsDark"
143-
], f"Grid MUST be dark when window is dark! Got: {result['gridThemeClass']}"
139+
assert result["gridIsDark"], (
140+
f"Grid MUST be dark when window is dark! Got: {result['gridThemeClass']}"
141+
)
144142
if result["hasPlotly"]:
145143
# Verify applied colors match plotly_dark template FROM THE SOURCE
146144
actual_paper = result.get("plotlyPaperBg")
147145
actual_plot = result.get("plotlyPlotBg")
148146
expected_paper = result.get("expectedDarkPaperBg")
149147
expected_plot = result.get("expectedDarkPlotBg")
150148
assert expected_paper is not None, "plotly_dark template not loaded!"
151-
assert (
152-
actual_paper == expected_paper
153-
), f"paper_bgcolor MUST match plotly_dark template! Expected: '{expected_paper}', Got: '{actual_paper}'"
154-
assert (
155-
actual_plot == expected_plot
156-
), f"plot_bgcolor MUST match plotly_dark template! Expected: '{expected_plot}', Got: '{actual_plot}'"
149+
assert actual_paper == expected_paper, (
150+
f"paper_bgcolor MUST match plotly_dark template! Expected: '{expected_paper}', Got: '{actual_paper}'"
151+
)
152+
assert actual_plot == expected_plot, (
153+
f"plot_bgcolor MUST match plotly_dark template! Expected: '{expected_plot}', Got: '{actual_plot}'"
154+
)
157155
else:
158-
assert result[
159-
"windowIsLight"
160-
], f"Window should be LIGHT! Got: {result['htmlClass']}"
156+
assert result["windowIsLight"], f"Window should be LIGHT! Got: {result['htmlClass']}"
161157
if result["hasGrid"]:
162-
assert not result[
163-
"gridIsDark"
164-
], f"Grid MUST be light when window is light! Got: {result['gridThemeClass']}"
158+
assert not result["gridIsDark"], (
159+
f"Grid MUST be light when window is light! Got: {result['gridThemeClass']}"
160+
)
165161
if result["hasPlotly"]:
166162
# Verify applied colors match plotly_white template FROM THE SOURCE
167163
actual_paper = result.get("plotlyPaperBg")
168164
actual_plot = result.get("plotlyPlotBg")
169165
expected_paper = result.get("expectedLightPaperBg")
170166
expected_plot = result.get("expectedLightPlotBg")
171167
assert expected_paper is not None, "plotly_white template not loaded!"
172-
assert (
173-
actual_paper == expected_paper
174-
), f"paper_bgcolor MUST match plotly_white template! Expected: '{expected_paper}', Got: '{actual_paper}'"
175-
assert (
176-
actual_plot == expected_plot
177-
), f"plot_bgcolor MUST match plotly_white template! Expected: '{expected_plot}', Got: '{actual_plot}'"
168+
assert actual_paper == expected_paper, (
169+
f"paper_bgcolor MUST match plotly_white template! Expected: '{expected_paper}', Got: '{actual_paper}'"
170+
)
171+
assert actual_plot == expected_plot, (
172+
f"plot_bgcolor MUST match plotly_white template! Expected: '{expected_plot}', Got: '{actual_plot}'"
173+
)
178174

179175
return result
180176

@@ -200,9 +196,7 @@ def test_dark_dataframe(self, dark_app):
200196
def test_dark_plotly(self, dark_app):
201197
"""DARK show_plotly renders with DARK template."""
202198
figure = {"data": [{"x": [1, 2, 3], "y": [10, 15, 13], "type": "scatter"}]}
203-
label = show_plotly_and_wait_ready(
204-
dark_app, figure, title="Dark+Plotly", timeout=20.0
205-
)
199+
label = show_plotly_and_wait_ready(dark_app, figure, title="Dark+Plotly", timeout=20.0)
206200
# Plotly renders asynchronously after DOM is ready (longer wait for WebKitGTK)
207201
time.sleep(1.5)
208202

@@ -290,9 +284,9 @@ def test_single_window_mode_reuses(self):
290284
});
291285
""",
292286
)
293-
assert (
294-
result and isinstance(result, dict) and result["hasSecond"]
295-
), f"Second content not rendered! Got: {result}"
287+
assert result and isinstance(result, dict) and result["hasSecond"], (
288+
f"Second content not rendered! Got: {result}"
289+
)
296290
app.close()
297291

298292
def test_new_window_mode_creates_multiple(self):
@@ -302,12 +296,8 @@ def test_new_window_mode_creates_multiple(self):
302296
label2 = show_and_wait_ready(app, "<div id='win2'>W2</div>")
303297
assert label1 != label2, "NEW_WINDOW should create unique labels!"
304298

305-
r1 = wait_for_result(
306-
label1, "pywry.result({ has: !!document.getElementById('win1') });"
307-
)
308-
r2 = wait_for_result(
309-
label2, "pywry.result({ has: !!document.getElementById('win2') });"
310-
)
299+
r1 = wait_for_result(label1, "pywry.result({ has: !!document.getElementById('win1') });")
300+
r2 = wait_for_result(label2, "pywry.result({ has: !!document.getElementById('win2') });")
311301
assert r1 and isinstance(r1, dict) and r1["has"], "Window 1 content missing!"
312302
assert r2 and isinstance(r2, dict) and r2["has"], "Window 2 content missing!"
313303
app.close()
@@ -322,9 +312,7 @@ def test_toolbar_renders_correctly(self):
322312
toolbars = [
323313
{
324314
"position": "top",
325-
"items": [
326-
{"type": "button", "label": "MyButton", "event": "toolbar:click"}
327-
],
315+
"items": [{"type": "button", "label": "MyButton", "event": "toolbar:click"}],
328316
}
329317
]
330318

@@ -396,9 +384,7 @@ def test_toolbar_html_buttons_work(self):
396384
# Event tracking
397385
events = {"clicked": False}
398386

399-
def on_click(
400-
data: dict, event_type: str, widget_id: str
401-
) -> None: # pylint: disable=unused-argument
387+
def on_click(data: dict, event_type: str, widget_id: str) -> None: # pylint: disable=unused-argument
402388
events["clicked"] = True
403389
events["data"] = data
404390

@@ -434,9 +420,7 @@ def test_toolbar_plotly_buttons_work(self):
434420

435421
events = {"clicked": False}
436422

437-
def on_click(
438-
data: dict, event_type: str, widget_id: str
439-
) -> None: # pylint: disable=unused-argument
423+
def on_click(data: dict, event_type: str, widget_id: str) -> None: # pylint: disable=unused-argument
440424
events["clicked"] = True
441425

442426
toolbars = [
@@ -478,9 +462,7 @@ def test_toolbar_dataframe_buttons_work(self):
478462

479463
events = {"clicked": False}
480464

481-
def on_click(
482-
data: dict, event_type: str, widget_id: str
483-
) -> None: # pylint: disable=unused-argument
465+
def on_click(data: dict, event_type: str, widget_id: str) -> None: # pylint: disable=unused-argument
484466
events["clicked"] = True
485467

486468
toolbars = [
@@ -568,9 +550,7 @@ def on_select(data):
568550
time.sleep(0.1)
569551

570552
assert events["received"], "Select change event not received"
571-
assert (
572-
events["data"]["value"] == "b"
573-
), f"Expected value 'b', got {events['data']}"
553+
assert events["data"]["value"] == "b", f"Expected value 'b', got {events['data']}"
574554
app.close()
575555

576556
def test_multiselect_triggers_event_with_values_array(self):
@@ -601,9 +581,7 @@ def on_multiselect(data):
601581
}
602582
]
603583

604-
label = show_and_wait_ready(
605-
app, "<div>MultiSelect Test</div>", toolbars=toolbars
606-
)
584+
label = show_and_wait_ready(app, "<div>MultiSelect Test</div>", toolbars=toolbars)
607585
get_registry().register(label, "test:multiselect", on_multiselect)
608586

609587
# First open the multiselect dropdown, then click on the 'green' option
@@ -907,9 +885,7 @@ def on_left(data):
907885
},
908886
]
909887

910-
label = show_and_wait_ready(
911-
app, "<div>Multi-toolbar Test</div>", toolbars=toolbars
912-
)
888+
label = show_and_wait_ready(app, "<div>Multi-toolbar Test</div>", toolbars=toolbars)
913889
get_registry().register(label, "top:click", on_top)
914890
get_registry().register(label, "bottom:select", on_bottom)
915891
get_registry().register(label, "left:range", on_left)
@@ -936,18 +912,12 @@ def on_left(data):
936912

937913
start = time.time()
938914
while (time.time() - start) < 4.0:
939-
if (
940-
events["top_btn"]
941-
and events["bottom_select"]
942-
and events["left_range"] is not None
943-
):
915+
if events["top_btn"] and events["bottom_select"] and events["left_range"] is not None:
944916
break
945917
time.sleep(0.1)
946918

947919
assert events["top_btn"], "Top button event not received"
948-
assert (
949-
events["bottom_select"] == "y"
950-
), f"Bottom select: {events['bottom_select']}"
920+
assert events["bottom_select"] == "y", f"Bottom select: {events['bottom_select']}"
951921
assert events["left_range"] == 75, f"Left range: {events['left_range']}"
952922
app.close()
953923

@@ -988,9 +958,7 @@ def on_number(data):
988958
}
989959
]
990960

991-
label = show_and_wait_ready(
992-
app, "<div>Multi-item Toolbar</div>", toolbars=toolbars
993-
)
961+
label = show_and_wait_ready(app, "<div>Multi-item Toolbar</div>", toolbars=toolbars)
994962
get_registry().register(label, "action:one", on_btn1)
995963
get_registry().register(label, "action:two", on_btn2)
996964
get_registry().register(label, "filter:mode", on_select)
@@ -1025,9 +993,7 @@ def on_number(data):
1025993

1026994
start = time.time()
1027995
while (time.time() - start) < 4.0:
1028-
if all(
1029-
[events["btn1"], events["btn2"], events["select"], events["number"]]
1030-
):
996+
if all([events["btn1"], events["btn2"], events["select"], events["number"]]):
1031997
break
1032998
time.sleep(0.1)
1033999

@@ -1066,9 +1032,7 @@ def on_view(data):
10661032
],
10671033
)
10681034

1069-
label = show_and_wait_ready(
1070-
app, "<div>Pydantic Toolbar</div>", toolbars=[toolbar]
1071-
)
1035+
label = show_and_wait_ready(app, "<div>Pydantic Toolbar</div>", toolbars=[toolbar])
10721036
get_registry().register(label, "data:export", on_export)
10731037
get_registry().register(label, "view:change", on_view)
10741038

@@ -1096,9 +1060,7 @@ def on_view(data):
10961060
# Event data contains the custom data from the button's data attribute
10971061
export_data = events["export"]
10981062
assert export_data is not None, "Export event not received"
1099-
assert isinstance(
1100-
export_data, dict
1101-
), f"Export data should be dict: {export_data}"
1063+
assert isinstance(export_data, dict), f"Export data should be dict: {export_data}"
11021064
assert export_data["format"] == "csv", f"Export data: {export_data}"
11031065
# Note: Button emits only its custom data, not componentId (unlike inputs)
11041066
assert events["view"] == "chart", f"View: {events['view']}"
@@ -1125,9 +1087,7 @@ def test_component_ids_are_unique_across_toolbars(self):
11251087
],
11261088
)
11271089

1128-
label = show_and_wait_ready(
1129-
app, "<div>ID Test</div>", toolbars=[toolbar1, toolbar2]
1130-
)
1090+
label = show_and_wait_ready(app, "<div>ID Test</div>", toolbars=[toolbar1, toolbar2])
11311091

11321092
# Verify unique IDs exist in DOM - just check that both toolbars render
11331093
result = wait_for_result(

0 commit comments

Comments
 (0)