Merge pull request #88 from pimoroni/actions
[EVA-2020-02-2.git] / library / tests / test_noise.py
CommitLineData
e9c93677
PH
1import pytest\r
2\r
3\r
e9c93677 4def test_noise_setup(sounddevice, numpy):\r
e9c93677
PH
5 from enviroplus.noise import Noise\r
6\r
7 noise = Noise(sample_rate=16000, duration=0.1)\r
8 del noise\r
9\r
10\r
11def test_noise_get_amplitudes_at_frequency_ranges(sounddevice, numpy):\r
e9c93677
PH
12 from enviroplus.noise import Noise\r
13\r
14 noise = Noise(sample_rate=16000, duration=0.1)\r
15 noise.get_amplitudes_at_frequency_ranges([\r
16 (100, 500),\r
17 (501, 1000)\r
18 ])\r
19\r
20 sounddevice.rec.assert_called_with(0.1 * 16000, samplerate=16000, blocking=True, channels=1, dtype='float64')\r
21\r
22\r
23def test_noise_get_noise_profile(sounddevice, numpy):\r
e9c93677
PH
24 from enviroplus.noise import Noise\r
25\r
5a376ddb
PH
26 numpy.mean.return_value = 10.0\r
27\r
e9c93677
PH
28 noise = Noise(sample_rate=16000, duration=0.1)\r
29 amp_low, amp_mid, amp_high, amp_total = noise.get_noise_profile(\r
30 noise_floor=100,\r
31 low=0.12,\r
32 mid=0.36,\r
33 high=None)\r
34\r
35 sounddevice.rec.assert_called_with(0.1 * 16000, samplerate=16000, blocking=True, channels=1, dtype='float64')\r
36\r
5a376ddb
PH
37 assert amp_total == 10.0\r
38\r
e9c93677
PH
39\r
40def test_get_amplitude_at_frequency_range(sounddevice, numpy):\r
e9c93677
PH
41 from enviroplus.noise import Noise\r
42\r
43 noise = Noise(sample_rate=16000, duration=0.1)\r
44\r
45 noise.get_amplitude_at_frequency_range(0, 8000)\r
46\r
47 with pytest.raises(ValueError):\r
48 noise.get_amplitude_at_frequency_range(0, 16000)\r