Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion noScribe/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
57 changes: 57 additions & 0 deletions tests/test_log_link.py
Original file line number Diff line number Diff line change
@@ -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"])
]
Loading