Files
Athena-Deck/test_audio_cpp_runtime.py

45 lines
2.2 KiB
Python

import json
from pathlib import Path
import tempfile
import time
import unittest
from unittest.mock import patch
from audio_cpp_runtime import AudioCppRuntime,REVISION
class AudioCppTests(unittest.TestCase):
def test_marker_cannot_escape_root(self):
with tempfile.TemporaryDirectory() as root:
Path(root,'active.json').write_text(json.dumps({'id':'../../outside'}))
self.assertFalse(AudioCppRuntime(root).status()['installed'])
def test_build_failure_is_not_published(self):
with tempfile.TemporaryDirectory() as root:
runtime=AudioCppRuntime(root);runtime.job=dict(id='a'*32,state='running')
with patch.object(runtime,'_command',side_effect=RuntimeError('synthetic failure')):runtime._run()
self.assertEqual(runtime.job['state'],'failed')
self.assertFalse(runtime.status()['installed'])
self.assertFalse(Path(root,'a'*32,'ready').exists())
def test_publish_only_after_cli_smoke_and_spec(self):
with tempfile.TemporaryDirectory() as root:
runtime=AudioCppRuntime(root);runtime.job=dict(id='a'*32,state='running');commands=[]
def command(args,env):
commands.append([str(a) for a in args])
base=Path(root,'a'*32)
if str(args[0])=='cmake' and '--build' in args:
(base/'source/model_specs').mkdir(parents=True)
(base/'source/model_specs/yue2.json').write_text('{}')
(base/'build/bin').mkdir(parents=True)
(base/'build/bin/audiocpp_cli').touch()
with patch.object(runtime,'_command',side_effect=command),patch('subprocess.check_output',return_value='12.0\n8.6\n'):runtime._run()
self.assertEqual(runtime.job['state'],'complete')
self.assertTrue(runtime.status()['installed'])
self.assertTrue(runtime.status()['adapter_ready'])
self.assertIn('-DCMAKE_CUDA_ARCHITECTURES=120;86',commands[3])
self.assertEqual(commands[-1][-1],'--help')
self.assertEqual(Path(root,'a'*32,'ready').read_text(),REVISION)
def test_missing_prerequisites_dont_start_thread(self):
with tempfile.TemporaryDirectory() as root:
runtime=AudioCppRuntime(root)
with patch('audio_cpp_runtime.sys.platform','linux'),patch('audio_cpp_runtime.shutil.which',return_value=None):
with self.assertRaisesRegex(ValueError,'Build-Werkzeuge fehlen'):runtime.start()
self.assertIsNone(runtime.worker)