comparison test/test_process.py @ 82:a11b57e9fb0b

naming: module methods snake_case
author Chris Cannam
date Wed, 21 Jan 2015 12:43:50 +0000
parents b2afd385586f
children f0c18ba7b54e
comparison
equal deleted inserted replaced
81:0a2f2e7803ea 82:a11b57e9fb0b
1 1
2 import vamp 2 import vamp
3 import numpy as np 3 import numpy as np
4 4
5 testPluginKey = "vamp-test-plugin:vamp-test-plugin" 5 plugin_key = "vamp-test-plugin:vamp-test-plugin"
6 testPluginKeyFreq = "vamp-test-plugin:vamp-test-plugin-freq" 6 plugin_key_freq = "vamp-test-plugin:vamp-test-plugin-freq"
7 7
8 rate = 44100 8 rate = 44100
9 9
10 # Throughout this file we have the assumption that the plugin gets run with a 10 # Throughout this file we have the assumption that the plugin gets run with a
11 # blocksize of 1024, and with a step of 1024 for the time-domain version or 512 11 # blocksize of 1024, and with a step of 1024 for the time-domain version or 512
19 # start at 1, not 0 so that all elts are non-zero 19 # start at 1, not 0 so that all elts are non-zero
20 return np.arange(n) + 1 20 return np.arange(n) + 1
21 21
22 def test_process_n(): 22 def test_process_n():
23 buf = input_data(blocksize) 23 buf = input_data(blocksize)
24 results = list(vamp.process(buf, rate, testPluginKey, "input-summary")) 24 results = list(vamp.process(buf, rate, plugin_key, "input-summary"))
25 assert len(results) == 1 25 assert len(results) == 1
26 26
27 def test_process_freq_n(): 27 def test_process_freq_n():
28 buf = input_data(blocksize) 28 buf = input_data(blocksize)
29 results = list(vamp.process(buf, rate, testPluginKeyFreq, "input-summary", {})) 29 results = list(vamp.process(buf, rate, plugin_key_freq, "input-summary", {}))
30 assert len(results) == 2 # one complete block starting at zero, one half-full 30 assert len(results) == 2 # one complete block starting at zero, one half-full
31 31
32 def test_process_default_output(): 32 def test_process_default_output():
33 # If no output is specified, we should get the first one (instants) 33 # If no output is specified, we should get the first one (instants)
34 buf = input_data(blocksize) 34 buf = input_data(blocksize)
35 results = list(vamp.process(buf, rate, testPluginKey, "", {})) 35 results = list(vamp.process(buf, rate, plugin_key, "", {}))
36 assert len(results) == 10 36 assert len(results) == 10
37 for i in range(len(results)): 37 for i in range(len(results)):
38 expectedTime = vamp.vampyhost.RealTime('seconds', i * 1.5) 38 expectedTime = vamp.vampyhost.RealTime('seconds', i * 1.5)
39 actualTime = results[i]["timestamp"] 39 actualTime = results[i]["timestamp"]
40 assert expectedTime == actualTime 40 assert expectedTime == actualTime
41 41
42 def test_process_summary_param(): 42 def test_process_summary_param():
43 buf = input_data(blocksize * 10) 43 buf = input_data(blocksize * 10)
44 results = list(vamp.process(buf, rate, testPluginKey, "input-summary", { "produce_output": 0 })) 44 results = list(vamp.process(buf, rate, plugin_key, "input-summary", { "produce_output": 0 }))
45 assert len(results) == 0 45 assert len(results) == 0
46 46
47 def test_process_multi_summary_param(): 47 def test_process_multi_summary_param():
48 buf = input_data(blocksize * 10) 48 buf = input_data(blocksize * 10)
49 results = list(vamp.processMultipleOutputs(buf, rate, testPluginKey, [ "input-summary" ], { "produce_output": 0 })) 49 results = list(vamp.process_multiple_outputs(buf, rate, plugin_key, [ "input-summary" ], { "produce_output": 0 }))
50 assert len(results) == 0 50 assert len(results) == 0
51 51
52 def test_process_summary_param_bool(): 52 def test_process_summary_param_bool():
53 buf = input_data(blocksize * 10) 53 buf = input_data(blocksize * 10)
54 results = list(vamp.process(buf, rate, testPluginKey, "input-summary", { "produce_output": False })) 54 results = list(vamp.process(buf, rate, plugin_key, "input-summary", { "produce_output": False }))
55 assert len(results) == 0 55 assert len(results) == 0
56 56
57 def test_process_multi_summary_param_bool(): 57 def test_process_multi_summary_param_bool():
58 buf = input_data(blocksize * 10) 58 buf = input_data(blocksize * 10)
59 results = list(vamp.processMultipleOutputs(buf, rate, testPluginKey, [ "input-summary" ], { "produce_output": False })) 59 results = list(vamp.process_multiple_outputs(buf, rate, plugin_key, [ "input-summary" ], { "produce_output": False }))
60 assert len(results) == 0 60 assert len(results) == 0
61 61
62 def test_process_summary(): 62 def test_process_summary():
63 buf = input_data(blocksize * 10) 63 buf = input_data(blocksize * 10)
64 results = list(vamp.process(buf, rate, testPluginKey, "input-summary", {})) 64 results = list(vamp.process(buf, rate, plugin_key, "input-summary", {}))
65 assert len(results) == 10 65 assert len(results) == 10
66 for i in range(len(results)): 66 for i in range(len(results)):
67 # 67 #
68 # each feature has a single value, equal to the number of non-zero elts 68 # each feature has a single value, equal to the number of non-zero elts
69 # in the input block (which is all of them, i.e. the blocksize) plus 69 # in the input block (which is all of them, i.e. the blocksize) plus
73 actual = results[i]["values"][0] 73 actual = results[i]["values"][0]
74 assert actual == expected 74 assert actual == expected
75 75
76 def test_process_multi_summary(): 76 def test_process_multi_summary():
77 buf = input_data(blocksize * 10) 77 buf = input_data(blocksize * 10)
78 results = list(vamp.processMultipleOutputs(buf, rate, testPluginKey, [ "input-summary" ], {})) 78 results = list(vamp.process_multiple_outputs(buf, rate, plugin_key, [ "input-summary" ], {}))
79 assert len(results) == 10 79 assert len(results) == 10
80 for i in range(len(results)): 80 for i in range(len(results)):
81 # 81 #
82 # each feature has a single value, equal to the number of non-zero elts 82 # each feature has a single value, equal to the number of non-zero elts
83 # in the input block (which is all of them, i.e. the blocksize) plus 83 # in the input block (which is all of them, i.e. the blocksize) plus
87 actual = results[i]["input-summary"]["values"][0] 87 actual = results[i]["input-summary"]["values"][0]
88 assert actual == expected 88 assert actual == expected
89 89
90 def test_process_freq_summary(): 90 def test_process_freq_summary():
91 buf = input_data(blocksize * 10) 91 buf = input_data(blocksize * 10)
92 results = list(vamp.process(buf, rate, testPluginKeyFreq, "input-summary", {})) 92 results = list(vamp.process(buf, rate, plugin_key_freq, "input-summary", {}))
93 assert len(results) == 20 93 assert len(results) == 20
94 for i in range(len(results)): 94 for i in range(len(results)):
95 # 95 #
96 # sort of as above, but much much subtler: 96 # sort of as above, but much much subtler:
97 # 97 #
125 eps = 1e-6 125 eps = 1e-6
126 assert abs(actual - expected) < eps 126 assert abs(actual - expected) < eps
127 127
128 def test_process_multi_freq_summary(): 128 def test_process_multi_freq_summary():
129 buf = input_data(blocksize * 10) 129 buf = input_data(blocksize * 10)
130 results = list(vamp.processMultipleOutputs(buf, rate, testPluginKeyFreq, [ "input-summary" ], {})) 130 results = list(vamp.process_multiple_outputs(buf, rate, plugin_key_freq, [ "input-summary" ], {}))
131 assert len(results) == 20 131 assert len(results) == 20
132 for i in range(len(results)): 132 for i in range(len(results)):
133 expected = i * (blocksize/2) + blocksize/2 + 1 # "first" elt 133 expected = i * (blocksize/2) + blocksize/2 + 1 # "first" elt
134 if (i == len(results)-1): 134 if (i == len(results)-1):
135 expected = 0 135 expected = 0
138 eps = 1e-6 138 eps = 1e-6
139 assert abs(actual - expected) < eps 139 assert abs(actual - expected) < eps
140 140
141 def test_process_timestamps(): 141 def test_process_timestamps():
142 buf = input_data(blocksize * 10) 142 buf = input_data(blocksize * 10)
143 results = list(vamp.process(buf, rate, testPluginKey, "input-timestamp", {})) 143 results = list(vamp.process(buf, rate, plugin_key, "input-timestamp", {}))
144 assert len(results) == 10 144 assert len(results) == 10
145 for i in range(len(results)): 145 for i in range(len(results)):
146 # The timestamp should be the frame number of the first frame in the 146 # The timestamp should be the frame number of the first frame in the
147 # input buffer 147 # input buffer
148 expected = i * blocksize 148 expected = i * blocksize
149 actual = results[i]["values"][0] 149 actual = results[i]["values"][0]
150 assert actual == expected 150 assert actual == expected
151 151
152 def test_process_multi_timestamps(): 152 def test_process_multi_timestamps():
153 buf = input_data(blocksize * 10) 153 buf = input_data(blocksize * 10)
154 results = list(vamp.processMultipleOutputs(buf, rate, testPluginKey, [ "input-timestamp" ])) 154 results = list(vamp.process_multiple_outputs(buf, rate, plugin_key, [ "input-timestamp" ]))
155 assert len(results) == 10 155 assert len(results) == 10
156 for i in range(len(results)): 156 for i in range(len(results)):
157 # The timestamp should be the frame number of the first frame in the 157 # The timestamp should be the frame number of the first frame in the
158 # input buffer 158 # input buffer
159 expected = i * blocksize 159 expected = i * blocksize
160 actual = results[i]["input-timestamp"]["values"][0] 160 actual = results[i]["input-timestamp"]["values"][0]
161 assert actual == expected 161 assert actual == expected
162 162
163 def test_process_freq_timestamps(): 163 def test_process_freq_timestamps():
164 buf = input_data(blocksize * 10) 164 buf = input_data(blocksize * 10)
165 results = list(vamp.process(buf, rate, testPluginKeyFreq, "input-timestamp", {})) 165 results = list(vamp.process(buf, rate, plugin_key_freq, "input-timestamp", {}))
166 assert len(results) == 20 166 assert len(results) == 20
167 for i in range(len(results)): 167 for i in range(len(results)):
168 # The timestamp should be the frame number of the frame just beyond 168 # The timestamp should be the frame number of the frame just beyond
169 # half-way through the input buffer 169 # half-way through the input buffer
170 expected = i * (blocksize/2) + blocksize/2 170 expected = i * (blocksize/2) + blocksize/2
171 actual = results[i]["values"][0] 171 actual = results[i]["values"][0]
172 assert actual == expected 172 assert actual == expected
173 173
174 def test_process_multi_freq_timestamps(): 174 def test_process_multi_freq_timestamps():
175 buf = input_data(blocksize * 10) 175 buf = input_data(blocksize * 10)
176 results = list(vamp.processMultipleOutputs(buf, rate, testPluginKeyFreq, [ "input-timestamp" ], {})) 176 results = list(vamp.process_multiple_outputs(buf, rate, plugin_key_freq, [ "input-timestamp" ], {}))
177 assert len(results) == 20 177 assert len(results) == 20
178 for i in range(len(results)): 178 for i in range(len(results)):
179 # The timestamp should be the frame number of the frame just beyond 179 # The timestamp should be the frame number of the frame just beyond
180 # half-way through the input buffer 180 # half-way through the input buffer
181 expected = i * (blocksize/2) + blocksize/2 181 expected = i * (blocksize/2) + blocksize/2
182 actual = results[i]["input-timestamp"]["values"][0] 182 actual = results[i]["input-timestamp"]["values"][0]
183 assert actual == expected 183 assert actual == expected
184 184
185 def test_process_multiple_outputs(): 185 def test_process_multiple_outputs():
186 buf = input_data(blocksize * 10) 186 buf = input_data(blocksize * 10)
187 results = list(vamp.processMultipleOutputs(buf, rate, testPluginKey, [ "input-summary", "input-timestamp" ], {})) 187 results = list(vamp.process_multiple_outputs(buf, rate, plugin_key, [ "input-summary", "input-timestamp" ], {}))
188 assert len(results) == 20 188 assert len(results) == 20
189 si = 0 189 si = 0
190 ti = 0 190 ti = 0
191 for r in results: 191 for r in results:
192 assert "input-summary" in r or "input-timestamp" in r 192 assert "input-summary" in r or "input-timestamp" in r