forked from Rockachopa/Timmy-time-dashboard
Complete the module consolidation planned in REFACTORING_PLAN.md: Modules merged: - work_orders/ + task_queue/ → swarm/ (subpackages) - self_modify/ + self_tdd/ + upgrades/ → self_coding/ (subpackages) - tools/ → creative/tools/ - chat_bridge/ + telegram_bot/ + shortcuts/ + voice/ → integrations/ (new) - ws_manager/ + notifications/ + events/ + router/ → infrastructure/ (new) - agents/ + agent_core/ + memory/ → timmy/ (subpackages) Updated across codebase: - 66 source files: import statements rewritten - 13 test files: import + patch() target strings rewritten - pyproject.toml: wheel includes (28→14), entry points updated - CLAUDE.md: singleton paths, module map, entry points table - AGENTS.md: file convention updates - REFACTORING_PLAN.md: execution status, success metrics Extras: - Module-level CLAUDE.md added to 6 key packages (Phase 6.2) - Zero test regressions: 1462 tests passing https://claude.ai/code/session_01JNjWfHqusjT3aiN4vvYgUk
125 lines
4.3 KiB
Python
125 lines
4.3 KiB
Python
"""Tests for tools.music_tools — Music generation (Lyra persona).
|
||
|
||
Heavy AI model tests are skipped; only catalogue, interface, and
|
||
metadata tests run in CI.
|
||
"""
|
||
|
||
import pytest
|
||
from unittest.mock import patch, MagicMock
|
||
|
||
from creative.tools.music_tools import (
|
||
MUSIC_TOOL_CATALOG,
|
||
GENRES,
|
||
list_genres,
|
||
generate_song,
|
||
generate_instrumental,
|
||
generate_vocals,
|
||
)
|
||
|
||
|
||
class TestMusicToolCatalog:
|
||
def test_catalog_has_all_tools(self):
|
||
expected = {
|
||
"generate_song", "generate_instrumental",
|
||
"generate_vocals", "list_genres",
|
||
}
|
||
assert expected == set(MUSIC_TOOL_CATALOG.keys())
|
||
|
||
def test_catalog_entries_have_required_keys(self):
|
||
for tool_id, info in MUSIC_TOOL_CATALOG.items():
|
||
assert "name" in info
|
||
assert "description" in info
|
||
assert "fn" in info
|
||
assert callable(info["fn"])
|
||
|
||
|
||
class TestListGenres:
|
||
def test_returns_genre_list(self):
|
||
result = list_genres()
|
||
assert result["success"]
|
||
assert len(result["genres"]) > 10
|
||
assert "pop" in result["genres"]
|
||
assert "cinematic" in result["genres"]
|
||
|
||
|
||
class TestGenres:
|
||
def test_common_genres_present(self):
|
||
for genre in ["pop", "rock", "hip-hop", "jazz", "electronic", "classical"]:
|
||
assert genre in GENRES
|
||
|
||
|
||
class TestGenerateSongInterface:
|
||
def test_raises_without_ace_step(self):
|
||
with patch("creative.tools.music_tools._model", None):
|
||
with patch("creative.tools.music_tools._get_model", side_effect=ImportError("no ace-step")):
|
||
with pytest.raises(ImportError):
|
||
generate_song("la la la")
|
||
|
||
def test_duration_clamped(self):
|
||
"""Duration is clamped to 30–240 range."""
|
||
mock_audio = MagicMock()
|
||
mock_audio.save = MagicMock()
|
||
|
||
mock_model = MagicMock()
|
||
mock_model.generate.return_value = mock_audio
|
||
|
||
with patch("creative.tools.music_tools._get_model", return_value=mock_model):
|
||
with patch("creative.tools.music_tools._output_dir", return_value=MagicMock()):
|
||
with patch("creative.tools.music_tools._save_metadata"):
|
||
# Should clamp 5 to 30
|
||
generate_song("lyrics", duration=5)
|
||
call_kwargs = mock_model.generate.call_args[1]
|
||
assert call_kwargs["duration"] == 30
|
||
|
||
def test_generate_song_with_mocked_model(self, tmp_path):
|
||
mock_audio = MagicMock()
|
||
mock_audio.save = MagicMock()
|
||
|
||
mock_model = MagicMock()
|
||
mock_model.generate.return_value = mock_audio
|
||
|
||
with patch("creative.tools.music_tools._get_model", return_value=mock_model):
|
||
with patch("creative.tools.music_tools._output_dir", return_value=tmp_path):
|
||
result = generate_song(
|
||
"hello world", genre="rock", duration=60, title="Test Song"
|
||
)
|
||
|
||
assert result["success"]
|
||
assert result["genre"] == "rock"
|
||
assert result["title"] == "Test Song"
|
||
assert result["duration"] == 60
|
||
|
||
|
||
class TestGenerateInstrumentalInterface:
|
||
def test_with_mocked_model(self, tmp_path):
|
||
mock_audio = MagicMock()
|
||
mock_audio.save = MagicMock()
|
||
|
||
mock_model = MagicMock()
|
||
mock_model.generate.return_value = mock_audio
|
||
|
||
with patch("creative.tools.music_tools._get_model", return_value=mock_model):
|
||
with patch("creative.tools.music_tools._output_dir", return_value=tmp_path):
|
||
result = generate_instrumental("epic orchestral", genre="cinematic")
|
||
|
||
assert result["success"]
|
||
assert result["genre"] == "cinematic"
|
||
assert result["instrumental"] is True
|
||
|
||
|
||
class TestGenerateVocalsInterface:
|
||
def test_with_mocked_model(self, tmp_path):
|
||
mock_audio = MagicMock()
|
||
mock_audio.save = MagicMock()
|
||
|
||
mock_model = MagicMock()
|
||
mock_model.generate.return_value = mock_audio
|
||
|
||
with patch("creative.tools.music_tools._get_model", return_value=mock_model):
|
||
with patch("creative.tools.music_tools._output_dir", return_value=tmp_path):
|
||
result = generate_vocals("do re mi", style="jazz")
|
||
|
||
assert result["success"]
|
||
assert result["vocals_only"] is True
|
||
assert result["style"] == "jazz"
|