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