Add cleanup before each test, to avoid cascading failures due to already-setup pins

Reformat file
This commit is contained in:
Matthew West 2016-08-10 09:07:40 -07:00
parent 472e2f964d
commit 08ea892889

View file

@ -1,9 +1,9 @@
import pytest
import glob
import os
import platform
import glob
import Adafruit_BBIO.PWM as PWM
import pytest
kernel = platform.release()
@ -14,6 +14,7 @@ def teardown_module(module):
class TestPwmSetup:
def test_start_pwm(self):
PWM.cleanup()
PWM.start("P9_14", 0)
if kernel >= '4.1.0':
@ -44,6 +45,7 @@ class TestPwmSetup:
PWM.cleanup()
def test_start_pwm_with_polarity_one(self):
PWM.cleanup()
PWM.start("P9_14", 0, 2000, 1)
if kernel >= '4.1.0':
@ -71,6 +73,7 @@ class TestPwmSetup:
PWM.cleanup()
def test_start_pwm_with_polarity_default(self):
PWM.cleanup()
PWM.start("P9_14", 0, 2000)
if kernel >= '4.1.0':
@ -98,6 +101,7 @@ class TestPwmSetup:
PWM.cleanup()
def test_start_pwm_with_polarity_zero(self):
PWM.cleanup()
PWM.start("P9_14", 0, 2000, 0)
if kernel >= '4.1.0':
@ -125,52 +129,64 @@ class TestPwmSetup:
PWM.cleanup()
def test_pwm_start_invalid_pwm_key(self):
PWM.cleanup()
with pytest.raises(ValueError):
PWM.start("P8_25", -1)
def test_pwm_start_invalid_duty_cycle_negative(self):
PWM.cleanup()
with pytest.raises(ValueError):
PWM.start("P9_14", -1)
def test_pwm_start_valid_duty_cycle_min(self):
PWM.cleanup()
# testing an exception isn't thrown
PWM.start("P9_14", 0)
PWM.cleanup()
def test_pwm_start_valid_duty_cycle_max(self):
PWM.cleanup()
# testing an exception isn't thrown
PWM.start("P9_14", 100)
PWM.cleanup()
def test_pwm_start_invalid_duty_cycle_high(self):
PWM.cleanup()
with pytest.raises(ValueError):
PWM.start("P9_14", 101)
def test_pwm_start_invalid_duty_cycle_string(self):
PWM.cleanup()
with pytest.raises(TypeError):
PWM.start("P9_14", "1")
def test_pwm_start_invalid_frequency_negative(self):
PWM.cleanup()
with pytest.raises(ValueError):
PWM.start("P9_14", 0, -1)
def test_pwm_start_invalid_frequency_string(self):
PWM.cleanup()
with pytest.raises(TypeError):
PWM.start("P9_14", 0, "1")
def test_pwm_start_negative_polarity(self):
PWM.cleanup()
with pytest.raises(ValueError):
PWM.start("P9_14", 0, 100, -1)
def test_pwm_start_invalid_positive_polarity(self):
PWM.cleanup()
with pytest.raises(ValueError):
PWM.start("P9_14", 0, 100, 2)
def test_pwm_start_invalid_polarity_type(self):
PWM.cleanup()
with pytest.raises(TypeError):
PWM.start("P9_14", 0, 100, "1")
def test_pwm_duty_modified(self):
PWM.cleanup()
PWM.start("P9_14", 0)
if kernel >= '4.1.0':
@ -201,51 +217,60 @@ class TestPwmSetup:
PWM.cleanup()
def test_pwm_duty_cycle_non_setup_key(self):
PWM.cleanup()
with pytest.raises(RuntimeError):
PWM.set_duty_cycle("P9_14", 100)
PWM.cleanup()
def test_pwm_duty_cycle_invalid_key(self):
PWM.cleanup()
with pytest.raises(ValueError):
PWM.set_duty_cycle("P9_15", 100)
PWM.cleanup()
def test_pwm_duty_cycle_invalid_value_high(self):
PWM.cleanup()
PWM.start("P9_14", 0)
with pytest.raises(ValueError):
PWM.set_duty_cycle("P9_14", 101)
PWM.cleanup()
def test_pwm_duty_cycle_invalid_value_negative(self):
PWM.cleanup()
PWM.start("P9_14", 0)
with pytest.raises(ValueError):
PWM.set_duty_cycle("P9_14", -1)
PWM.cleanup()
def test_pwm_duty_cycle_invalid_value_string(self):
PWM.cleanup()
PWM.start("P9_14", 0)
with pytest.raises(TypeError):
PWM.set_duty_cycle("P9_14", "a")
PWM.cleanup()
def test_pwm_frequency_invalid_value_negative(self):
PWM.cleanup()
PWM.start("P9_14", 0)
with pytest.raises(ValueError):
PWM.set_frequency("P9_14", -1)
PWM.cleanup()
def test_pwm_frequency_invalid_value_string(self):
PWM.cleanup()
PWM.start("P9_14", 0)
with pytest.raises(TypeError):
PWM.set_frequency("P9_14", "11")
PWM.cleanup()
def test_pwm_freq_non_setup_key(self):
PWM.cleanup()
with pytest.raises(RuntimeError):
PWM.set_frequency("P9_14", 100)
PWM.cleanup()
def test_pwm_freq_non_setup_invalid_key(self):
PWM.cleanup()
with pytest.raises(ValueError):
PWM.set_frequency("P9_15", 100)
PWM.cleanup()