Exemple #1
0
    def test_osc_light(self):
        self.client_instance.send_message = MagicMock()
        self.machine.lights["test_light1"].color("red")
        self.advance_time_and_run(.1)
        self.client_instance.send_message.assert_has_calls([
            call('/thing/light/blue/17', 0.0),
            call('/thing/light/green/17', 0.0),
            call('/thing/light/red/17', 1.0)
        ],
                                                           any_order=True)

        self.client_instance.send_message = MagicMock()
        self.machine.lights["test_light1"].color("blue")
        self.advance_time_and_run(.1)
        self.client_instance.send_message.assert_has_calls([
            call('/thing/light/blue/17', 1.0),
            call('/thing/light/green/17', 0.0),
            call('/thing/light/red/17', 0.0)
        ],
                                                           any_order=True)

        self.client_instance.send_message = MagicMock()
        self.machine.lights["test_light1"].color("white")
        self.advance_time_and_run(.1)
        self.client_instance.send_message.assert_has_calls([
            call('/thing/light/blue/17', 1.0),
            call('/thing/light/green/17', 1.0),
            call('/thing/light/red/17', 1.0)
        ],
                                                           any_order=True)
Exemple #2
0
 def setUp(self):
     client_class = patch('mpf.platforms.osc.SimpleUDPClient')
     self.client_class = client_class.start()
     self.client_instance = MagicMock()
     self.client_class.return_value = self.client_instance
     self.addCleanup(self.client_class.stop)
     super().setUp()
Exemple #3
0
 def setUp(self):
     smbus = patch('mpf.platforms.smbus2.SMBus2Asyncio')
     self.smbus = smbus.start()
     self.smbus_instance = MagicMock()
     self.smbus.return_value = self.smbus_instance
     self.addCleanup(self.smbus.stop)
     super().setUp()
Exemple #4
0
    def setUp(self):
        modules = {
            'PIL': MagicMock(),
            'PIL.Image': MagicMock(),
        }
        self.module_patcher = patch.dict('sys.modules', modules)
        self.module_patcher.start()
        Image = patch('mpf.platforms.rpi_dmd.Image')
        self.image = Image.start()

        RGBMatrix = patch('mpf.platforms.rpi_dmd.RGBMatrix')
        RGBMatrixOptions = patch('mpf.platforms.rpi_dmd.RGBMatrixOptions')
        self.rgbmatrixoptions = RGBMatrixOptions.start()
        self.rgbmatrix = RGBMatrix.start()
        self.rgbmatrix_instance = MagicMock()
        self.rgbmatrix.return_value = self.rgbmatrix_instance
        self.addCleanup(self.rgbmatrix.stop)
        super().setUp()
Exemple #5
0
 def test_bootloader_crash_ignored(self):
     # Test that RGB processor bootloader msgs can be ignored
     self.machine.default_platform.config['ignore_rgb_crash'] = True
     self.mock_event('fast_rgb_rebooted')
     self.machine.stop = MagicMock()
     self.machine.default_platform.process_received_message("!B:00", "RGB")
     self.advance_time_and_run(1)
     self.assertFalse(self.machine.stop.called)
     self.assertEventCalled('fast_rgb_rebooted')
Exemple #6
0
 def setUp(self):
     RGBMatrix = patch('mpf.platforms.rpi_dmd.RGBMatrix')
     RGBMatrixOptions = patch('mpf.platforms.rpi_dmd.RGBMatrixOptions')
     self.rgbmatrixoptions = RGBMatrixOptions.start()
     self.rgbmatrix = RGBMatrix.start()
     self.rgbmatrix_instance = MagicMock()
     self.rgbmatrix.return_value = self.rgbmatrix_instance
     self.addCleanup(self.rgbmatrix.stop)
     super().setUp()
Exemple #7
0
    def test_i2c(self):
        result = asyncio.Future(loop=self.loop)
        result.set_result(True)
        self.smbus_instance.write_byte_data = MagicMock(return_value=result)

        self.machine.default_platform.i2c_write8("1-17", 23, 1337)
        self.machine_run()
        self.smbus_instance.write_byte_data.assert_called_once_with(
            17, 23, 1337)
        self.smbus.assert_called_once_with('1', loop=self.loop)

        result = asyncio.Future(loop=self.loop)
        result.set_result(1337)
        self.smbus_instance.read_byte_data = MagicMock(return_value=result)
        self.assertEqual(
            1337,
            self.loop.run_until_complete(
                self.machine.default_platform.i2c_read8("1-17", 23)))
        self.smbus_instance.read_byte_data.assert_called_once_with(17, 23)
Exemple #8
0
    def test_i2c(self):
        self.machine.default_platform.i2c_write8("1-17", 23, 1337)
        self.smbus.write_byte_data.assert_called_once_with(17, 23, 1337)
        smbus2.SMBus.assert_called_once_with('1')

        self.smbus.read_byte_data = MagicMock(return_value=1337)
        self.assertEqual(
            1337,
            self.loop.run_until_complete(
                self.machine.default_platform.i2c_read8("1-17", 23)))
        self.smbus.read_byte_data.assert_called_once_with(17, 23)
Exemple #9
0
    def setUp(self):
        client_class = patch('mpf.platforms.osc.SimpleUDPClient')
        self.client_class = client_class.start()
        self.client_instance = MagicMock()
        self.client_class.return_value = self.client_instance

        dispatcher_class = patch('mpf.platforms.osc.Dispatcher')
        self.dispatcher_class = dispatcher_class.start()
        self.dispatcher_instance = MagicMock()
        self.dispatcher_class.return_value = self.dispatcher_instance

        server_class = patch('mpf.platforms.osc.AsyncIOOSCUDPServer')
        self.server_class = server_class.start()
        self.server_instance = MagicMock()
        self.server_instance.create_serve_endpoint = self._start_serve
        self.server_class.return_value = self.server_instance

        self.addCleanup(self.client_class.stop)
        self.addCleanup(self.dispatcher_class.stop)
        self.addCleanup(self.server_class.stop)
        super().setUp()
    def start_game(self):
        self.machine.playfield.add_ball = MagicMock()
        # self.machine.ball_controller.num_balls_known = 3
        self.assertModeRunning('attract')
        self.hit_switch_and_run("s_trough", 1)
        self.hit_and_release_switch("s_start")

        # All this stuff may be unnecessary but its what I need to do currently when I run mpf both -x
        self.release_switch_and_run("s_trough", 1)
        self.hit_and_release_switch("s_plunger")
        self.hit_and_release_switch("s_orbit_right")
        self.assertIsNotNone(self.machine.game)
    def test_step_stick(self):
        direction = self.machine.digital_outputs["c_direction"].hw_driver
        step_enable = self.machine.digital_outputs[
            "c_step"].hw_driver.enable = MagicMock()
        step_disable = self.machine.digital_outputs[
            "c_step"].hw_driver.disable = MagicMock()
        enable = self.machine.digital_outputs["c_enable"].hw_driver
        self.assertEqual("enabled", direction.state)
        self.assertEqual("enabled", enable.state)

        self.advance_time_and_run(1)

        self.assertEqual(25, step_enable.call_count)
        self.assertEqual(25, step_disable.call_count)

        self.hit_switch_and_run("s_home", .1)
        step_enable = self.machine.digital_outputs[
            "c_step"].hw_driver.enable = MagicMock()
        step_disable = self.machine.digital_outputs[
            "c_step"].hw_driver.disable = MagicMock()

        self.advance_time_and_run(1)
        self.assertEqual(0, step_enable.call_count)
        self.assertEqual(0, step_disable.call_count)

        self.post_event("test_01")
        self.advance_time_and_run(1)
        self.assertEqual("enabled", direction.state)
        self.assertEqual(20, step_enable.call_count)
        self.assertEqual(20, step_disable.call_count)

        step_enable = self.machine.digital_outputs[
            "c_step"].hw_driver.enable = MagicMock()
        step_disable = self.machine.digital_outputs[
            "c_step"].hw_driver.disable = MagicMock()
        self.post_event("test_00")
        self.advance_time_and_run(1)
        self.assertEqual("disabled", direction.state)
        self.assertEqual(10, step_enable.call_count)
        self.assertEqual(10, step_disable.call_count)

        step_enable = self.machine.digital_outputs[
            "c_step"].hw_driver.enable = MagicMock()
        step_disable = self.machine.digital_outputs[
            "c_step"].hw_driver.disable = MagicMock()
        self.post_event("test_10")
        self.advance_time_and_run(2)
        self.assertEqual("enabled", direction.state)
        self.assertEqual(40, step_enable.call_count)
        self.assertEqual(40, step_disable.call_count)
Exemple #12
0
    def setUp(self):
        self.expected_duration = 1.5
        self.serialMock = MockLisySocket(api_version=9)

        self.serialMock.permanent_commands = {
            b'\x29': b'\x7F',           # changed switches? -> no
            b'\x65': b'\x00'            # watchdog
        }

        self.serialMock.expected_commands = {
            b'\x00': b'APC\00',         # hw APC
            b'\x01': b'0.02\00',        # APC version
            b'\x02': b'0.09\00',        # api version
            b'\x64': b'\x00',           # reset -> ok
            b'\x03': b'\x28',           # get number of lamps -> 40
            b'\x04': b'\x09',           # get number of solenoids -> 9
            b'\x06': b'\x05',           # get number of displays -> 5
            b'\x07\x00': b'\x02\x10',   # get type of display 0
            b'\x07\x01': b'\x03\x05',   # get type of display 1
            b'\x07\x02': b'\x04\x07',   # get type of display 2
            b'\x07\x03': b'\x05\x03',   # get type of display 3
            b'\x07\x04': b'\x06\x10',   # get type of display 4
            b'\x09': b'\x58',           # get number of switches -> 88
            b'\x13': b'\x00',           # get number of modern lights -> 0
            b'\x1e\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00': None,  # clear display
            b'\x1f\x05\x00\x00\x00\x00\x00': None,                                              # clear display
            b'\x20\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00': None,          # clear display
            b'\x21\x03\x20\x20\x20': None,                                                      # clear display
            b'\x22\x10\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20': None,  # clear display
            b'\x19\x00\x0a': None,
            b'\x19\x01\x0a': None,
            b'\x19\x67\xff': None,
            b'\x19\x05\x1e': None,
            b'\x19\x06\x0a': None,
            b'\x19\x07\x0a': None,
        }

        for number in range(88):
            if number % 10 >= 8:
                self.serialMock.expected_commands[bytes([40, number])] = b'\x02'
            else:
                self.serialMock.expected_commands[bytes([40, number])] = b'\x00' if number != 37 else b'\x01'

        # prevent changes on real hardware
        lisy.LisyHardwarePlatform._disable_dts_on_start_of_serial = MagicMock()

        super().setUp()

        lisy.LisyHardwarePlatform._disable_dts_on_start_of_serial.assert_called_with()

        self._wait_for_processing()
        self.assertFalse(self.serialMock.expected_commands)
Exemple #13
0
    def setUp(self):
        if sys.version_info[0] == 3 and sys.version_info[1] == 4:
            # this fails on python 3.4 because of some asyncio bugs
            self.skipTest("Test is unstable in Python 3.4")
            return
        self.expected_duration = 1.5
        self.serialMock = MockLisySocket()

        self.serialMock.permanent_commands = {
            b'\x29': b'\x7F',           # changed switches? -> no
            b'\x65': b'\x00'            # watchdog
        }

        self.serialMock.expected_commands = {
            b'\x00': b'APC\00',         # hw APC
            b'\x01': b'0.02\00',        # APC version
            b'\x02': b'0.09\00',        # api version
            b'\x64': b'\x00',           # reset -> ok
            b'\x03': b'\x28',           # get number of lamps -> 40
            b'\x04': b'\x09',           # get number of solenoids -> 9
            b'\x06': b'\x05',           # get number of displays -> 5
            b'\x07\x00': b'\x10\x02',   # get type of display 0
            b'\x07\x01': b'\x05\x03',   # get type of display 1
            b'\x07\x02': b'\x07\x04',   # get type of display 2
            b'\x07\x03': b'\x03\x05',   # get type of display 3
            b'\x07\x04': b'\x10\x06',   # get type of display 4
            b'\x09': b'\x58',           # get number of switches -> 88
            b'\x13': b'\x00',           # get number of modern lights -> 0
            b'\x1e\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00': None,  # clear display
            b'\x1f\x05\x00\x00\x00\x00\x00': None,                                              # clear display
            b'\x20\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00': None,          # clear display
            b'\x21\x03\x20\x20\x20': None,                                                      # clear display
            b'\x22\x10\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20': None,  # clear display
        }

        for number in range(88):
            if number % 10 >= 8:
                self.serialMock.expected_commands[bytes([40, number])] = b'\x02'
            else:
                self.serialMock.expected_commands[bytes([40, number])] = b'\x00' if number != 37 else b'\x01'

        # prevent changes on real hardware
        lisy.LisyHardwarePlatform._disable_dts_on_start_of_serial = MagicMock()

        super().setUp()

        lisy.LisyHardwarePlatform._disable_dts_on_start_of_serial.assert_called_with()

        self._wait_for_processing()
        self.assertFalse(self.serialMock.expected_commands)
Exemple #14
0
    def setUp(self):
        self.expected_duration = 1.5
        self.serialMock = MockLisySocket(api_version=10)

        self.serialMock.permanent_commands = {
            b'\x29': b'\x7F',  # changed switches? -> no
            b'\x65': b'\x00'  # watchdog
        }

        self.serialMock.expected_commands = {
            b'\x00': b'FUTURE_HARDWARE\00',  # hw not known yet
            b'\x01': b'0.42\00',  # hardware version
            b'\x02': b'0.10\00',  # api version
            b'\x64': b'\x00',  # reset -> ok
            b'\x03': b'\x00',  # get number of simple lamps -> 0
            b'\x04': b'\x09',  # get number of solenoids -> 9
            b'\x06': b'\x00',  # get number of displays -> 0
            b'\x09': b'\x58',  # get number of switches -> 88
            b'\x13':
            b'\x02\x01',  # get number of modern lights -> 512 + 1 = 513 modern lights
            b'\x19\x00\x0a': None,
            b'\x19\x01\x0a': None,
            b'\x19\x05\x1e': None,
            b'\x19\x06\x0a': None,
            b'\x19\x07\x0a': None,
        }

        for number in range(88):
            if number % 10 >= 8:
                self.serialMock.expected_commands[bytes([40,
                                                         number])] = b'\x02'
            else:
                self.serialMock.expected_commands[bytes(
                    [40, number])] = b'\x00' if number != 37 else b'\x01'

        # prevent changes on real hardware
        lisy.LisyHardwarePlatform._disable_dts_on_start_of_serial = MagicMock()

        super().setUp()

        lisy.LisyHardwarePlatform._disable_dts_on_start_of_serial.assert_called_with(
        )

        self._wait_for_processing()
        self.assertFalse(self.serialMock.expected_commands)
Exemple #15
0
    def test_ac_switch_and_enable(self):

        c_side_a2 = self._get_a_driver(self.machine.coils.c_side_a2)
        c_side_c2 = self._get_c_driver(self.machine.coils.c_side_c2)

        c_side_a2.enable = MagicMock()
        c_side_a2.disable = MagicMock()
        c_side_c2.enable = MagicMock()
        c_side_c2.disable = MagicMock()

        c_ac_relay = self.machine.coils.c_ac_relay
        c_ac_relay.enable = MagicMock()
        c_ac_relay.disable = MagicMock()

        self.advance_time_and_run(0.10)

        # test enable on c side
        self.machine.coils.c_side_c2.enable()
        self.machine_run()
        c_ac_relay.enable.assert_called_with()
        c_ac_relay.enable = MagicMock()
        assert not c_side_c2.enable.called
        self.advance_time_and_run(0.075)
        c_side_c2.enable.assert_called_with(
            PulseSettings(power=1.0, duration=10), HoldSettings(power=0.5))

        # a side has preference. it should transition
        self.machine.coils.c_side_a2.enable()
        self.machine_run()
        c_side_c2.disable.assert_called_with()
        c_ac_relay.disable.assert_called_with()
        c_ac_relay.disable = MagicMock()
        assert not c_side_a2.enable.called

        # it should enable a side coils now
        self.advance_time_and_run(0.075)
        c_side_a2.enable.assert_called_with(
            PulseSettings(power=1.0, duration=10), HoldSettings(power=0.5))

        # disable driver on a side.
        self.machine.coils.c_side_a2.disable()
        self.advance_time_and_run(0.2)
Exemple #16
0
    def test_ac_switch_and_enable(self):

        c_side_a2 = self._get_a_driver(self.machine.coils.c_side_a2)
        c_side_c2 = self._get_c_driver(self.machine.coils.c_side_c2)

        c_side_a2.enable = MagicMock()
        c_side_a2.disable = MagicMock()
        c_side_c2.enable = MagicMock()
        c_side_c2.disable = MagicMock()

        c_ac_relay = self.machine.coils.c_ac_relay
        c_ac_relay.enable = MagicMock()
        c_ac_relay.disable = MagicMock()

        self.advance_time_and_run(0.10)

        # test enable on c side
        self.machine.coils.c_side_c2.enable()
        self.machine_run()
        c_ac_relay.enable.assert_called_with()
        c_ac_relay.enable = MagicMock()
        assert not c_side_c2.enable.called
        self.advance_time_and_run(0.075)
        c_side_c2.enable.assert_called_with(
            self.machine.coils.c_side_c2.get_configured_driver())

        # a side has preference. it should transition
        self.machine.coils.c_side_a2.enable()
        self.machine_run()
        c_side_c2.disable.assert_called_with(ConfiguredHwDriver(c_side_c2, {}))
        c_ac_relay.disable.assert_called_with()
        assert not c_side_a2.enable.called

        # it should enable a side coils now
        self.advance_time_and_run(0.075)
        c_side_a2.enable.assert_called_with(
            self.machine.coils.c_side_a2.get_configured_driver())
Exemple #17
0
 async def _start_serve(self):
     return MagicMock(), None
Exemple #18
0
    def test_ac_switch_and_pulse(self):
        # test diag led flashing. otherwise snux is not running
        c_diag_led_driver = self.machine.coils.c_diag_led_driver
        c_diag_led_driver.pulse = MagicMock()
        self.advance_time_and_run(1)
        c_diag_led_driver.pulse.assert_called_with(250)

        # test if a and c side relays were properly loaded
        self.assertEqual(2, len(self._get_snux_platform().a_drivers))
        self.assertEqual(2, len(self._get_snux_platform().c_drivers))
        c_side_a1 = self._get_a_driver(self.machine.coils.c_side_a1)
        c_side_a2 = self._get_a_driver(self.machine.coils.c_side_a2)
        c_side_c1 = self._get_c_driver(self.machine.coils.c_side_c1)
        c_side_c2 = self._get_c_driver(self.machine.coils.c_side_c2)
        self.assertTrue(c_side_a1)
        self.assertTrue(c_side_a2)
        self.assertTrue(c_side_c1)
        self.assertTrue(c_side_c2)

        c_ac_relay = self.machine.coils.c_ac_relay
        c_ac_relay.enable = MagicMock()
        c_ac_relay.disable = MagicMock()

        c_side_a1.pulse = MagicMock()
        c_side_a2.enable = MagicMock()
        c_side_a2.disable = MagicMock()
        c_side_c1.pulse = MagicMock()
        c_side_c2.enable = MagicMock()
        c_side_c2.disable = MagicMock()

        # a side should be triggered first. c side should wait
        self.machine.coils.c_side_a1.pulse(50)
        self.machine.coils.c_side_c1.pulse(50)
        self.advance_time_and_run(0.001)
        c_side_a1.pulse.assert_called_with(
            PulseSettings(power=1.0, duration=50))
        c_side_a1.pulse = MagicMock()
        assert not c_side_c1.pulse.called
        assert not c_ac_relay.enable.called

        # after 50ms + 75ms transition c side should get triggered
        self.advance_time_and_run(0.075)
        c_ac_relay.enable.assert_called_with()
        c_ac_relay.enable = MagicMock()
        assert not c_side_a1.pulse.called
        assert not c_side_c1.pulse.called

        # after the relay switches. pulse the other coil
        self.advance_time_and_run(0.075)
        assert not c_side_a1.pulse.called
        c_side_c1.pulse.assert_called_with(
            PulseSettings(power=1.0, duration=50))

        # it should switch back to a side when idle
        self.advance_time_and_run(0.052)
        c_ac_relay.disable.assert_called_with()
        c_ac_relay.disable = MagicMock()
Exemple #19
0
    def test_osc_platform(self):
        # test lights
        self.client_instance.send_message = MagicMock()
        self.machine.lights["test_light1"].color("red")
        self.advance_time_and_run(.1)
        self.client_instance.send_message.assert_has_calls([
            call('/light/light1/blue', 0.0),
            call('/light/light1/green', 0.0),
            call('/light/light1/red', 1.0)
        ],
                                                           any_order=True)

        self.client_instance.send_message = MagicMock()
        self.machine.lights["test_light1"].color("blue")
        self.advance_time_and_run(.1)
        self.client_instance.send_message.assert_has_calls([
            call('/light/light1/blue', 1.0),
            call('/light/light1/green', 0.0),
            call('/light/light1/red', 0.0)
        ],
                                                           any_order=True)

        self.client_instance.send_message = MagicMock()
        self.machine.lights["test_light1"].color("white")
        self.advance_time_and_run(.1)
        self.client_instance.send_message.assert_has_calls([
            call('/light/light1/blue', 1.0),
            call('/light/light1/green', 1.0),
            call('/light/light1/red', 1.0)
        ],
                                                           any_order=True)

        self.client_instance.send_message = MagicMock()
        self.machine.lights["test_light2"].color("white")
        self.advance_time_and_run(.1)
        self.client_instance.send_message.assert_has_calls([
            call('/light/light2/blue', 1.0),
            call('/light/light2/green', 1.0),
            call('/light/light2/red', 1.0)
        ],
                                                           any_order=True)

        # send switch hits
        self.assertSwitchState("switch_abc", False)
        self.machine.default_platform._handle_switch("/sw/abc", True)
        self.advance_time_and_run(.1)
        self.assertSwitchState("switch_abc", True)
        self.machine.default_platform._handle_switch("/sw/abc", False)
        self.advance_time_and_run(.1)
        self.assertSwitchState("switch_abc", False)

        self.assertSwitchState("switch_1", False)
        self.machine.default_platform._handle_switch("/sw/1", True)
        self.advance_time_and_run(.1)
        self.assertSwitchState("switch_1", True)
        self.machine.default_platform._handle_switch("/sw/1", False)
        self.advance_time_and_run(.1)
        self.assertSwitchState("switch_1", False)

        # test outgoing events
        self.client_instance.send_message = MagicMock()
        self.post_event_with_params("my_test_event", a=100, b=True)
        self.advance_time_and_run(.1)
        self.client_instance.send_message.assert_has_calls(
            [call('/event/my_test_event', ['a', 100, 'b', True])],
            any_order=True)

        self.client_instance.send_message = MagicMock()
        self.post_event("my_other_test_event")
        self.advance_time_and_run(.1)
        self.client_instance.send_message.assert_has_calls(
            [call('/event/my_other_test_event', [])], any_order=True)

        # test incoming events
        self.mock_event("test_event")
        self.machine.default_platform._handle_event("/event/test_event", "a",
                                                    200, "b", "asd")
        self.advance_time_and_run(.1)
        self.assertEventCalledWith("test_event", a=200, b="asd")

        self.start_game()
        self.advance_time_and_run()

        self.client_instance.send_message.assert_has_calls([
            call('/event/player_turn_started',
                 ['number', 1, 'player', '<Player 1>'])
        ],
                                                           any_order=True)
Exemple #20
0
 def test_bootloader_crash(self):
     # Test that the machine stops if the RGB processor sends a bootloader msg
     self.machine.stop = MagicMock()
     self.machine.default_platform.process_received_message("!B:00", "RGB")
     self.advance_time_and_run(1)
     self.assertTrue(self.machine.stop.called)
Exemple #21
0
    def test_spi_bit_bang(self):

        # wait for o_cs low
        for i in range(100):
            if self.machine.digital_outputs[
                    "o_cs"].hw_driver.state == "enabled":
                break
            self.advance_time_and_run(.025)
        else:
            self.fail("Did not find o_cs high")
        self.machine.digital_outputs["o_clock"].hw_driver.pulse = MagicMock()
        # set bit 7
        self.hit_switch_and_run("s_miso", .05)
        self.assertEqual(
            1,
            self.machine.digital_outputs["o_clock"].hw_driver.pulse.call_count)
        # unset bit 6
        self.release_switch_and_run("s_miso", .05)
        self.assertEqual(
            2,
            self.machine.digital_outputs["o_clock"].hw_driver.pulse.call_count)
        # unset bit 5
        self.release_switch_and_run("s_miso", .05)
        self.assertEqual(
            3,
            self.machine.digital_outputs["o_clock"].hw_driver.pulse.call_count)
        # set bit 4
        self.hit_switch_and_run("s_miso", .05)
        self.assertEqual(
            4,
            self.machine.digital_outputs["o_clock"].hw_driver.pulse.call_count)
        # set bit 3
        self.hit_switch_and_run("s_miso", .05)
        self.assertEqual(
            5,
            self.machine.digital_outputs["o_clock"].hw_driver.pulse.call_count)
        # set bit 2
        self.hit_switch_and_run("s_miso", .05)
        self.assertEqual(
            6,
            self.machine.digital_outputs["o_clock"].hw_driver.pulse.call_count)
        # unset bit 1
        self.release_switch_and_run("s_miso", .05)
        self.assertEqual(
            7,
            self.machine.digital_outputs["o_clock"].hw_driver.pulse.call_count)
        # set bit 0
        self.hit_switch_and_run("s_miso", .05)
        self.assertEqual(
            8,
            self.machine.digital_outputs["o_clock"].hw_driver.pulse.call_count)
        self.advance_time_and_run(.1)

        self.assertSwitchState("s_trough_0", True)
        self.assertSwitchState("s_trough_1", False)
        self.assertSwitchState("s_trough_2", True)
        self.assertSwitchState("s_trough_3", True)
        self.assertSwitchState("s_trough_4", True)
        self.assertSwitchState("s_trough_5", False)
        self.assertSwitchState("s_trough_6", False)
        self.assertSwitchState("s_trough_7", True)
Exemple #22
0
 def _start_game(self):
     self.machine.playfield.add_ball = MagicMock()
     self.machine.ball_controller.num_balls_known = 3
     self.hit_and_release_switch("s_start")
     self.advance_time_and_run()
     self.assertIsNotNone(self.machine.game)
Exemple #23
0
 def setUp(self):
     smbus2.SMBus = MagicMock()
     self.smbus = MagicMock()
     smbus2.SMBus.return_value = self.smbus
     super().setUp()