/
test_Motors.py
68 lines (54 loc) · 2.06 KB
/
test_Motors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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()