-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_helper.py
70 lines (46 loc) · 1.85 KB
/
test_helper.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
from helper import save_file, new_song, save_image, combine_notes_and_chords, parse_melody
from music21 import stream, note
import unittest
import shutil
import os
class TestHelpers(unittest.TestCase):
def setUp(self):
# create files
os.makedirs('static/user_files/usertest/temp')
open('static/user_files/usertest/temp/temp_song.wav', 'a').close()
def tearDown(self):
# delete files
shutil.rmtree('static/user_files/usertest')
def test_new_song(self):
melody = 'C4'
results = new_song(melody, 'test')
self.assertEqual(results[0], [melody])
self.assertTrue(os.path.exists('static/user_files/usertest/temp/temp_song.wav'))
self.assertTrue(os.path.exists('static/user_files/usertest/temp/temp_song.mid'))
def test_save_file(self):
path = 'static/user_files/usertest/music/'
filename = 'song.wav'
user_id = 'test'
save_file(path, filename, user_id)
self.assertTrue(os.path.exists(path + filename))
def test_save_image(self):
image = 'data:image/png;base64,iVBORw='
path = 'static/user_files/usertest/scores/'
filename = 'song_score1.png'
save_image(path, filename, image)
self.assertTrue(os.path.exists(path + filename))
def test_combine_notes_chords(self):
melody = stream.Stream()
n = note.Note('C4')
n2 = note.Note('C4')
melody.append(n)
melody.append(n2)
result = combine_notes_and_chords(melody, [['C3', 'rest']])
self.assertEqual(type(result), stream.Stream)
def test_parse_melody(self):
result = parse_melody('C4 rest')
self.assertEqual(type(result[0]), stream.Part)
self.assertEqual(result[1], [0, 12])
self.assertEqual(result[2], ['C4', 'r'])
if __name__ == '__main__':
unittest.main()