Skip to content

Commit

Permalink
refactor shot block tests to use common test structure
Browse files Browse the repository at this point in the history
  • Loading branch information
bosh committed Aug 25, 2024
1 parent 73c8cc4 commit 6ceda4c
Showing 1 changed file with 25 additions and 72 deletions.
97 changes: 25 additions & 72 deletions mpf/tests/test_Shots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6ceda4c

Please sign in to comment.