From 99ba73dc9fd0776d8f03bc6e6799261d580e7dea Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Tue, 20 Oct 2020 15:41:31 +0100 Subject: [PATCH] Update tests --- library/.coveragerc | 2 +- library/README.md | 1 + library/grow/pump.py | 1 - library/tests/test_setup.py | 81 +++++++++++++++++-------------------- library/tox.ini | 10 ++--- 5 files changed, 43 insertions(+), 52 deletions(-) diff --git a/library/.coveragerc b/library/.coveragerc index 48d2b51..8de38fd 100644 --- a/library/.coveragerc +++ b/library/.coveragerc @@ -1,4 +1,4 @@ [run] -source = enviroplus +source = grow omit = .tox/* diff --git a/library/README.md b/library/README.md index 6f2b145..fc5f59a 100644 --- a/library/README.md +++ b/library/README.md @@ -57,6 +57,7 @@ You should read the following to get up and running with our monitoring script: * Discord - https://discord.gg/hr93ByC # Changelog + 0.0.1 ----- diff --git a/library/grow/pump.py b/library/grow/pump.py index 39d88fc..9a21d9e 100644 --- a/library/grow/pump.py +++ b/library/grow/pump.py @@ -80,4 +80,3 @@ class Pump(object): self.set_speed(speed) self._timeout.start() return True - diff --git a/library/tests/test_setup.py b/library/tests/test_setup.py index 254a7c9..1e8ecb1 100644 --- a/library/tests/test_setup.py +++ b/library/tests/test_setup.py @@ -1,56 +1,47 @@ +import mock + + def test_moisture_setup(GPIO, smbus): - from grow import moisture - moisture._is_setup = False + from grow.moisture import Moisture - moisture.setup() - moisture.setup() + ch1 = Moisture(channel=1) + ch2 = Moisture(channel=2) + ch3 = Moisture(channel=3) + + assert GPIO.setup.has_calls([ + mock.call(ch1._gpio_pin, GPIO.IN), + mock.call(ch2._gpio_pin, GPIO.IN), + mock.call(ch3._gpio_pin, GPIO.IN) + ]) -def test_moisture_read_all(GPIO, smbus): - from grow import moisture - moisture._is_setup = False +def test_moisture_read(GPIO, smbus): + from grow.moisture import Moisture - result = moisture.read_all() + assert Moisture(channel=1).saturation == 1.0 + assert Moisture(channel=2).saturation == 1.0 + assert Moisture(channel=3).saturation == 1.0 - assert type(result(1)) == float - assert int(result(1)) == 100 + assert Moisture(channel=1).moisture == 0 + assert Moisture(channel=2).moisture == 0 + assert Moisture(channel=3).moisture == 0 - assert type(result(2)) == float - assert int(result(2)) == 500 - - assert type(result.(3)) == float - assert int(result.(3)) == 5000 - - assert "Moisture" in str(result) - - -def test_moisture_read_each(GPIO, smbus): - from grow import moisture - moisture._is_setup = False - - assert int(moisture.read(1)) == 100 - assert int(moisture.read(2)) == 500 - assert int(moisture.read(3)) == 5000 - - -def test_moisture_cleanup(GPIO, smbus): - from grow import moisture - moisture.cleanup() - - GPIO.input.assert_called_with(moisture.MOISTURE_1_PIN, 0) - GPIO.input.assert_called_with(moisture.MOISTURE_2_PIN, 0) - GPIO.input.assert_called_with(moisture.MOISTURE_3_PIN, 0) def test_pump_setup(GPIO, smbus): - from grow import pump - moisture._is_setup = False - moisture.setup() - moisture.setup() + from grow.pump import Pump, PUMP_PWM_FREQ -def test_pump_cleanup(GPIO, smbus): - from grow import pump - pump.cleanup() + ch1 = Pump(channel=1) + ch2 = Pump(channel=2) + ch3 = Pump(channel=3) - GPIO.input.assert_called_with(moisture.PUMP_1_PIN, 0) - GPIO.input.assert_called_with(moisture.PUMP_2_PIN, 0) - GPIO.input.assert_called_with(moisture.PUMP_3_PIN, 0) + assert GPIO.setup.has_calls([ + mock.call(ch1._gpio_pin, GPIO.OUT, initial=GPIO.LOW), + mock.call(ch2._gpio_pin, GPIO.OUT, initial=GPIO.LOW), + mock.call(ch3._gpio_pin, GPIO.OUT, initial=GPIO.LOW) + ]) + + assert GPIO.PWM.has_calls([ + mock.call(ch1._gpio_pin, PUMP_PWM_FREQ), + mock.call(ch2._gpio_pin, PUMP_PWM_FREQ), + mock.call(ch3._gpio_pin, PUMP_PWM_FREQ) + ]) diff --git a/library/tox.ini b/library/tox.ini index aa96216..015a231 100644 --- a/library/tox.ini +++ b/library/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{27,35},qa +envlist = py{35,37},qa skip_missing_interpreters = True [testenv] @@ -14,11 +14,11 @@ deps = [testenv:qa] commands = - check-manifest --ignore tox.ini,tests*,.coveragerc - python setup.py check -m -r -s + check-manifest --ignore tox.ini,tests/*,.coveragerc + python setup.py sdist bdist_wheel + twine check dist/* flake8 --ignore E501 - rstcheck README.rst deps = check-manifest flake8 - rstcheck + twine