From 73c8cc4f968779040b57c917dcebd2d594ac8be6 Mon Sep 17 00:00:00 2001 From: Alex Lobascio Date: Sun, 25 Aug 2024 01:17:21 -0700 Subject: [PATCH 1/2] add tests around shot_profile block option behavior The tests for the false and default case have the same logic, suggesting that mpf-docs:docs/config/shot_profiles.md is out of date about default block behavior. --- .../shots/config/test_shot_groups.yaml | 4 ++ .../shots/modes/base2/config/base2.yaml | 4 ++ .../shots/modes/mode1/config/mode1.yaml | 19 +++++- mpf/tests/test_Shots.py | 64 ++++++++++++++++++- 4 files changed, 89 insertions(+), 2 deletions(-) diff --git a/mpf/tests/machine_files/shots/config/test_shot_groups.yaml b/mpf/tests/machine_files/shots/config/test_shot_groups.yaml index 4b06f7f00..80767f464 100644 --- a/mpf/tests/machine_files/shots/config/test_shot_groups.yaml +++ b/mpf/tests/machine_files/shots/config/test_shot_groups.yaml @@ -12,6 +12,10 @@ switches: number: switch_4: number: + switch_5: + number: + switch_6: + number: s_rotate_l: number: s_rotate_r: diff --git a/mpf/tests/machine_files/shots/modes/base2/config/base2.yaml b/mpf/tests/machine_files/shots/modes/base2/config/base2.yaml index ddf6ae685..cf82e013d 100644 --- a/mpf/tests/machine_files/shots/modes/base2/config/base2.yaml +++ b/mpf/tests/machine_files/shots/modes/base2/config/base2.yaml @@ -20,6 +20,10 @@ shots: light: tag1 shot_4: switch: switch_1 + shot_5: + switch: switch_5 + shot_6: + switch: switch_6 led_1: switch: switch_1 show_tokens: diff --git a/mpf/tests/machine_files/shots/modes/mode1/config/mode1.yaml b/mpf/tests/machine_files/shots/modes/mode1/config/mode1.yaml index 299ab4a90..80bc73d12 100644 --- a/mpf/tests/machine_files/shots/modes/mode1/config/mode1.yaml +++ b/mpf/tests/machine_files/shots/modes/mode1/config/mode1.yaml @@ -24,6 +24,12 @@ shots: mode1_shot_3: switch: switch_3 profile: mode1_shot_3 + mode1_shot_5: + switch: switch_5 + profile: mode1_shot_5 + mode1_shot_6: + switch: switch_6 + profile: mode1_shot_6 shot_profiles: mode1_shot_2: @@ -32,10 +38,21 @@ shot_profiles: - name: mode1_one - name: mode1_two - name: mode1_three - mode1_shot_3: + mode1_shot_3: # Test block: True show: rainbow2 block: True states: - name: mode1_one - name: mode1_two - name: mode1_three + mode1_shot_5: # Test block: False + show: rainbow2 + block: False + states: + - name: mode1_one + - name: mode1_two + mode1_shot_6: # Test block default + show: rainbow2 + states: + - name: mode1_one + - name: mode1_two diff --git a/mpf/tests/test_Shots.py b/mpf/tests/test_Shots.py index 3103c28a1..bf48e916d 100644 --- a/mpf/tests/test_Shots.py +++ b/mpf/tests/test_Shots.py @@ -29,7 +29,7 @@ def stop_game(self): self.advance_time_and_run() self.assertIsNone(self.machine.game) - def test_block(self): + def test_block_true(self): self.mock_event("playfield_active") self.hit_and_release_switch("switch_3") self.advance_time_and_run(.1) @@ -60,6 +60,68 @@ def test_block(self): 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") + + self.start_game() + self.assertEqual("unlit", self.machine.shots["shot_5"].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) + + 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_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) + def test_loading_shots(self): # Make sure machine-wide shots load & mode-specific shots do not self.assertIn('shot_1', self.machine.shots) From 6ceda4cfe82dc5459b46d4263724985f07dafdd3 Mon Sep 17 00:00:00 2001 From: Alex Lobascio Date: Sun, 25 Aug 2024 01:28:12 -0700 Subject: [PATCH 2/2] 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