Fix tests

This commit is contained in:
Miguel Jacq 2025-11-10 10:54:17 +11:00
parent fd70ec9777
commit 61e37b7669
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9

View file

@ -59,7 +59,6 @@ def test_toolbar_signals_dispatch_once_per_click(
tb = w.toolBar tb = w.toolBar
# Spy on the first tab's editor # Spy on the first tab's editor
ed1 = w.current_editor()
calls1 = { calls1 = {
"bold": 0, "bold": 0,
"italic": 0, "italic": 0,
@ -77,14 +76,14 @@ def test_toolbar_signals_dispatch_once_per_click(
return _spy return _spy
ed1.apply_weight = types.MethodType(mk("bold"), ed1) w.editor.apply_weight = types.MethodType(mk("bold"), w.editor)
ed1.apply_italic = types.MethodType(mk("italic"), ed1) w.editor.apply_italic = types.MethodType(mk("italic"), w.editor)
ed1.apply_strikethrough = types.MethodType(mk("strike"), ed1) w.editor.apply_strikethrough = types.MethodType(mk("strike"), w.editor)
ed1.apply_code = types.MethodType(mk("code"), ed1) w.editor.apply_code = types.MethodType(mk("code"), w.editor)
ed1.apply_heading = types.MethodType(mk("heading"), ed1) w.editor.apply_heading = types.MethodType(mk("heading"), w.editor)
ed1.toggle_bullets = types.MethodType(mk("bullets"), ed1) w.editor.toggle_bullets = types.MethodType(mk("bullets"), w.editor)
ed1.toggle_numbers = types.MethodType(mk("numbers"), ed1) w.editor.toggle_numbers = types.MethodType(mk("numbers"), w.editor)
ed1.toggle_checkboxes = types.MethodType(mk("checkboxes"), ed1) w.editor.toggle_checkboxes = types.MethodType(mk("checkboxes"), w.editor)
# Click all the things once # Click all the things once
tb.boldRequested.emit() tb.boldRequested.emit()
@ -101,10 +100,9 @@ def test_toolbar_signals_dispatch_once_per_click(
# Switch to a new tab and make sure clicks go ONLY to the active editor # Switch to a new tab and make sure clicks go ONLY to the active editor
date2 = w.calendar.selectedDate().addDays(1) date2 = w.calendar.selectedDate().addDays(1)
w._open_date_in_tab(date2) w._open_date_in_tab(date2)
ed2 = w.current_editor()
calls2 = {"bold": 0} calls2 = {"bold": 0}
ed2.apply_weight = types.MethodType( w.editor.apply_weight = types.MethodType(
lambda self: calls2.__setitem__("bold", calls2["bold"] + 1), ed2 lambda self: calls2.__setitem__("bold", calls2["bold"] + 1), w.editor
) )
tb.boldRequested.emit() tb.boldRequested.emit()
@ -145,12 +143,11 @@ def test_history_and_insert_image_not_duplicated(
dummy = tmp_path / "x.png" dummy = tmp_path / "x.png"
dummy.write_bytes(b"\x89PNG\r\n\x1a\n") dummy.write_bytes(b"\x89PNG\r\n\x1a\n")
inserted = {"count": 0} inserted = {"count": 0}
ed = w.current_editor()
def fake_insert(self, p): def fake_insert(self, p):
inserted["count"] += 1 inserted["count"] += 1
ed.insert_image_from_path = types.MethodType(fake_insert, ed) w.editor.insert_image_from_path = types.MethodType(fake_insert, w.editor)
monkeypatch.setattr( monkeypatch.setattr(
QFileDialog, QFileDialog,
"getOpenFileNames", "getOpenFileNames",
@ -172,10 +169,9 @@ def test_highlighter_attached_after_text_load(qtbot, app, tmp_db_cfg, fresh_db):
qtbot.addWidget(w) qtbot.addWidget(w)
w.show() w.show()
ed = w.current_editor() w.editor.from_markdown("**bold**\n- [ ] task\n~~strike~~")
ed.from_markdown("**bold**\n- [ ] task\n~~strike~~") assert w.editor.highlighter is not None
assert ed.highlighter is not None assert w.editor.highlighter.document() is w.editor.document()
assert ed.highlighter.document() is ed.document()
@pytest.mark.gui @pytest.mark.gui
@ -190,18 +186,16 @@ def test_findbar_works_for_current_tab(qtbot, app, tmp_db_cfg, fresh_db):
w.show() w.show()
# Tab 1 content # Tab 1 content
ed1 = w.current_editor() w.editor.from_markdown("alpha bravo charlie")
ed1.from_markdown("alpha bravo charlie")
w.findBar.show_bar() w.findBar.show_bar()
w.findBar.edit.setText("bravo") w.findBar.edit.setText("bravo")
w.findBar.find_next() w.findBar.find_next()
assert ed1.textCursor().selectedText() == "bravo" assert w.editor.textCursor().selectedText() == "bravo"
# Tab 2 content (contains the query too) # Tab 2 content (contains the query too)
date2 = w.calendar.selectedDate().addDays(1) date2 = w.calendar.selectedDate().addDays(1)
w._open_date_in_tab(date2) w._open_date_in_tab(date2)
ed2 = w.current_editor() w.editor.from_markdown("x bravo y bravo z")
ed2.from_markdown("x bravo y bravo z") w.editor.moveCursor(QTextCursor.Start)
ed2.moveCursor(QTextCursor.Start)
w.findBar.find_next() w.findBar.find_next()
assert ed2.textCursor().selectedText() == "bravo" assert w.editor.textCursor().selectedText() == "bravo"