From 29377cf24da9ae6c3d360605e654856cbd442dcd Mon Sep 17 00:00:00 2001 From: Robert Wolterman Date: Sun, 26 Feb 2017 21:04:40 -0600 Subject: [PATCH] updates to the pytest tests to fix the issues with pwm, added 2 new tests that bring in 5 total unit tests. python3 unit tests are passing, this will close #42 and close #47 --- CHANGELOG.rst | 6 ++++ CHIP_IO/OverlayManager.py | 7 +++-- Makefile | 39 ++++++++++++++++++++++-- README.rst | 11 +++---- debian/changelog | 8 +++++ debian/files | 4 +-- setup.py | 2 +- source/constants.c | 2 +- test/{ => integrations}/gptest.py | 0 test/{ => integrations}/lradctest.py | 0 test/{ => integrations}/omtest.py | 0 test/{ => integrations}/pwmtest.py | 0 test/{ => integrations}/servotest.py | 0 test/{ => integrations}/spwmtest.py | 0 test/integrations/spwmtest2.py | 45 ++++++++++++++++++++++++++++ test/test_lradc.py | 14 +++++++++ test/test_pwm_setup.py | 27 +++++++++-------- test/test_utilities.py | 11 +++++++ 18 files changed, 149 insertions(+), 27 deletions(-) rename test/{ => integrations}/gptest.py (100%) rename test/{ => integrations}/lradctest.py (100%) rename test/{ => integrations}/omtest.py (100%) rename test/{ => integrations}/pwmtest.py (100%) rename test/{ => integrations}/servotest.py (100%) rename test/{ => integrations}/spwmtest.py (100%) create mode 100644 test/integrations/spwmtest2.py create mode 100644 test/test_lradc.py create mode 100644 test/test_utilities.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 241d2a3..4f94287 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,9 @@ +0.5.3 +--- +* Fixes to the PWM pytest +* Added pytest for LRADC and Utilities +* Makefile updates for all the things + 0.5.2 --- * Updating Utilties to determine CHIP Pro better diff --git a/CHIP_IO/OverlayManager.py b/CHIP_IO/OverlayManager.py index e61a64a..043c939 100644 --- a/CHIP_IO/OverlayManager.py +++ b/CHIP_IO/OverlayManager.py @@ -20,7 +20,8 @@ import os import shutil import time -import Utilities as UT +import sys +from .Utilities import is_chip_pro DEBUG = False @@ -162,7 +163,7 @@ def load(overlay, path=""): return 1 # DETERMINE IF WE ARE A CHIP PRO AND WE ARE COMMANDED TO LOAD PWM0 - if UT.is_chip_pro() and overlay.upper() == "PWM0": + if is_chip_pro() and overlay.upper() == "PWM0": print("CHIP Pro supports PWM0 in base DTB, exiting") return 1 @@ -200,7 +201,7 @@ def unload(overlay): print("UNLOAD OVERLAY: {0}".format(overlay)) # DETERMINE IF WE ARE A CHIP PRO AND WE ARE COMMANDED TO UNLOAD PWM0 - if UT.is_chip_pro() and overlay.upper() == "PWM0": + if is_chip_pro() and overlay.upper() == "PWM0": print("CHIP Pro supports PWM0 in base DTB, exiting") return diff --git a/Makefile b/Makefile index 147a3bb..881553b 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,16 @@ +# PyPi Packaging package: clean + @echo " ** PACKAGING FOR PYPI **" python setup.py sdist +# PyPi Publishing publish: package + @echo " ** UPLOADING TO PYPI **" twine upload dist/* +# Clean all the things clean: + @echo " ** CLEANING CHIP_IO **" rm -rf CHIP_IO.* build dist rm -f *.pyo *.pyc rm -f *.egg @@ -12,14 +18,43 @@ clean: rm -rf debian/python-chip-io* rm -rf debian/python3-chip-io* -tests: - py.test +# Run all the tests +tests: pytest2 pytest3 +# Run the tests with Python 2 +pytest2: + @echo " ** RUNING CHIP_IO TESTS UNDER PYTHON 2 **" + pushd test; python -m pytest; popd + +# Run the tests with Python 3 +pytest3: + @echo " ** RUNING CHIP_IO TESTS UNDER PYTHON 3 **" + pushd test; python3 -m pytest; popd + +# Build all the things build: + @echo " ** BUILDING CHIP_IO: PYTHON 2 **" python setup.py build --force +# Install all the things install: build + @echo " ** INSTALLING CHIP_IO: PYTHON 2 **" python setup.py install --force +# Build for Python 3 +build3: + @echo " ** BUILDING CHIP_IO: PYTHON 3 **" + python3 setup.py build --force + +# Install for Python 3 +install3: build3 + @echo " ** INSTALLING CHIP_IO: PYTHON 3 **" + python3 setup.py install --force + +# Install for both Python 2 and 3 +all: install install3 + +# Create a deb file debfile: + @echo " ** BUILDING DEBIAN PACKAGES **" dpkg-buildpackage -rfakeroot -uc -b diff --git a/README.rst b/README.rst index ae14212..86a21ee 100644 --- a/README.rst +++ b/README.rst @@ -438,11 +438,12 @@ Install py.test to run the tests. You'll also need the python compiler package f To run the tests, do the following.:: # If only one version of Python is installed - sudo py.test - # If more than one version of Python - cd test - sudo python2 -m pytest - sudo python3 -m pytest + # Python 2 + sudo make pytest2 + # Python 3 + sudo make pytest3 + # If more than one version of Python, run through both + sudo make test **Credits** diff --git a/debian/changelog b/debian/changelog index d200864..0a3a1ae 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +chip-io (0.5.3-1) unstable; urgency=low + + * Fixes to the PWM pytest + * Added pytest for LRADC and Utilities + * Makefile updates for all the things + + -- Robert Wolterman Sun, 26 Feb 2017 20:46:00 -0600 + chip-io (0.5.2-1) unstable; urgency=low * Updating Utilities to determine CHIP Pro better diff --git a/debian/files b/debian/files index 6ea9694..5f46cfe 100644 --- a/debian/files +++ b/debian/files @@ -1,2 +1,2 @@ -python-chip-io_0.4.0-1_armhf.deb python optional -python3-chip-io_0.4.0-1_armhf.deb python optional +python-chip-io_0.5.3-1_armhf.deb python optional +python3-chip-io_0.5.3-1_armhf.deb python optional diff --git a/setup.py b/setup.py index 9e531e6..8d1d798 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ classifiers = ['Development Status :: 3 - Alpha', 'Topic :: System :: Hardware'] setup(name = 'CHIP_IO', - version = '0.5.2', + version = '0.5.3', author = 'Robert Wolterman', author_email = 'robert.wolterman@gmail.com', description = 'A module to control CHIP IO channels', diff --git a/source/constants.c b/source/constants.c index 8939154..15ad57d 100644 --- a/source/constants.c +++ b/source/constants.c @@ -85,6 +85,6 @@ void define_constants(PyObject *module) bcm = Py_BuildValue("i", BCM); PyModule_AddObject(module, "BCM", bcm); - version = Py_BuildValue("s", "0.5.2"); + version = Py_BuildValue("s", "0.5.3"); PyModule_AddObject(module, "VERSION", version); } diff --git a/test/gptest.py b/test/integrations/gptest.py similarity index 100% rename from test/gptest.py rename to test/integrations/gptest.py diff --git a/test/lradctest.py b/test/integrations/lradctest.py similarity index 100% rename from test/lradctest.py rename to test/integrations/lradctest.py diff --git a/test/omtest.py b/test/integrations/omtest.py similarity index 100% rename from test/omtest.py rename to test/integrations/omtest.py diff --git a/test/pwmtest.py b/test/integrations/pwmtest.py similarity index 100% rename from test/pwmtest.py rename to test/integrations/pwmtest.py diff --git a/test/servotest.py b/test/integrations/servotest.py similarity index 100% rename from test/servotest.py rename to test/integrations/servotest.py diff --git a/test/spwmtest.py b/test/integrations/spwmtest.py similarity index 100% rename from test/spwmtest.py rename to test/integrations/spwmtest.py diff --git a/test/integrations/spwmtest2.py b/test/integrations/spwmtest2.py new file mode 100644 index 0000000..3c940d0 --- /dev/null +++ b/test/integrations/spwmtest2.py @@ -0,0 +1,45 @@ +#!/usr/bin/python + +import CHIP_IO.SOFTPWM as PWM +import CHIP_IO.GPIO as GPIO +import CHIP_IO.OverlayManager as OM +import time +import datetime + +if __name__ == "__main__": + # SETUP VARIABLES + PWMGPIO = "XIO-P7" + #PWMGPIO = "LCD-D4" + COUNT = 150 + SLEEPTIME = 0.01 + + time.sleep(1) + + # SETUP PWM + try: + print("PWM START") + #PWM.toggle_debug() + PWM.start(PWMGPIO, 50, 45, 1) + + # UNCOMMENT FOR CRASH + print("PWM SET FREQUENCY") + PWM.set_frequency(PWMGPIO, 10) + + # UNCOMMENT FOR CRASH + print("PWM SET DUTY CYCLE") + PWM.set_duty_cycle(PWMGPIO, 25) + + #time.sleep(COUNT*SLEEPTIME + 1) + raw_input("PRESS ENTER WHEN DONE") + + except: + raise + finally: + # CLEANUP + print("CLEANUP") + PWM.stop(PWMGPIO) + PWM.cleanup() + #OM.unload("PWM0") + #GPIO.cleanup() + + diff --git a/test/test_lradc.py b/test/test_lradc.py new file mode 100644 index 0000000..e1030e5 --- /dev/null +++ b/test/test_lradc.py @@ -0,0 +1,14 @@ +import pytest + +import CHIP_IO.LRADC as LRADC + +class TestLRADC: + def test_scale_factor(self): + assert LRADC.get_scale_factor() == 31.25 + + def test_sample_rate_values(self): + assert LRADC.get_allowable_sample_rates() == (32.25, 62.5, 125, 250) + + def test_set_sample_rate(self): + LRADC.set_sample_rate(32.25) + assert LRADC.get_sample_rate() == 32.25 diff --git a/test/test_pwm_setup.py b/test/test_pwm_setup.py index 6fb68d1..bdc9810 100644 --- a/test/test_pwm_setup.py +++ b/test/test_pwm_setup.py @@ -4,29 +4,22 @@ import time import CHIP_IO.PWM as PWM import CHIP_IO.OverlayManager as OM +import CHIP_IO.Utilities as UT def setup_module(module): - OM.load("PWM0") + if not UT.is_chip_pro(): + OM.load("PWM0") def teardown_module(module): PWM.cleanup() - OM.unload("PWM0") + if not UT.is_chip_pro(): + OM.unload("PWM0") class TestPwmSetup: def setup_method(self, test_method): time.sleep(0.5) - #def teardown_method(self, test_method): - # PWM.cleanup() - #OM.unload("PWM0") - - #def setup_module(self, module): - # OM.load("PWM0") - - #def teardown_module(self, module): - # OM.unload("PWM0") - def test_start_pwm(self): PWM.start("PWM0", 0) @@ -91,10 +84,12 @@ class TestPwmSetup: def test_pwm_start_valid_duty_cycle_min(self): #testing an exception isn't thrown PWM.start("PWM0", 0) + PWM.cleanup() def test_pwm_start_valid_duty_cycle_max(self): #testing an exception isn't thrown PWM.start("PWM0", 100) + PWM.cleanup() def test_pwm_start_invalid_duty_cycle_high(self): with pytest.raises(ValueError): @@ -143,7 +138,8 @@ class TestPwmSetup: assert int(period) == 500000 def test_pwm_duty_cycle_non_setup_key(self): - with pytest.raises(RuntimeError): + with pytest.raises(ValueError): + PWM.cleanup() PWM.set_duty_cycle("PWM0", 100) def test_pwm_duty_cycle_invalid_key(self): @@ -154,26 +150,31 @@ class TestPwmSetup: PWM.start("PWM0", 0) with pytest.raises(ValueError): PWM.set_duty_cycle("PWM0", 101) + PWM.cleanup() def test_pwm_duty_cycle_invalid_value_negative(self): PWM.start("PWM0", 0) with pytest.raises(ValueError): PWM.set_duty_cycle("PWM0", -1) + PWM.cleanup() def test_pwm_duty_cycle_invalid_value_string(self): PWM.start("PWM0", 0) with pytest.raises(TypeError): PWM.set_duty_cycle("PWM0", "a") + PWM.cleanup() def test_pwm_frequency_invalid_value_negative(self): PWM.start("PWM0", 0) with pytest.raises(ValueError): PWM.set_frequency("PWM0", -1) + PWM.cleanup() def test_pwm_frequency_invalid_value_string(self): PWM.start("PWM0", 0) with pytest.raises(TypeError): PWM.set_frequency("PWM0", "11") + PWM.cleanup() def test_pwm_freq_non_setup_key(self): with pytest.raises(RuntimeError): diff --git a/test/test_utilities.py b/test/test_utilities.py new file mode 100644 index 0000000..66d29b2 --- /dev/null +++ b/test/test_utilities.py @@ -0,0 +1,11 @@ +import pytest + +import CHIP_IO.Utilities as UT + +class TestUtilities: + def test_invalid_set_1v8_with_string(self): + assert not UT.set_1v8_pin_voltage("yaystring") + + def test_invalid_set_1v8_with_outofbounds_value(self): + assert not UT.set_1v8_pin_voltage(0.5) + assert not UT.set_1v8_pin_voltage(4.5)