Files
Athena-Deck/test_video.py
T
Mikei386 c0bc5d3a1b Integrate Basalt telemetry and shared GPU speech runtimes
Publish the reviewed accumulated runtime, scheduler, profile, UI, native recipes and historical maintenance evidence. Includes Qwen GPU ASR correction and shared Anna/atelier ownership. Validated with 784 local tests, Python/JSON parsing and eight JavaScript syntax checks. Live GPU acceptance and full fresh-host restore limits remain documented.
2026-11-03 21:16:41 +01:00

45 lines
2.9 KiB
Python

import tempfile
import unittest
from unittest.mock import Mock
from inference import Scheduler,InferenceError
from video import Video
class Helper:
def __init__(self):self.services=[dict(id='ltx',name='LTX',running=False,ready=False),dict(id='other',name='Other',running=False,ready=False)];self.actions=[];self.fail_start=False
def call(self,action,ident=None):
self.actions.append((action,ident))
if action=='video-status':return {'services':[dict(s) for s in self.services]}
if action=='video-start' and self.fail_start:raise ValueError('GPU belegt')
row=next(s for s in self.services if s['id']==ident);row['running']=row['ready']=action=='video-start';return dict(row)
class VideoTests(unittest.TestCase):
def test_video_waits_for_gpu_stt_and_evicts_only_after_release(self):
import time
with tempfile.TemporaryDirectory() as d:
helper=Helper();scheduler=Scheduler(Mock());scheduler.evict_stt=Mock();release=scheduler.stt_reservation()
video=Video(scheduler,Mock(),helper,d);video.select('ltx');video.switch('video');time.sleep(.05)
self.assertFalse(any(a=='video-start' for a,_ in helper.actions));scheduler.evict_stt.assert_not_called()
assert video.thread is not None
release();video.thread.join(2);self.assertFalse(video.thread.is_alive());self.assertEqual(video.status()['mode'],'video');scheduler.evict_stt.assert_called_once()
def test_switch_and_persistent_provider_selection(self):
with tempfile.TemporaryDirectory() as d:
h=Helper();stop=Mock();scheduler=Scheduler(Mock());v=Video(scheduler,stop,h,d)
v.select('ltx');self.assertEqual(Video(Scheduler(Mock()),Mock(),h,d).selected,'ltx')
v.switch('video');v.thread.join(3);self.assertEqual(v.status()['mode'],'video');stop.assert_called_once()
with self.assertRaises(InferenceError):
with scheduler.lease(('chat',)):pass
with self.assertRaises(ValueError):v.select('other')
v.switch('llm');v.thread.join(3);self.assertEqual(v.status()['mode'],'llm')
v.select('other');v.switch('video');v.thread.join(3);self.assertIn(('video-start','other'),h.actions)
def test_restart_adopts_running_service_without_stopping_it(self):
with tempfile.TemporaryDirectory() as d:
h=Helper();h.services[0].update(running=True,ready=True);v=Video(Scheduler(Mock()),Mock(),h,d)
self.assertEqual(v.status()['mode'],'video');v.close();self.assertFalse(any(a=='video-stop' for a,_ in h.actions))
def test_foreign_gpu_failure_reopens_llm_without_starting_service(self):
with tempfile.TemporaryDirectory() as d:
h=Helper();h.fail_start=True;v=Video(Scheduler(Mock()),Mock(),h,d);v.select('ltx');v.switch('video');v.thread.join(3)
self.assertEqual(v.status()['mode'],'llm');self.assertEqual(v.error,'GPU belegt')
def test_helper_loss_fails_closed_for_configured_service(self):
with tempfile.TemporaryDirectory() as d:
h=Helper();v=Video(Scheduler(Mock()),Mock(),h,d);v.select('ltx');h.call=Mock(side_effect=OSError())
self.assertEqual(v.status()['mode'],'video')