Skip to content

Commit

Permalink
Added unit tests for audio, with an associated sample file (short, an…
Browse files Browse the repository at this point in the history
…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
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Binary file added kivy/tests/sample1.ogg
Binary file not shown.
62 changes: 62 additions & 0 deletions kivy/tests/test_audio.py
@@ -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


0 comments on commit 4093670

Please sign in to comment.