-
Notifications
You must be signed in to change notification settings - Fork 116
/
test.py
41 lines (31 loc) · 1.73 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-=
# On Mac, ignoring the issue of not having AppKit if it's not the stock version of Python, it's working for all but Cyrllic...
# Just need to find out how to properly escape the name so that it works...
from os import listdir
from os.path import join
from sys import version
from time import time
from playsound import playsound, PlaysoundException
import unittest
durationMarginLow = 0.3
duratingMarginHigh = 1.5
class PlaysoundTests(unittest.TestCase):
def helper(self, file, approximateDuration, block = True):
startTime = time()
playsound(join('test_media', file), block = block)
duration = time() - startTime
self.assertTrue(approximateDuration - durationMarginLow <= duration <= approximateDuration + duratingMarginHigh, 'File "{}" took an unexpected amount of time: {}'.format(file, duration))
testBlockingASCII_MP3 = lambda self: self.helper('Damonte.mp3', 1.1)
testBlockingASCII_WAV = lambda self: self.helper('Sound4.wav', 1.3)
testBlockingCYRIL_WAV = lambda self: self.helper(u'Буква_Я.wav', 1.6)
testBlockingSPACE_MP3 = lambda self: self.helper('Discovery - Go at throttle up (2).mp3', 2.3)
testNonBlockingRepeat = lambda self: self.helper(u'Буква_Я.wav', 0.0, block = False)
def testMissing(self):
with self.assertRaises(PlaysoundException) as context:
playsound('notarealfile.wav')
message = context.exception.message.lower()
for sub in ['cannot', 'find', 'filename', 'notarealfile.wav']:
self.assertIn(sub, message.lower(), '"{}" was expected in the exception message, but instead got: "{}"'.format(sub, message))
if __name__ == '__main__':
print(version)
unittest.main()