Skip to content

Commit

Permalink
Merge pull request #1828 from bosh/add_shot_block_test_cases
Browse files Browse the repository at this point in the history
Add shot block test cases
  • Loading branch information
avanwinkle authored Sep 1, 2024
2 parents 35a84ba + 6ceda4c commit 48b6e09
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
4 changes: 4 additions & 0 deletions mpf/tests/machine_files/shots/config/test_shot_groups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ switches:
number:
switch_4:
number:
switch_5:
number:
switch_6:
number:
s_rotate_l:
number:
s_rotate_r:
Expand Down
4 changes: 4 additions & 0 deletions mpf/tests/machine_files/shots/modes/base2/config/base2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 18 additions & 1 deletion mpf/tests/machine_files/shots/modes/mode1/config/mode1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
45 changes: 30 additions & 15 deletions mpf/tests/test_Shots.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,51 @@ def stop_game(self):
self.advance_time_and_run()
self.assertIsNone(self.machine.game)

def test_block(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)
if should_block:
self.assertEqual("unlit", self.machine.shots[shot].state_name)
else:
self.assertEqual("lit", self.machine.shots[shot].state_name)

self.assertEqual("mode1_two", self.machine.shots[high_priority_shot].state_name)

def test_block_true(self):
self.block_test("switch_3", "shot_3", True)

def test_block_false(self):
self.block_test("switch_5", "shot_5", False)

def test_block_default(self): #Default behaves as false
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 48b6e09

Please sign in to comment.