| """The synthesized audio returns valid, non-trivial WAV bytes.""" |
| import io |
| import wave |
|
|
| from sting import (chime_wav_bytes, flatline_wav_bytes, heartbeat_wav_bytes, |
| menu_loop_wav_bytes, sigh_wav_bytes, sting_wav_bytes, |
| type_tick_wav_bytes) |
|
|
|
|
| def _frames(b: bytes) -> int: |
| with wave.open(io.BytesIO(b), "rb") as w: |
| assert w.getnchannels() == 1 |
| assert w.getsampwidth() == 2 |
| return w.getnframes() |
|
|
|
|
| def test_heartbeat_is_a_whole_number_of_beats_for_seamless_loop(): |
| |
| frames = _frames(heartbeat_wav_bytes()) |
| assert frames == int(22050 * 1.7) |
|
|
|
|
| def test_sigh_is_a_few_seconds_of_audio(): |
| assert _frames(sigh_wav_bytes()) == int(22050 * 2.6) |
|
|
|
|
| def test_flatline_is_four_seconds(): |
| assert _frames(flatline_wav_bytes()) == int(22050 * 4.0) |
|
|
|
|
| def test_existing_sounds_still_synthesize(): |
| assert len(sting_wav_bytes()) > 1000 |
| assert len(chime_wav_bytes(0)) > 500 |
|
|
|
|
| def test_menu_loop_is_valid_wav(): |
| b = menu_loop_wav_bytes() |
| assert len(b) > 2000 |
| assert _frames(b) > int(22050 * 7) |
|
|
|
|
| def test_type_tick_is_a_short_valid_wav(): |
| b = type_tick_wav_bytes() |
| assert len(b) > 400 |
| assert _frames(b) < int(22050 * 0.2) |
|
|