Skip to content

Commit

Permalink
Fixed #18, thx to swift
Browse files Browse the repository at this point in the history
  • Loading branch information
Tino de Bruijn committed Aug 17, 2013
1 parent 839fec5 commit 3d77096
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Empty file.
8 changes: 4 additions & 4 deletions pyfirmata/pyfirmata.py
Expand Up @@ -293,10 +293,10 @@ def servo_config(self, pin, min_pulse=544, max_pulse=2400, angle=0):
def exit(self):
""" Call this to exit cleanly. """
# First detach all servo's, otherwise it somehow doesn't want to close...
# FIXME
for pin in self.digital:
if pin.mode == SERVO:
pin.mode = OUTPUT
if hasattr(self, 'digital'):
for pin in self.digital:
if pin.mode == SERVO:
pin.mode = OUTPUT
if hasattr(self, 'sp'):
self.sp.close()

Expand Down
11 changes: 11 additions & 0 deletions tests.py
Expand Up @@ -334,6 +334,17 @@ def test_handle_digital_inputs(self):
self.assertEqual(self.board.digital[12].value, False)
self.assertEqual(self.board.digital[13].value, None)

def test_proper_exit_conditions(self):
"""
Test that the exit method works properly if we didn't make it all
the way through `setup_layout`.
"""
del self.board.digital
try:
self.board.exit()
except AttributeError:
self.fail("exit() raised an AttributeError unexpectedly!")


board_messages = unittest.TestLoader().loadTestsFromTestCase(TestBoardMessages)
board_layout = unittest.TestLoader().loadTestsFromTestCase(TestBoardLayout)
Expand Down

0 comments on commit 3d77096

Please sign in to comment.