self.regs[0x00:0x01] = 0x0f, 0x00\r
\r
\r
+@pytest.fixture(scope='function', autouse=True)\r
+def cleanup():\r
+ yield None\r
+ try:\r
+ del sys.modules['enviroplus']\r
+ except KeyError:\r
+ pass\r
+ try:\r
+ del sys.modules['enviroplus.noise']\r
+ except KeyError:\r
+ pass\r
+ try:\r
+ del sys.modules['enviroplus.gas']\r
+ except KeyError:\r
+ pass\r
+\r
+\r
@pytest.fixture(scope='function', autouse=False)\r
def GPIO():\r
"""Mock RPi.GPIO module."""\r
-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
-import sys
-import mock
-
-
-def force_reimport(module):
- """Force the module under test to be re-imported.
-
- Because pytest runs all tests within the same scope (this makes me cry)
- we have to do some manual housekeeping to avoid tests polluting each other.
-
- Since conftest.py already does some sys.modules mangling I see no reason not to
- do the same thing here.
- """
- if "." in module:
- steps = module.split(".")
- else:
- steps = [module]
-
- for i in range(len(steps)):
- module = ".".join(steps[0:i + 1])
- try:
- del sys.modules[module]
- except KeyError:
- pass
-
-
def test_gas_setup(GPIO, smbus):
from enviroplus import gas
gas._is_setup = False
def test_gas_cleanup(GPIO, smbus):
- force_reimport('enviroplus.gas')
from enviroplus import gas
gas.cleanup()