Merge pull request 'fix: close #4-#5-#14 - fix test_updated_app.py tuple unpacking and function args' (#29) from fix/issue-tests into main

Reviewed-on: https://git.home.ms/jarianc/kokorotts-server/pulls/29
This commit is contained in:
jarianc 2026-07-05 07:54:25 -05:00
commit f15a71a143

View File

@ -12,10 +12,10 @@ def test_speaker_parsing():
with open("test.txt", "r") as f:
text = f.read()
# Import the function from app.py
from app import parse_speaker_text
speakers = parse_speaker_text(text)
# Issue #4: parse_speaker_text returns (speakers, tracks) tuple
speakers, tracks = parse_speaker_text(text)
# Should have 2 speakers
assert len(speakers) == 2, f"Expected 2 speakers, got {len(speakers)}"
@ -28,7 +28,7 @@ def test_speaker_parsing():
assert speakers["Alex"], "Alex should have content"
assert speakers["Jamie"], "Jamie should have content"
print(" Speaker parsing test passed")
print("OK: Speaker parsing test passed")
def test_voice_assignment():
@ -38,7 +38,8 @@ def test_voice_assignment():
with open("test.txt", "r") as f:
text = f.read()
speakers = parse_speaker_text(text)
# Issue #14: Unpack tuple properly - parse_speaker_text returns (speakers, tracks)
speakers, tracks = parse_speaker_text(text)
speaker_voice_map = assign_voices_to_speakers(speakers)
# Should have assignments for both speakers
@ -52,42 +53,38 @@ def test_voice_assignment():
f"Invalid voice {voice} for {speaker}"
)
print(" Voice assignment test passed")
print("OK: Voice assignment test passed")
def test_full_integration():
"""Test that the full integration works with a simple example"""
# For this test we'll create a basic Flask app to test our functions
from app import generate_wav_files, parse_speaker_text, assign_voices_to_speakers
# Simple test data
test_text = """Alex: Hello world
Jamie: This is a test"""
speakers = parse_speaker_text(test_text)
# Issue #4/#14: Unpack tuple properly
speakers, tracks = parse_speaker_text(test_text)
speaker_voice_map = assign_voices_to_speakers(speakers)
# Test generating files (using temporary directory for output)
with tempfile.TemporaryDirectory() as tmpdir:
# Change output directory for this test
original_output_dir = os.environ.get("OUTPUT_DIR", "output")
os.environ["OUTPUT_DIR"] = tmpdir
try:
# Issue #5: Pass all 4 required args (speakers, speaker_voice_map, title, tracks)
wav_files = generate_wav_files(
speakers, speaker_voice_map, "test_integration"
speakers, speaker_voice_map, "test_integration", tracks
)
# Check that files were created
if wav_files:
print(" Integration test passed - WAV files generated")
print("OK: Integration test passed - WAV files generated")
else:
print("<EFBFBD><EFBFBD><EFBFBD> Integration test - No files generated (but no error)")
print("WARN: Integration test - No files generated (but no error)")
finally:
# Restore original output directory
os.environ["OUTPUT_DIR"] = original_output_dir
print(" Full integration test completed")
print("OK: Full integration test completed")
if __name__ == "__main__":