-import sys\r
-import mock\r
import pytest\r
\r
\r
-def force_reimport(module):\r
- """Force the module under test to be re-imported.\r
-\r
- Because pytest runs all tests within the same scope (this makes me cry)\r
- we have to do some manual housekeeping to avoid tests polluting each other.\r
-\r
- Since conftest.py already does some sys.modules mangling I see no reason not to\r
- do the same thing here.\r
- """\r
- if "." in module:\r
- steps = module.split(".")\r
- else:\r
- steps = [module]\r
- \r
- for i in range(len(steps)):\r
- module = ".".join(steps[0:i + 1])\r
- try:\r
- del sys.modules[module]\r
- except KeyError:\r
- pass\r
-\r
-\r
def test_noise_setup(sounddevice, numpy):\r
- force_reimport('enviroplus.noise')\r
from enviroplus.noise import Noise\r
\r
noise = Noise(sample_rate=16000, duration=0.1)\r
\r
\r
def test_noise_get_amplitudes_at_frequency_ranges(sounddevice, numpy):\r
- # Ippity zippidy what is this farce\r
- # a curious function that makes my tests pass?\r
- force_reimport('enviroplus.noise')\r
from enviroplus.noise import Noise\r
\r
noise = Noise(sample_rate=16000, duration=0.1)\r
\r
\r
def test_noise_get_noise_profile(sounddevice, numpy):\r
- # Ippity zippidy what is this farce\r
- # a curious function that makes my tests pass?\r
- force_reimport('enviroplus.noise')\r
from enviroplus.noise import Noise\r
\r
+ numpy.mean.return_value = 10.0\r
+\r
noise = Noise(sample_rate=16000, duration=0.1)\r
amp_low, amp_mid, amp_high, amp_total = noise.get_noise_profile(\r
noise_floor=100,\r
\r
sounddevice.rec.assert_called_with(0.1 * 16000, samplerate=16000, blocking=True, channels=1, dtype='float64')\r
\r
+ assert amp_total == 10.0\r
+\r
\r
def test_get_amplitude_at_frequency_range(sounddevice, numpy):\r
- # Ippity zippidy what is this farce\r
- # a curious function that makes my tests pass?\r
- force_reimport('enviroplus.noise')\r
from enviroplus.noise import Noise\r
\r
noise = Noise(sample_rate=16000, duration=0.1)\r