Spaces:
Running on Zero
Running on Zero
| """Basic tests for the AI Creative Studio & Moldovan AI Media Studio. | |
| These tests verify: | |
| - app.py and studio_server.py can be compiled and parsed syntactically. | |
| - The FastAPI endpoints exist and audio synthesizer functions properly. | |
| """ | |
| import os | |
| import sys | |
| import py_compile | |
| import pytest | |
| from pathlib import Path | |
| PROJECT_ROOT = Path(__file__).resolve().parent.parent | |
| sys.path.insert(0, str(PROJECT_ROOT)) | |
| sys.path.insert(0, str(PROJECT_ROOT / "moldovan-qwen")) | |
| def test_app_imports(): | |
| """Verify the app module can be parsed syntactically without errors.""" | |
| result = py_compile.compile(str(PROJECT_ROOT / "app.py"), doraise=True) | |
| assert result is not None and os.path.exists(result), f"app.py has syntax errors: {result}" | |
| def test_studio_server_imports(): | |
| """Verify the moldovan studio server can be parsed syntactically.""" | |
| server_path = PROJECT_ROOT / "moldovan-qwen" / "studio_server.py" | |
| result = py_compile.compile(str(server_path), doraise=True) | |
| assert result is not None and os.path.exists(result), f"studio_server.py syntax error: {result}" | |
| def test_audio_synthesizer_imports(): | |
| """Verify audio synthesizer module compiles.""" | |
| synth_path = PROJECT_ROOT / "moldovan-qwen" / "engine" / "audio_synthesizer.py" | |
| result = py_compile.compile(str(synth_path), doraise=True) | |
| assert result is not None and os.path.exists(result), f"audio_synthesizer.py syntax error: {result}" | |
| def test_native_audio_wav_generation(tmp_path): | |
| """Verify that native PCM WAV audio files are generated correctly.""" | |
| from engine.audio_synthesizer import MoldovanAudioSynthesizer | |
| synth = MoldovanAudioSynthesizer(output_dir=str(tmp_path)) | |
| res = synth.generate_track_audio("Test Beat", genre="Chișinău 808 Trap", bpm=140, bars=2) | |
| assert res["success"] is True | |
| assert os.path.exists(res["file_path"]) | |
| assert os.path.getsize(res["file_path"]) > 10000 | |
| def test_environment(): | |
| """Verify HF_TOKEN is set in environment (skip in CI/dev).""" | |
| token = os.getenv("HF_TOKEN") | |
| if token is None: | |
| pytest.skip("HF_TOKEN not set — skip in CI/dev environments") | |
| assert token is not None, "HF_TOKEN must be set" | |
| def test_api_endpoints_exist(): | |
| """Verify the API endpoints are defined in the module.""" | |
| app_source = (PROJECT_ROOT / "app.py").read_text() | |
| assert "/v1/health" in app_source, "Health endpoint not found in app.py" | |
| assert "/v1/gpu/status" in app_source, "GPU status endpoint not found in app.py" | |
| assert "/v1/chat/completions" in app_source, "Chat completions endpoint not found in app.py" | |
| def test_model_paths_exist(): | |
| """Verify model files exist on disk (HF Space mount).""" | |
| model_path = Path("/data/gemma-4-26B-A4B-it-ultra-uncensored-heretic.i1-Q4_K_M.gguf") | |
| if not model_path.exists(): | |
| pytest.skip(f"Model not found at {model_path} — expected on HF Spaces") | |
| assert model_path.exists(), f"Model not found at {model_path}" | |