mirror of
https://github.com/xtacocorex/CHIP_IO
synced 2025-07-20 12:53:22 +00:00
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
This commit is contained in:
45
test/integrations/spwmtest2.py
Normal file
45
test/integrations/spwmtest2.py
Normal file
@ -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()
|
||||
|
||||
|
14
test/test_lradc.py
Normal file
14
test/test_lradc.py
Normal file
@ -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
|
@ -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):
|
||||
|
11
test/test_utilities.py
Normal file
11
test/test_utilities.py
Normal file
@ -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)
|
Reference in New Issue
Block a user