def test_start_pwm(self):
        PWM.start("P9_14", 0)

        files = os.listdir('/sys/devices')
        ocp = '/sys/devices/'+[s for s in files if s.startswith('ocp')][0]
        files = os.listdir(ocp)
        pwm_test = ocp+'/'+[s for s in files if s.startswith('pwm_test_P9_14')][0]

        assert os.path.exists(pwm_test)
        duty = open(pwm_test + '/duty').read()
        period = open(pwm_test + '/period').read()
        assert int(duty) == 0
        assert int(period) == 500000
        PWM.cleanup()
 def test_pwm_duty_cycle_invalid_value_negative(self):
     PWM.start("P9_14", 0)
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("P9_14", -1)
         PWM.cleanup()            
 def test_pwm_duty_cycle_non_setup_key(self):
     with pytest.raises(RuntimeError):
         PWM.set_duty_cycle("P9_14", 100)
         PWM.cleanup()    
 def test_pwm_duty_cycle_invalid_key(self):
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("P9_15", 100)
         PWM.cleanup()                  
 def test_pwm_start_valid_duty_cycle_max(self):
     #testing an exception isn't thrown
     PWM.start("P9_14", 100)  
     PWM.cleanup()            
def teardown_module(module):
    PWM.cleanup()
 def test_pwm_freq_non_setup_key(self):
     with pytest.raises(ValueError):
         PWM.set_frequency("P9_15", 100)
         PWM.cleanup()                            
 def test_pwm_frequency_invalid_value_string(self):
     PWM.start("P9_14", 0)
     with pytest.raises(TypeError):
         PWM.set_frequency("P9_14", "11")
         PWM.cleanup()
 def test_pwm_frequency_invalid_value_negative(self):
     PWM.start("P9_14", 0)
     with pytest.raises(ValueError):
         PWM.set_frequency("P9_14", -1)
         PWM.cleanup()            
 def test_pwm_duty_cycle_invalid_value_string(self):
     PWM.start("P9_14", 0)
     with pytest.raises(TypeError):
         PWM.set_duty_cycle("P9_14", "a")
         PWM.cleanup()               
Exemplo n.º 11
0
                        #this will eventually be used to send sensor data back to command
                        s.sendall(last)
                except KeyboardInterrupt:
                    raise
                except: 
                    s.close()
                    print 'CONNECTION LOST: ATTEMPTING RECONNECT -- '# + msg[1]

            #loop to beginning
            except socket.error, msg:
                print 'Send failed: '
            except KeyboardInterrupt:
                raise

        except socket.error, msg:
            print 'Failed to create socket. Error code: ' + str(msg[0]) + ' Error message: ' + msg[1]
        except KeyboardInterrupt:
               print 'Closing socket...'
               s.close()
               print 'Shutting down PWM outputs...'
               PWM.cleanup()
               time.sleep(.5)
               sys.exit()


# Allow use as a module or standalone script
if __name__ == "__main__":
    main()