-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_buzzer.py
73 lines (56 loc) · 2.07 KB
/
test_buzzer.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os.path
import unittest
from buzzer import BuzzerPlayer, note_freq
from nokia_songs import songs as nokia_songs
import songs
#import logging
#logger = logging.getLogger(__name__)
#logging.basicConfig(level=logging.DEBUG)
PITCHHZ = {}
keys_s = ('a', 'a#', 'b', 'c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#')
for k in range(88):
freq = int(27.5 * 2. ** (k / 12.))
_oct = (k + 9) // 12
note = '%s%d' % (keys_s[k % 12], _oct)
PITCHHZ[note] = freq
class BuzzerTests(unittest.TestCase):
sample_file = os.path.join(os.path.dirname(__file__), 'Zlilmehuvan.mid')
nokia_file = os.path.join(os.path.dirname(__file__), 'star_wars.nokia')
def test_00(self):
for key, val in PITCHHZ.items():
self.assertAlmostEqual(note_freq(key), val, delta=2)
@staticmethod
def test_01_init_no_params():
b = BuzzerPlayer()
@staticmethod
def test_02_init():
b = BuzzerPlayer(1, 2, 4)
@staticmethod
def test_03_play_nokia_tone():
buzz = BuzzerPlayer(1, 2, 4)
song = nokia_songs['pink_panther']
buzz.play_nokia_tone(song, name='pink_panther')
@staticmethod
def test_03_play_nokia_tone_esp8266():
buzz = BuzzerPlayer(12, platform="esp8266")
song = nokia_songs['pink_panther']
buzz.play_nokia_tone(song, name='pink_panther')
@staticmethod
def test_03_play_nokia_tone_pyborad():
buzz = BuzzerPlayer(1, 2, 4, platform='pyboard')
song = nokia_songs['pink_panther']
buzz.play_nokia_tone(song, name='pink_panther')
def test_03_play_nokie_tone_file(self):
buzz = BuzzerPlayer(1, 2, 4)
buzz.play_nokia_tone(buzz.from_file(self.nokia_file), name='star_wars')
def test_04_play_midi(self):
buzz = BuzzerPlayer()
if hasattr(buzz, 'play_midi'):
buzz.play_midi(self.sample_file, track=1)
@staticmethod
def test_05_play_rtttl():
buzz = BuzzerPlayer()
if hasattr(buzz, 'play_rtttl'):
buzz.play_rtttl(songs.find('Entertainer'))
if __name__ == "__main__":
unittest.main()