diff --git a/noScribe/main.py b/noScribe/main.py index e935170f..bc0b8d71 100644 --- a/noScribe/main.py +++ b/noScribe/main.py @@ -2116,7 +2116,8 @@ def _append_log_text(self, txt, tags, link, tb, where): self.log_textbox.delete("1.0", f"1.0 + {self.log_len - 3000} chars") self.log_len = 3000 if link: - tags = tags + self.hyperlink.add(partial(self.openLink, link)) + # A single tag comes as a string ('error'), several as a list. + tags = ([tags] if isinstance(tags, str) else tags) + self.hyperlink.add(partial(self.openLink, link)) self.log_textbox.insert(tk.END, txt, tags) self.log_textbox.yview_moveto(1) self.log_len += len(txt) diff --git a/tests/test_log_link.py b/tests/test_log_link.py new file mode 100644 index 00000000..b085455f --- /dev/null +++ b/tests/test_log_link.py @@ -0,0 +1,57 @@ +"""A log line with a link and a single tag given as a string. + +`logn(t('rescue_saving', ...), 'error', link=...)` -- the notice that the +transcript could not be written under its name and was saved under another -- +failed in the window: `'error' + ['hyper', 'hyper-0']` raised a TypeError, which +_append_log_text caught and wrote to the log file instead. So the only notice of +where a failed job's partial transcript went never appeared on screen. +""" +import queue +import threading + +import pytest + +pytest.importorskip("tkinter") + +from noScribe.main import App + + +class _Textbox: + def __init__(self): + self.inserted = [] + + def winfo_exists(self): + return True + + def configure(self, **kwargs): + pass + + def insert(self, index, txt, tags=None): + self.inserted.append((txt, tags)) + + def yview_moveto(self, fraction): + pass + + +class _Hyperlinks: + def add(self, action): + return ["hyper", "hyper-0"] + + +@pytest.mark.parametrize("tags", ["error", ["error"]]) +def test_link_with_a_tag_reaches_the_window(tags): + app = object.__new__(App) + app._headless = False + app._shutting_down = False + app._ui_thread_id = threading.get_ident() + app._ui_tasks = queue.Queue() + app.log_file = None + app.log_len = 0 + app.log_textbox = _Textbox() + app.hyperlink = _Hyperlinks() + + app.log("Saved as transcript (1).html\n", tags, link="file://transcript (1).html") + + assert app.log_textbox.inserted == [ + ("Saved as transcript (1).html\n", ["error", "hyper", "hyper-0"]) + ]