fix: close #4-#5-#14 - fix test_updated_app.py: unpack parse_speaker_text tuple correctly, pass tracks arg to generate_wav_files

This commit is contained in:
Jarian 2026-07-05 12:47:23 +00:00
parent 564c68e002
commit 5c615f3892

View File

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