| 1 | import pytest\r |
| 2 | \r |
| 3 | \r |
| 4 | def test_noise_setup(sounddevice, numpy):\r |
| 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 |
| 11 | def test_noise_get_amplitudes_at_frequency_ranges(sounddevice, numpy):\r |
| 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 |
| 23 | def test_noise_get_noise_profile(sounddevice, numpy):\r |
| 24 | from enviroplus.noise import Noise\r |
| 25 | \r |
| 26 | numpy.mean.return_value = 10.0\r |
| 27 | \r |
| 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 |
| 37 | assert amp_total == 10.0\r |
| 38 | \r |
| 39 | \r |
| 40 | def test_get_amplitude_at_frequency_range(sounddevice, numpy):\r |
| 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 |