feat: TkProgressTqdm leitet tqdm-Fortschritt an Queue weiter
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import queue
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import tqdm as tqdm_module
|
||||
|
||||
from whisper_local.tray._download_progress import TkProgressTqdm
|
||||
|
||||
|
||||
class TestTkProgressTqdm:
|
||||
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
|
||||
Reference in New Issue
Block a user