Skip to content

Commit

Permalink
add test for Motor device
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdoa2 committed May 21, 2016
1 parent 6d4fa75 commit 7989355
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
24 changes: 24 additions & 0 deletions mpf/tests/machine_files/motor/config/config.yaml
@@ -0,0 +1,24 @@
#config_version=4

switches:
s_position_up:
number:
s_position_down:
number:

coils:
c_motor_run:
number:
allow_enable: True

motors:
motorized_drop_target_bank:
motor_coil: c_motor_run
position_switches:
up: s_position_up
down: s_position_down
reset_position: down
go_to_position:
go_up: up
go_down: down
go_down2: down
68 changes: 68 additions & 0 deletions mpf/tests/test_Motors.py
@@ -0,0 +1,68 @@
from unittest.mock import MagicMock

from mpf.tests.MpfTestCase import MpfTestCase


class TestMotors(MpfTestCase):

def getConfigFile(self):
return 'config.yaml'

def getMachinePath(self):
return 'tests/machine_files/motor/'

def testMotorizedDropTargetBank(self):
motor = self.machine.motors.motorized_drop_target_bank
coil = self.machine.coils.c_motor_run
coil.enable = MagicMock()
coil.disable = MagicMock()

# reset should move it down
motor.reset()
self.advance_time_and_run()
coil.enable.assert_called_with()
coil.enable = MagicMock()
assert not coil.disable.called

# it goes up. nothing should happen
self.hit_switch_and_run("s_position_up", 1)
assert not coil.enable.called
assert not coil.disable.called

# it leaves up position
self.release_switch_and_run("s_position_up", 1)
assert not coil.enable.called
assert not coil.disable.called

self.advance_time_and_run(5)
# it goes down. motor should stop
self.hit_switch_and_run("s_position_down", 1)
assert not coil.enable.called
coil.disable.assert_called_with()
coil.disable = MagicMock()

# should not start motor
self.post_event("go_down2")
self.advance_time_and_run()
assert not coil.enable.called
coil.disable.assert_called_with()
coil.disable = MagicMock()

# go up
self.post_event("go_up")
self.advance_time_and_run()
coil.enable.assert_called_with()
coil.enable = MagicMock()
assert not coil.disable.called

# it leaves down position
self.release_switch_and_run("s_position_down", 0)
assert not coil.enable.called
assert not coil.disable.called

self.advance_time_and_run(5)
# it goes up. motor should stop
self.hit_switch_and_run("s_position_up", 1)
assert not coil.enable.called
coil.disable.assert_called_with()
coil.disable = MagicMock()

0 comments on commit 7989355

Please sign in to comment.