def test_single(self): self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule = MagicMock( ) self.machine.flippers["f_test_single"].enable() self.assertEqual( 1, len(self.machine.default_platform. set_pulse_on_hit_and_enable_and_release_rule. _mock_call_args_list)) self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule.assert_called_once_with( SwitchSettings( hw_switch=self.machine.switches["s_flipper"].hw_switch, invert=False, debounce=False), DriverSettings( hw_driver=self.machine.coils["c_flipper_main"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=10), hold_settings=HoldSettings(power=0.125), recycle=False)) self.machine.default_platform.clear_hw_rule = MagicMock() self.machine.flippers["f_test_single"].disable() self.assertEqual(1, self.machine.default_platform.clear_hw_rule.called) self.machine.default_platform.clear_hw_rule.assert_called_once_with( SwitchSettings( hw_switch=self.machine.switches["s_flipper"].hw_switch, invert=False, debounce=False), DriverSettings( hw_driver=self.machine.coils["c_flipper_main"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=10), hold_settings=HoldSettings(power=0.125), recycle=False))
def test_hw_rule_pulse_inverted_autofire(self): self.machine.default_platform.set_pulse_on_hit_rule = MagicMock() self.machine.autofires["ac_test_inverted2"].enable() self.machine.default_platform.set_pulse_on_hit_rule.assert_called_once_with( SwitchSettings(hw_switch=self.machine.switches["s_test"].hw_switch, invert=True, debounce=False), DriverSettings(hw_driver=self.machine.coils["c_test2"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=23), hold_settings=None, recycle=True)) self.machine.default_platform.clear_hw_rule = MagicMock() self.machine.autofires["ac_test_inverted2"].disable() self.machine.default_platform.clear_hw_rule.assert_called_once_with( SwitchSettings(hw_switch=self.machine.switches["s_test"].hw_switch, invert=True, debounce=False), DriverSettings(hw_driver=self.machine.coils["c_test2"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=23), hold_settings=None, recycle=True))
def test_flipper_with_settings(self): flipper = self.machine.flippers.f_test_flippers_with_settings self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule = MagicMock( ) flipper.enable() self.assertEqual( 1, len(self.machine.default_platform. set_pulse_on_hit_and_enable_and_release_rule. _mock_call_args_list)) self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule.assert_called_once_with( SwitchSettings(hw_switch=self.machine.switches.s_flipper.hw_switch, invert=False, debounce=False), DriverSettings( hw_driver=self.machine.coils.c_flipper_main.hw_driver, pulse_settings=PulseSettings(power=1.0, duration=10), hold_settings=HoldSettings(power=0.125), recycle=False)) self.machine.default_platform.clear_hw_rule = MagicMock() flipper.disable() self.assertEqual(1, self.machine.default_platform.clear_hw_rule.called) self.machine.default_platform.clear_hw_rule.assert_called_once_with( SwitchSettings(hw_switch=self.machine.switches.s_flipper.hw_switch, invert=False, debounce=False), DriverSettings( hw_driver=self.machine.coils.c_flipper_main.hw_driver, pulse_settings=PulseSettings(power=1.0, duration=10), hold_settings=HoldSettings(power=0.125), recycle=False)) self.machine.settings.set_setting_value("flipper_power", 0.8) self.advance_time_and_run() self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule = MagicMock( ) flipper.enable() self.assertEqual( 1, len(self.machine.default_platform. set_pulse_on_hit_and_enable_and_release_rule. _mock_call_args_list)) self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule.assert_called_once_with( SwitchSettings(hw_switch=self.machine.switches.s_flipper.hw_switch, invert=False, debounce=False), DriverSettings( hw_driver=self.machine.coils.c_flipper_main.hw_driver, pulse_settings=PulseSettings(power=1.0, duration=8), hold_settings=HoldSettings(power=0.125), recycle=False)) self.assertEqual(8, flipper._get_pulse_ms())
def test_kickback_with_ball_save(self): self.machine.default_platform.set_pulse_on_hit_rule = MagicMock() self.mock_event("kickback_kickback_test_fired") self.assertFalse(self.machine.ball_saves["kickback_save"].enabled) # kickback is not enabled. nothing should happen self.hit_and_release_switch("s_kickback") self.advance_time_and_run(.01) self.assertEventNotCalled("kickback_kickback_test_fired") # enable kickback self.post_event("kickback_enable") self.advance_time_and_run(.01) # should write a hw rule self.machine.default_platform.set_pulse_on_hit_rule.assert_called_once_with( SwitchSettings( hw_switch=self.machine.switches["s_kickback"].hw_switch, invert=False, debounce=False), DriverSettings( hw_driver=self.machine.coils["kickback_coil"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=100), hold_settings=None, recycle=True)) # a hit should fire it self.hit_and_release_switch("s_kickback") self.advance_time_and_run(.01) self.assertEventCalled("kickback_kickback_test_fired") # ball save should be enabled just in case self.assertTrue(self.machine.ball_saves["kickback_save"].enabled) # but disable after 6s self.advance_time_and_run(6.1) self.assertFalse(self.machine.ball_saves["kickback_save"].enabled) # it only works once though self.mock_event("kickback_kickback_test_fired") self.hit_and_release_switch("s_kickback") self.advance_time_and_run(.01) self.assertEventNotCalled("kickback_kickback_test_fired")
def test_hold_with_eos(self): self.machine.default_platform.set_pulse_on_hit_and_release_and_disable_rule = MagicMock() self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule = MagicMock() self.machine.flippers["f_test_hold_eos"].enable() self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule.assert_called_once_with( SwitchSettings(hw_switch=self.machine.switches["s_flipper"].hw_switch, invert=False, debounce=False), DriverSettings(hw_driver=self.machine.coils["c_flipper_hold"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=10), hold_settings=HoldSettings(power=1.0), recycle=False) ) self.machine.default_platform.set_pulse_on_hit_and_release_and_disable_rule.assert_called_with( SwitchSettings(hw_switch=self.machine.switches["s_flipper"].hw_switch, invert=False, debounce=False), SwitchSettings(hw_switch=self.machine.switches["s_flipper_eos"].hw_switch, invert=False, debounce=False), DriverSettings(hw_driver=self.machine.coils["c_flipper_main"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=10), hold_settings=None, recycle=False), RepulseSettings(enable_repulse=False) ) self.machine.default_platform.clear_hw_rule = MagicMock() self.machine.flippers["f_test_hold_eos"].disable() self.machine.default_platform.clear_hw_rule.assert_has_calls([ call( SwitchSettings(hw_switch=self.machine.switches["s_flipper"].hw_switch, invert=False, debounce=False), DriverSettings(hw_driver=self.machine.coils["c_flipper_main"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=10), hold_settings=None, recycle=False) ), call( SwitchSettings(hw_switch=self.machine.switches["s_flipper_eos"].hw_switch, invert=False, debounce=False), DriverSettings(hw_driver=self.machine.coils["c_flipper_main"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=10), hold_settings=None, recycle=False) ), call( SwitchSettings(hw_switch=self.machine.switches["s_flipper"].hw_switch, invert=False, debounce=False), DriverSettings(hw_driver=self.machine.coils["c_flipper_hold"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=10), hold_settings=HoldSettings(power=1.0), recycle=False) ), ], any_order=True)
def _get_configured_switch(switch: SwitchRuleSettings) -> SwitchSettings: """Return configured switch for rule.""" return SwitchSettings(hw_switch=switch.switch.hw_switch, invert=switch.invert != switch.switch.invert, debounce=switch.debounce)
def test_hold_no_eos(self): self.machine.default_platform.set_pulse_on_hit_and_release_rule = MagicMock() self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule = MagicMock() # Config uses enable_events to enable the flipper on boot self.assertTrue(self.machine.flippers["left_flipper"]._enabled) self.machine.flippers["left_flipper"].disable() self.assertFalse(self.machine.flippers["left_flipper"]._enabled) self.machine.flippers["left_flipper"].enable() # def set_hw_rule(self, sw_name, sw_activity, driver_name, driver_action, # disable_on_release=True, drive_now=False, # **driver_settings_overrides): self.assertEqual(1, len(self.machine.default_platform.set_pulse_on_hit_and_release_rule._mock_call_args_list)) self.assertEqual(1, len(self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule. _mock_call_args_list)) self.machine.default_platform.set_pulse_on_hit_and_release_rule.assert_called_once_with( SwitchSettings(hw_switch=self.machine.switches["s_left_flipper"].hw_switch, invert=False, debounce=False), DriverSettings(hw_driver=self.machine.coils["c_flipper_left_main"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=30), hold_settings=None, recycle=False) ) self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule.assert_called_once_with( SwitchSettings(hw_switch=self.machine.switches["s_left_flipper"].hw_switch, invert=False, debounce=False), DriverSettings(hw_driver=self.machine.coils["c_flipper_left_hold"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=10), hold_settings=HoldSettings(power=1.0), recycle=False) ) self.machine.default_platform.clear_hw_rule = MagicMock() self.machine.flippers["left_flipper"].disable() self.assertFalse(self.machine.flippers["left_flipper"]._enabled) self.machine.default_platform.clear_hw_rule.assert_has_calls( [call( SwitchSettings(hw_switch=self.machine.switches["s_left_flipper"].hw_switch, invert=False, debounce=False), DriverSettings(hw_driver=self.machine.coils["c_flipper_left_main"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=30), hold_settings=None, recycle=False) ), call( SwitchSettings(hw_switch=self.machine.switches["s_left_flipper"].hw_switch, invert=False, debounce=False), DriverSettings(hw_driver=self.machine.coils["c_flipper_left_hold"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=10), hold_settings=HoldSettings(power=1.0), recycle=False) ) ], any_order=True) self.machine.default_platform.set_pulse_on_hit_and_release_rule = MagicMock() self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule = MagicMock() self.machine.flippers["left_flipper"].enable() self.machine.default_platform.set_pulse_on_hit_and_release_rule.assert_called_once_with( SwitchSettings(hw_switch=self.machine.switches["s_left_flipper"].hw_switch, invert=False, debounce=False), DriverSettings(hw_driver=self.machine.coils["c_flipper_left_main"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=30), hold_settings=None, recycle=False) ) self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule.assert_called_once_with( SwitchSettings(hw_switch=self.machine.switches["s_left_flipper"].hw_switch, invert=False, debounce=False), DriverSettings(hw_driver=self.machine.coils["c_flipper_left_hold"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=10), hold_settings=HoldSettings(power=1.0), recycle=False) )
def test_dual_wound_flipper_with_software_eos_repulse(self): self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse = MagicMock() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable = MagicMock() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable = MagicMock() # nothing should happen on EOS close without flipper button active self.hit_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # nothing should happen on EOS open without flipper button active self.release_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # flipper activation should also not yet do what self.hit_switch_and_run("s_flipper_dual_wound", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # EOS closes. nothing happens yet self.hit_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # EOS opens. nothing should happen as flipper is not enabled self.release_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # release flipper prior to enabling the flipper self.release_switch_and_run("s_flipper_dual_wound", 1) self.machine.default_platform.set_pulse_on_hit_and_release_and_disable_rule = MagicMock( ) self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule = MagicMock( ) self.assertPlaceholderEvaluates( False, "device.flippers.dual_wound_flipper.enabled") # enable flipper self.post_event("enable_flipper_dual_wound") self.assertPlaceholderEvaluates( True, "device.flippers.dual_wound_flipper.enabled") self.assertEqual( 1, len(self.machine.default_platform. set_pulse_on_hit_and_release_and_disable_rule. _mock_call_args_list)) self.assertEqual( 1, len(self.machine.default_platform. set_pulse_on_hit_and_enable_and_release_rule. _mock_call_args_list)) self.machine.default_platform.set_pulse_on_hit_and_release_and_disable_rule.assert_called_once_with( SwitchSettings(hw_switch=self.machine. switches["s_flipper_dual_wound"].hw_switch, invert=False, debounce=False), SwitchSettings(hw_switch=self.machine. switches["s_flipper_dual_wound_eos"].hw_switch, invert=False, debounce=False), DriverSettings(hw_driver=self.machine. coils["c_flipper_dual_wound_main"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=30), hold_settings=None, recycle=False), None # this is not passed as we implement it in software ) self.machine.default_platform.set_pulse_on_hit_and_enable_and_release_rule.assert_called_once_with( SwitchSettings(hw_switch=self.machine. switches["s_flipper_dual_wound"].hw_switch, invert=False, debounce=False), DriverSettings(hw_driver=self.machine. coils["c_flipper_dual_wound_hold"].hw_driver, pulse_settings=PulseSettings(power=1.0, duration=10), hold_settings=HoldSettings(power=1.0), recycle=False)) # nothing should happen on EOS close without flipper button active self.hit_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # nothing should happen on EOS open without flipper button active self.release_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # flipper activation should also not yet do what self.hit_switch_and_run("s_flipper_dual_wound", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # EOS closes. nothing happens yet self.hit_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # EOS opens. it should repulse self.release_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_called_with( PulseSettings(power=1.0, duration=30)) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse = MagicMock() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # EOS closes only shortly self.hit_switch_and_run("s_flipper_dual_wound_eos", .1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # EOS opens. it should not repulse yet self.release_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # EOS closes. nothing happens yet self.hit_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # EOS opens. it should repulse self.release_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_called_with( PulseSettings(power=1.0, duration=30)) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse = MagicMock() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # EOS closes. nothing happens yet self.hit_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # flipper button releases self.release_switch_and_run("s_flipper_dual_wound", 1) # eos opens - nothing should happen self.release_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_called_with( ) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable = MagicMock() # disable flipper self.post_event("disable_flipper_dual_wound") self.assertPlaceholderEvaluates( False, "device.flippers.dual_wound_flipper.enabled") # nothing should happen on EOS close without flipper button active self.hit_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # nothing should happen on EOS open without flipper button active self.release_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # flipper activation should also not yet do what self.hit_switch_and_run("s_flipper_dual_wound", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # EOS closes. nothing happens yet self.hit_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # EOS opens. nothing should happen as flipper is not enabled self.release_switch_and_run("s_flipper_dual_wound_eos", 1) self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.pulse.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.enable.assert_not_called() self.machine.coils[ "c_flipper_dual_wound_main"].hw_driver.disable.assert_not_called() # release flipper prior to enabling the flipper self.release_switch_and_run("s_flipper_dual_wound", 1)