Skip to content

Commit

Permalink
Fix flake8 errors (or ignore them :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tino de Bruijn committed Oct 29, 2016
1 parent c5a5614 commit d452762
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 40 deletions.
2 changes: 2 additions & 0 deletions pyfirmata/__init__.py
@@ -1,4 +1,6 @@
from .pyfirmata import * # NOQA
# TODO: should change above import to an explicit list, but people might rely on
# it, so do it in a backwards breaking release
from .boards import BOARDS

__version__ = '1.0.3' # Use bumpversion!
Expand Down
3 changes: 2 additions & 1 deletion pyfirmata/mockup.py
Expand Up @@ -120,7 +120,8 @@ def write(self, value):
if self.mode == pyfirmata.UNAVAILABLE:
raise IOError("Cannot read from pin {0}".format(self.pin_number))
if self.mode == pyfirmata.INPUT:
raise IOError("{0} pin {1} is not an output".format(self.port and "Digital" or "Analog", self.get_pin_number()))
raise IOError("{0} pin {1} is not an output"
.format(self.port and "Digital" or "Analog", self.get_pin_number()))
if not self.port:
raise AttributeError("AnalogPin instance has no attribute 'write'")
# if value != self.read():
Expand Down
17 changes: 11 additions & 6 deletions pyfirmata/pyfirmata.py
Expand Up @@ -169,7 +169,7 @@ def auto_setup(self):
"""
self.add_cmd_handler(CAPABILITY_RESPONSE, self._handle_report_capability_response)
self.send_sysex(CAPABILITY_QUERY, [])
self.pass_time(0.1) # Serial SYNC
self.pass_time(0.1) # Serial SYNC

while self.bytes_available():
self.iterate()
Expand Down Expand Up @@ -215,11 +215,15 @@ def get_pin(self, pin_def):
part = getattr(self, a_d)
pin_nr = int(bits[1])
if pin_nr >= len(part):
raise InvalidPinDefError('Invalid pin definition: {0} at position 3 on {1}'.format(pin_def, self.name))
raise InvalidPinDefError('Invalid pin definition: {0} at position 3 on {1}'
.format(pin_def, self.name))
if getattr(part[pin_nr], 'mode', None) == UNAVAILABLE:
raise InvalidPinDefError('Invalid pin definition: UNAVAILABLE pin {0} at position on {1}'.format(pin_def, self.name))
raise InvalidPinDefError('Invalid pin definition: '
'UNAVAILABLE pin {0} at position on {1}'
.format(pin_def, self.name))
if self.taken[a_d][pin_nr]:
raise PinAlreadyTakenError('{0} pin {1} is already taken on {2}'.format(a_d, bits[1], self.name))
raise PinAlreadyTakenError('{0} pin {1} is already taken on {2}'
.format(a_d, bits[1], self.name))
# ok, should be available
pin = part[pin_nr]
self.taken[a_d][pin_nr] = True
Expand Down Expand Up @@ -461,7 +465,7 @@ def _set_mode(self, mode):
if mode == SERVO:
if self.type != DIGITAL:
raise IOError("Only digital pins can drive servos! {0} is not"
"digital".format(self))
"digital".format(self))
self._mode = SERVO
self.board.servo_config(self.pin_number)
return
Expand Down Expand Up @@ -525,7 +529,8 @@ def write(self, value):
if self.mode is UNAVAILABLE:
raise IOError("{0} can not be used through Firmata".format(self))
if self.mode is INPUT:
raise IOError("{0} is set up as an INPUT and can therefore not be written to".format(self))
raise IOError("{0} is set up as an INPUT and can therefore not be written to"
.format(self))
if value is not self.value:
self.value = value
if self.mode is OUTPUT:
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -16,3 +16,4 @@ universal = true
[flake8]
max_line_length = 99
exclude = docs
ignore = W503,F405
68 changes: 35 additions & 33 deletions tests.py
Expand Up @@ -135,41 +135,41 @@ def test_handle_capability_response(self):
'analog': (0, 1),
'pwm': (1, 2),
'servo': (0, 1, 2),
# 'i2c': (2), # TODO 2.3 specs
# 'i2c': (2), # TODO 2.3 specs
'disabled': (0,),
}

# Eg: (127)
unavailible_pin = [
0x7F, # END_SYSEX (Pin delimiter)
0x7F, # END_SYSEX (Pin delimiter)
]

# Eg: (0, 1, 1, 1, 3, 8, 4, 14, 127)
digital_pin = [
0x00, # INPUT
0x01,
0x01, # OUTPUT
0x01,
0x03, # PWM
0x08,
0x7F, # END_SYSEX (Pin delimiter)
0x00, # INPUT
0x01,
0x01, # OUTPUT
0x01,
0x03, # PWM
0x08,
0x7F, # END_SYSEX (Pin delimiter)
]

# Eg. (0, 1, 1, 1, 4, 14, 127)
analog_pin = [
0x00, # INPUT
0x01,
0x01, # OUTPUT
0x01,
0x02, # ANALOG
0x0A,
0x06, # I2C
0x01,
0x7F, # END_SYSEX (Pin delimiter)
0x00, # INPUT
0x01,
0x01, # OUTPUT
0x01,
0x02, # ANALOG
0x0A,
0x06, # I2C
0x01,
0x7F, # END_SYSEX (Pin delimiter)
]

data_arduino = list(
[0x6C] # CAPABILITY_RESPONSE
[0x6C] # CAPABILITY_RESPONSE
+ unavailible_pin
+ digital_pin * 2
+ analog_pin * 2
Expand Down Expand Up @@ -273,8 +273,7 @@ def test_send_sysex_too_big_data(self):
self.assertRaises(ValueError, self.board.send_sysex, 0x79, [256, 1])

def test_receive_sysex_message(self):
sysex = bytearray([0xF0, 0x79, 2, 1, ord('a'), 0, ord('b'),
0, ord('c'), 0, 0xF7])
sysex = bytearray([0xF0, 0x79, 2, 1, ord('a'), 0, ord('b'), 0, ord('c'), 0, 0xF7])
self.board.sp.write(sysex)
while len(self.board.sp):
self.board.iterate()
Expand Down Expand Up @@ -315,22 +314,24 @@ def test_too_much_data(self):
# 10 angle MSB
def test_servo_config(self):
self.board.servo_config(2)
data = chain([0xF0, 0x70, 2], to_two_bytes(544),
to_two_bytes(2400), [0xF7, 0xE0 + 2, 0, 0])
data = chain([0xF0, 0x70, 2],
to_two_bytes(544),
to_two_bytes(2400),
[0xF7, 0xE0 + 2, 0, 0])
self.assert_serial(*list(data))

def test_servo_config_min_max_pulse(self):
self.board.servo_config(2, 600, 2000)
data = chain([0xF0, 0x70, 2], to_two_bytes(600),
to_two_bytes(2000), [0xF7, 0xE0 + 2, 0, 0])
data = chain([0xF0, 0x70, 2],
to_two_bytes(600),
to_two_bytes(2000),
[0xF7, 0xE0 + 2, 0, 0])
self.assert_serial(*data)

def test_servo_config_min_max_pulse_angle(self):
self.board.servo_config(2, 600, 2000, angle=90)
data = chain([0xF0, 0x70, 2], to_two_bytes(600),
to_two_bytes(2000), [0xF7])
angle_set = [0xE0 + 2, 90 % 128,
90 >> 7] # Angle set happens through analog message
data = chain([0xF0, 0x70, 2], to_two_bytes(600), to_two_bytes(2000), [0xF7])
angle_set = [0xE0 + 2, 90 % 128, 90 >> 7] # Angle set happens through analog message
data = list(data) + angle_set
self.assert_serial(*data)

Expand All @@ -340,8 +341,10 @@ def test_servo_config_invalid_pin(self):
def test_set_mode_servo(self):
p = self.board.digital[2]
p.mode = pyfirmata.SERVO
data = chain([0xF0, 0x70, 2], to_two_bytes(544),
to_two_bytes(2400), [0xF7, 0xE0 + 2, 0, 0])
data = chain([0xF0, 0x70, 2],
to_two_bytes(544),
to_two_bytes(2400),
[0xF7, 0xE0 + 2, 0, 0])
self.assert_serial(*data)


Expand Down Expand Up @@ -431,8 +434,7 @@ def test_correct_digital_input_first_pin_issue_9(self):
pin = self.board.get_pin('d:8:i')
mask = 0
mask |= 1 << 0 # set pin 0 high
self.board._handle_digital_message(pin.port.port_number,
mask % 128, mask >> 7)
self.board._handle_digital_message(pin.port.port_number, mask % 128, mask >> 7)
self.assertEqual(pin.value, True)

def test_handle_digital_inputs(self):
Expand Down

0 comments on commit d452762

Please sign in to comment.