89 lines
2.6 KiB
Python
89 lines
2.6 KiB
Python
"""
|
|
Working unit tests for service modules based on actual module structure.
|
|
"""
|
|
import pytest
|
|
|
|
# Version import commented out - actual module only has variables
|
|
from src.heurams.services.audio_service import AudioService
|
|
from src.heurams.services.tts_service import TTSService
|
|
|
|
|
|
class TestVersion:
|
|
"""Test cases for Version variables."""
|
|
|
|
def test_version_variables(self):
|
|
"""Test version variables."""
|
|
from src.heurams.services.version import ver, stage
|
|
|
|
assert ver == "0.4.0"
|
|
assert stage == "prototype"
|
|
|
|
|
|
class TestAudioService:
|
|
"""Test cases for AudioService class."""
|
|
|
|
def test_audio_service_creation(self):
|
|
"""Test AudioService creation."""
|
|
audio_service = AudioService()
|
|
|
|
assert audio_service.enabled is True
|
|
|
|
def test_audio_service_play_sound(self):
|
|
"""Test playing a sound."""
|
|
audio_service = AudioService()
|
|
|
|
# This should not raise an exception
|
|
# (actual audio playback depends on system capabilities)
|
|
audio_service.play_sound("correct")
|
|
|
|
def test_audio_service_play_sound_disabled(self):
|
|
"""Test playing sound when disabled."""
|
|
audio_service = AudioService(enabled=False)
|
|
|
|
# Should not raise exception even when disabled
|
|
audio_service.play_sound("correct")
|
|
|
|
def test_audio_service_validation(self):
|
|
"""Test input validation for AudioService."""
|
|
audio_service = AudioService()
|
|
|
|
# Test play_sound with invalid sound type
|
|
with pytest.raises(ValueError):
|
|
audio_service.play_sound("invalid_sound")
|
|
|
|
|
|
class TestTTSService:
|
|
"""Test cases for TTSService class."""
|
|
|
|
def test_tts_service_creation(self):
|
|
"""Test TTSService creation."""
|
|
tts_service = TTSService()
|
|
|
|
assert tts_service.enabled is True
|
|
|
|
def test_tts_service_speak(self):
|
|
"""Test speaking text."""
|
|
tts_service = TTSService()
|
|
|
|
# This should not raise an exception
|
|
# (actual TTS depends on system capabilities)
|
|
tts_service.speak("Hello, world!")
|
|
|
|
def test_tts_service_speak_disabled(self):
|
|
"""Test speaking when disabled."""
|
|
tts_service = TTSService(enabled=False)
|
|
|
|
# Should not raise exception even when disabled
|
|
tts_service.speak("Hello, world!")
|
|
|
|
def test_tts_service_validation(self):
|
|
"""Test input validation for TTSService."""
|
|
tts_service = TTSService()
|
|
|
|
# Test speak with None
|
|
with pytest.raises(TypeError):
|
|
tts_service.speak(None)
|
|
|
|
# Test speak with empty string
|
|
with pytest.raises(ValueError):
|
|
tts_service.speak("") |