From 6ceda4cfe82dc5459b46d4263724985f07dafdd3 Mon Sep 17 00:00:00 2001 From: Alex Lobascio Date: Sun, 25 Aug 2024 01:28:12 -0700 Subject: [PATCH] refactor shot block tests to use common test structure --- mpf/tests/test_Shots.py | 97 +++++++++++------------------------------ 1 file changed, 25 insertions(+), 72 deletions(-) diff --git a/mpf/tests/test_Shots.py b/mpf/tests/test_Shots.py index bf48e916d..c48360421 100644 --- a/mpf/tests/test_Shots.py +++ b/mpf/tests/test_Shots.py @@ -29,98 +29,51 @@ def stop_game(self): self.advance_time_and_run() self.assertIsNone(self.machine.game) - def test_block_true(self): + def block_test(self, switch, shot, should_block): + high_priority_shot = "mode1_" + shot self.mock_event("playfield_active") - self.hit_and_release_switch("switch_3") + self.hit_and_release_switch(switch) self.advance_time_and_run(.1) self.assertEventCalled("playfield_active") self.start_game() - self.assertEqual("unlit", self.machine.shots["shot_3"].state_name) + self.assertEqual("unlit", self.machine.shots[shot].state_name) - self.hit_and_release_switch("switch_3") + self.hit_and_release_switch(switch) self.advance_time_and_run(.1) - self.assertTrue(self.machine.shots["shot_3"].enabled) - self.assertEqual("lit", self.machine.shots["shot_3"].state_name) + self.assertFalse(self.machine.shots[high_priority_shot].enabled) + self.assertTrue(self.machine.shots[shot].enabled) + self.assertEqual("lit", self.machine.shots[shot].state_name) - self.machine.shots["shot_3"].reset() - self.assertEqual("unlit", self.machine.shots["shot_3"].state_name) + self.machine.shots[shot].reset() + self.assertEqual("unlit", self.machine.shots[shot].state_name) # Start the mode and make sure those shots load self.start_mode("mode1") - self.assertTrue(self.machine.shots["shot_3"].enabled) - self.assertTrue(self.machine.shots["mode1_shot_3"].enabled) - self.assertEqual("unlit", self.machine.shots["shot_3"].state_name) - self.assertEqual("mode1_one", self.machine.shots["mode1_shot_3"].state_name) + self.assertTrue(self.machine.shots[shot].enabled) + self.assertTrue(self.machine.shots[high_priority_shot].enabled) + self.assertEqual("unlit", self.machine.shots[shot].state_name) + self.assertEqual("mode1_one", self.machine.shots[high_priority_shot].state_name) - self.hit_and_release_switch("switch_3") + self.hit_and_release_switch(switch) self.advance_time_and_run(.1) - self.assertEqual("unlit", self.machine.shots["shot_3"].state_name) - self.assertEqual("mode1_two", self.machine.shots["mode1_shot_3"].state_name) - - def test_block_false(self): - self.mock_event("playfield_active") - self.hit_and_release_switch("switch_5") - self.advance_time_and_run(.1) - self.assertEventCalled("playfield_active") + if should_block: + self.assertEqual("unlit", self.machine.shots[shot].state_name) + else: + self.assertEqual("lit", self.machine.shots[shot].state_name) - self.start_game() - self.assertEqual("unlit", self.machine.shots["shot_5"].state_name) + self.assertEqual("mode1_two", self.machine.shots[high_priority_shot].state_name) - self.hit_and_release_switch("switch_5") - self.advance_time_and_run(.1) - self.assertTrue(self.machine.shots["shot_5"].enabled) - self.assertEqual("lit", self.machine.shots["shot_5"].state_name) - - self.machine.shots["shot_5"].reset() - self.assertEqual("unlit", self.machine.shots["shot_5"].state_name) - - # Start the mode and make sure those shots load - self.start_mode("mode1") - - self.assertTrue(self.machine.shots["shot_5"].enabled) - self.assertTrue(self.machine.shots["mode1_shot_5"].enabled) - self.assertEqual("unlit", self.machine.shots["shot_5"].state_name) - self.assertEqual("mode1_one", self.machine.shots["mode1_shot_5"].state_name) - - self.hit_and_release_switch("switch_5") - self.advance_time_and_run(.1) + def test_block_true(self): + self.block_test("switch_3", "shot_3", True) - self.assertEqual("lit", self.machine.shots["shot_5"].state_name) - self.assertEqual("mode1_two", self.machine.shots["mode1_shot_5"].state_name) + def test_block_false(self): + self.block_test("switch_5", "shot_5", False) def test_block_default(self): #Default behaves as false - self.mock_event("playfield_active") - self.hit_and_release_switch("switch_6") - self.advance_time_and_run(.1) - self.assertEventCalled("playfield_active") - - self.start_game() - self.assertEqual("unlit", self.machine.shots["shot_6"].state_name) - - self.hit_and_release_switch("switch_6") - self.advance_time_and_run(.1) - self.assertTrue(self.machine.shots["shot_6"].enabled) - self.assertEqual("lit", self.machine.shots["shot_6"].state_name) - - self.machine.shots["shot_6"].reset() - self.assertEqual("unlit", self.machine.shots["shot_6"].state_name) - - # Start the mode and make sure those shots load - self.start_mode("mode1") - - self.assertTrue(self.machine.shots["shot_6"].enabled) - self.assertTrue(self.machine.shots["mode1_shot_6"].enabled) - self.assertEqual("unlit", self.machine.shots["shot_6"].state_name) - self.assertEqual("mode1_one", self.machine.shots["mode1_shot_6"].state_name) - - self.hit_and_release_switch("switch_6") - self.advance_time_and_run(.1) - - self.assertEqual("lit", self.machine.shots["shot_6"].state_name) - self.assertEqual("mode1_two", self.machine.shots["mode1_shot_6"].state_name) + self.block_test("switch_6", "shot_6", False) def test_loading_shots(self): # Make sure machine-wide shots load & mode-specific shots do not