annotate test/test_collect.py @ 112:9343eee50605

Update to Python 3. Currently crashes during tests (and also, two tests are now failing, even with Py2).
author Chris Cannam
date Wed, 17 Jun 2015 12:35:41 +0100
parents 0c5a4dc04ed9
children 1c7c4bd74363
rev   line source
Chris@71 1
Chris@71 2 import vamp
Chris@71 3 import numpy as np
Chris@101 4 import vamp.frames as fr
Chris@71 5
Chris@82 6 plugin_key = "vamp-test-plugin:vamp-test-plugin"
Chris@82 7 plugin_key_freq = "vamp-test-plugin:vamp-test-plugin-freq"
Chris@71 8
Chris@112 9 rate = 44100.0
Chris@71 10
Chris@71 11 # Throughout this file we have the assumption that the plugin gets run with a
Chris@71 12 # blocksize of 1024, and with a step of 1024 for the time-domain version or 512
Chris@71 13 # for the frequency-domain one. That is certainly expected to be the norm for a
Chris@71 14 # plugin like this that declares no preference, and the Python Vamp module is
Chris@71 15 # expected to follow the norm
Chris@71 16
Chris@71 17 blocksize = 1024
Chris@92 18 eps = 1e-6
Chris@71 19
Chris@71 20 def input_data(n):
Chris@71 21 # start at 1, not 0 so that all elts are non-zero
Chris@71 22 return np.arange(n) + 1
Chris@71 23
Chris@71 24 def test_collect_runs_at_all():
Chris@88 25 buf = input_data(blocksize * 10)
Chris@94 26 step, results = vamp.collect(buf, rate, plugin_key, "input-timestamp")
Chris@88 27 assert results != []
Chris@88 28
Chris@96 29 ##!!! add test for default output
Chris@96 30
Chris@88 31 def test_collect_one_sample_per_step():
Chris@88 32 buf = input_data(blocksize * 10)
Chris@94 33 step, results = vamp.collect(buf, rate, plugin_key, "input-timestamp")
Chris@94 34 assert abs(float(step) - (1024.0 / rate)) < eps
Chris@88 35 assert len(results) == 10
Chris@93 36 for i in range(len(results)):
Chris@93 37 # The timestamp should be the frame number of the first frame in the
Chris@93 38 # input buffer
Chris@93 39 expected = i * blocksize
Chris@93 40 actual = results[i]
Chris@93 41 assert actual == expected
Chris@88 42
Chris@92 43 def test_collect_fixed_sample_rate():
Chris@92 44 buf = input_data(blocksize * 10)
Chris@94 45 step, results = vamp.collect(buf, rate, plugin_key, "curve-fsr")
Chris@94 46 assert abs(float(step) - 0.4) < eps
Chris@92 47 assert len(results) == 10
Chris@93 48 for i in range(len(results)):
Chris@93 49 assert abs(results[i] - i * 0.1) < eps
Chris@92 50
Chris@92 51 def test_collect_fixed_sample_rate_2():
Chris@92 52 buf = input_data(blocksize * 10)
Chris@94 53 step, results = vamp.collect(buf, rate, plugin_key, "curve-fsr-timed")
Chris@94 54 assert abs(float(step) - 0.4) < eps
Chris@92 55 assert len(results) == 10
Chris@93 56 for i in range(len(results)):
Chris@93 57 assert abs(results[i] - i * 0.1) < eps
Chris@92 58
Chris@92 59 def test_collect_variable_sample_rate():
Chris@92 60 buf = input_data(blocksize * 10)
Chris@94 61 results = vamp.collect(buf, rate, plugin_key, "curve-vsr")
Chris@92 62 assert len(results) == 10
Chris@92 63 i = 0
Chris@92 64 for r in results:
Chris@92 65 assert r["timestamp"] == vamp.vampyhost.RealTime('seconds', i * 0.75)
Chris@92 66 assert abs(r["values"][0] - i * 0.1) < eps
Chris@92 67 i = i + 1
Chris@96 68
Chris@96 69 def test_collect_grid_one_sample_per_step():
Chris@96 70 buf = input_data(blocksize * 10)
Chris@96 71 step, results = vamp.collect(buf, rate, plugin_key, "grid-oss")
Chris@96 72 assert abs(float(step) - (1024.0 / rate)) < eps
Chris@96 73 assert len(results) == 10
Chris@96 74 for i in range(len(results)):
Chris@97 75 expected = np.array([ (j + i + 2.0) / 30.0 for j in range(0, 10) ])
Chris@97 76 assert (abs(results[i] - expected) < eps).all()