Skip to content
Permalink
Browse files

improve fake game in test to handle mb drains

  • Loading branch information...
jabdoa2 committed Jun 1, 2019
1 parent bb0ffeb commit 458927fca909510ef5df643e6947a886862a2aa9
Showing with 18 additions and 6 deletions.
  1. +8 −6 mpf/tests/MpfFakeGameTestCase.py
  2. +6 −0 mpf/tests/MpfTestCase.py
  3. +4 −0 mpf/tests/test_MultiBall.py
@@ -48,10 +48,12 @@ def drain_all_balls(self):
file.
"""
drained_balls = 0
for _ in range(self.machine.game.balls_in_play):
self.post_event_with_params("ball_drain", balls=1)
self.machine.playfield.balls = 0
self.machine.playfield.available_balls = 0
result = self.post_relay_event_with_params("ball_drain", balls=1)
drained_balls += result['balls']
self.machine.playfield.balls -= drained_balls
self.machine.playfield.available_balls -= drained_balls
self.advance_time_and_run()

def drain_one_ball(self):
@@ -61,7 +63,7 @@ def drain_one_ball(self):
file.
"""
self.post_event_with_params("ball_drain", balls=1)
self.machine.playfield.balls -= 1
self.machine.playfield.available_balls -= 1
result = self.post_relay_event_with_params("ball_drain", balls=1)
self.machine.playfield.balls -= result['balls']
self.machine.playfield.available_balls -= result['balls']
self.advance_time_and_run()
@@ -243,6 +243,12 @@ def post_event_with_params(self, event_name, **params):
self.machine.events.post(event_name, **params)
self.machine_run()

def post_relay_event_with_params(self, event_name, **params):
"""Post a relay event synchronously and return the result."""
future = self.machine.events.post_relay_async(event_name, **params)
result = self.machine.clock.loop.run_until_complete(future)
return result

def assertPlaceholderEvaluates(self, expected, condition):
result = self.machine.placeholder_manager.build_raw_template(condition).evaluate([],
fail_on_missing_params=True)
@@ -72,6 +72,7 @@ def testSimpleMultiball(self):
# another ball should be ejected to pf
self.advance_time_and_run(10)
self.assertEqual(2, self.machine.playfield.balls)
self.assertBallsInPlay(2)

# ball drains
self.drain_all_balls()
@@ -84,6 +85,7 @@ def testSimpleMultiball(self):
# it should be readded because of shoot again
self.advance_time_and_run(10)
self.assertEqual(2, self.machine.playfield.balls)
self.assertBallsInPlay(2)

# two balls drain
self.drain_all_balls()
@@ -94,6 +96,7 @@ def testSimpleMultiball(self):
self.advance_time_and_run(10)
self.assertEqual(2, self.machine.playfield.balls)
self.assertEventNotCalled("multiball_mb1_ball_lost")
self.assertBallsInPlay(2)

# shoot again ends
self.advance_time_and_run(10)
@@ -102,6 +105,7 @@ def testSimpleMultiball(self):
self.drain_all_balls()
self.advance_time_and_run(1)
self.assertEventCalled("multiball_mb1_ball_lost", 1)
self.assertBallsInPlay(1)

# mb ends
self.assertEqual(1, self._events['multiball_mb1_ended'])

0 comments on commit 458927f

Please sign in to comment.
You can’t perform that action at this time.