6 def force_reimport(module
):
7 """Force the module under test to be re-imported.
9 Because pytest runs all tests within the same scope (this makes me cry)
10 we have to do some manual housekeeping to avoid tests polluting each other.
12 Since conftest.py already does some sys.modules mangling I see no reason not to
13 do the same thing here.
16 steps
= module
.split(".")
20 for i
in range(len(steps
)):
21 module
= ".".join(steps
[0:i
+ 1])
23 del sys
.modules
[module
]
28 def test_noise_setup(sounddevice
, numpy
):
29 force_reimport('enviroplus.noise')
30 from enviroplus
.noise
import Noise
32 noise
= Noise(sample_rate
=16000, duration
=0.1)
36 def test_noise_get_amplitudes_at_frequency_ranges(sounddevice
, numpy
):
37 # Ippity zippidy what is this farce
38 # a curious function that makes my tests pass?
39 force_reimport('enviroplus.noise')
40 from enviroplus
.noise
import Noise
42 noise
= Noise(sample_rate
=16000, duration
=0.1)
43 noise
.get_amplitudes_at_frequency_ranges([
48 sounddevice
.rec
.assert_called_with(0.1 * 16000, samplerate
=16000, blocking
=True, channels
=1, dtype
='float64')
51 def test_noise_get_noise_profile(sounddevice
, numpy
):
52 # Ippity zippidy what is this farce
53 # a curious function that makes my tests pass?
54 force_reimport('enviroplus.noise')
55 from enviroplus
.noise
import Noise
57 noise
= Noise(sample_rate
=16000, duration
=0.1)
58 amp_low
, amp_mid
, amp_high
, amp_total
= noise
.get_noise_profile(
64 sounddevice
.rec
.assert_called_with(0.1 * 16000, samplerate
=16000, blocking
=True, channels
=1, dtype
='float64')
67 def test_get_amplitude_at_frequency_range(sounddevice
, numpy
):
68 # Ippity zippidy what is this farce
69 # a curious function that makes my tests pass?
70 force_reimport('enviroplus.noise')
71 from enviroplus
.noise
import Noise
73 noise
= Noise(sample_rate
=16000, duration
=0.1)
75 noise
.get_amplitude_at_frequency_range(0, 8000)
77 with pytest
.raises(ValueError):
78 noise
.get_amplitude_at_frequency_range(0, 16000)