Files

51 lines
1.3 KiB
Python
Raw Permalink Normal View History

import queue
import tqdm as tqdm_module
from whisper_local.tray._download_progress import TkProgressTqdm
class TestTkProgressTqdm:
def teardown_method(self):
TkProgressTqdm._queue = None
def test_update_puts_message_in_queue(self):
q = queue.Queue()
TkProgressTqdm._queue = q
bar = TkProgressTqdm(total=1000, desc="model.bin", disable=True)
bar.update(300)
bar.close()
TkProgressTqdm._queue = None
msg = q.get_nowait()
assert msg["file"] == "model.bin"
assert msg["n"] == 300
assert msg["total"] == 1000
def test_update_without_queue_does_not_raise(self):
TkProgressTqdm._queue = None
bar = TkProgressTqdm(total=100, desc="test.bin", disable=True)
bar.update(50) # darf nicht crashen
bar.close()
def test_multiple_updates_accumulate(self):
q = queue.Queue()
TkProgressTqdm._queue = q
bar = TkProgressTqdm(total=1000, desc="file.bin", disable=True)
bar.update(200)
bar.update(300)
bar.close()
TkProgressTqdm._queue = None
msgs = []
while not q.empty():
msgs.append(q.get_nowait())
assert len(msgs) == 2
assert msgs[0]["n"] == 200
assert msgs[1]["n"] == 500 # tqdm akkumuliert: 200+300