forked from kivy/kivy
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for audio, with an associated sample file (short, an…
…d made it `.ogg` for easy compatibility, so big :(). See kivy#467
- Loading branch information
David Fraser
committed
Apr 26, 2012
1 parent
373fe00
commit 4093670
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
''' | ||
Audio tests | ||
=========== | ||
''' | ||
|
||
import unittest | ||
import os | ||
|
||
SAMPLE_FILE = os.path.join(os.path.dirname(__file__), 'sample1.ogg') | ||
SAMPLE_LENGTH = 1.402 | ||
SAMPLE_LENGTH_MIN = SAMPLE_LENGTH * 0.99 | ||
SAMPLE_LENGTH_MAX = SAMPLE_LENGTH * 1.01 | ||
|
||
class AudioTestCase(unittest.TestCase): | ||
|
||
def setUp(self): | ||
from kivy.core import audio | ||
self.make_sound = audio.SoundLoader.load | ||
|
||
def get_sound(self): | ||
import os | ||
assert os.path.exists(SAMPLE_FILE) | ||
return self.make_sound(filename=SAMPLE_FILE) | ||
|
||
def test_length_simple(self): | ||
sound = self.get_sound() | ||
length = sound.length | ||
assert SAMPLE_LENGTH_MIN <= length <= SAMPLE_LENGTH_MAX | ||
|
||
def test_length_playing(self): | ||
import time | ||
sound = self.get_sound() | ||
sound.play() | ||
try: | ||
time.sleep(0.1) | ||
length = sound.length | ||
assert SAMPLE_LENGTH_MIN <= length <= SAMPLE_LENGTH_MAX | ||
finally: | ||
sound.stop() | ||
|
||
def test_length_stopped(self): | ||
import time | ||
sound = self.get_sound() | ||
sound.play() | ||
try: | ||
time.sleep(0.1) | ||
finally: | ||
sound.stop() | ||
length = sound.length | ||
assert SAMPLE_LENGTH_MIN <= length <= SAMPLE_LENGTH_MAX | ||
|
||
class AudioGstreamerTestCase(AudioTestCase): | ||
def setUp(self): | ||
from kivy.core.audio import audio_gstreamer | ||
self.make_sound = audio_gstreamer.SoundGstreamer | ||
|
||
class AudioPygameTestCase(AudioTestCase): | ||
def setUp(self): | ||
from kivy.core.audio import audio_pygame | ||
self.make_sound = audio_pygame.SoundPygame | ||
|
||
|