<s> import unittest <EOL> from mpf . system . machine import MachineController <EOL> from mpf . system . utility_functions import Util <EOL> import logging <EOL> import time <EOL> import sys <EOL> from mock import * <EOL> from datetime import datetime , timedelta <EOL> import inspect <EOL> class MpfTestCase ( unittest . TestCase ) : <EOL> def get_platform ( self ) : <EOL> return '<STR_LIT>' <EOL> def get_use_bcp ( self ) : <EOL> return False <EOL> def getOptions ( self ) : <EOL> return { <EOL> '<STR_LIT>' : self . get_platform ( ) , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : self . getMachinePath ( ) , <EOL> '<STR_LIT>' : Util . string_to_list ( self . getConfigFile ( ) ) , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : self . get_use_bcp ( ) <EOL> } <EOL> def set_time ( self , new_time ) : <EOL> self . testTime = new_time <EOL> time . time . return_value = self . testTime <EOL> def advance_time ( self , delta ) : <EOL> self . testTime += delta <EOL> time . time . return_value = self . testTime <EOL> def advance_time_and_run ( self , delta ) : <EOL> end_time = time . time ( ) + delta <EOL> self . machine_run ( ) <EOL> while True : <EOL> next_event = self . machine . delay . get_next_event ( ) <EOL> next_timer = self . machine . timing . get_next_timer ( ) <EOL> wait_until = next_event <EOL> if wait_until and next_timer and wait_until > next_timer : <EOL> wait_until = next_timer <EOL> if wait_until and wait_until <= end_time : <EOL> self . set_time ( wait_until ) <EOL> self . machine_run ( ) <EOL> else : <EOL> break <EOL> self . set_time ( end_time ) <EOL> self . machine_run ( ) <EOL> def machine_run ( self ) : <EOL> self . machine . default_platform . tick ( ) <EOL> self . machine . timer_tick ( ) <EOL> def unittest_verbosity ( self ) : <EOL> """<STR_LIT>""" <EOL> frame = inspect . currentframe ( ) <EOL> while frame : <EOL> self = frame . f_locals . get ( '<STR_LIT>' ) <EOL> if isinstance ( self , unittest . TestProgram ) : <EOL> return self . verbosity <EOL> frame = frame . f_back <EOL> return <NUM_LIT:0> <EOL> def setUp ( self ) : <EOL> if self . unittest_verbosity ( ) > <NUM_LIT:1> : <EOL> logging . basicConfig ( level = logging . DEBUG , <EOL> format = '<STR_LIT>' ) <EOL> else : <EOL> logging . basicConfig ( level = <NUM_LIT> ) <EOL> self . realTime = time . time <EOL> self . testTime = self . realTime ( ) <EOL> time . time = MagicMock ( return_value = self . testTime ) <EOL> self . machine = MachineController ( self . getOptions ( ) ) <EOL> self . machine . default_platform . timer_initialize ( ) <EOL> self . machine . loop_start_time = time . time ( ) <EOL> self . machine . ball_controller . num_balls_known = <NUM_LIT> <EOL> self . advance_time_and_run ( <NUM_LIT> ) <EOL> def tearDown ( self ) : <EOL> if sys . exc_info != ( None , None , None ) : <EOL> logging . basicConfig ( level = <NUM_LIT> ) <EOL> self . advance_time_and_run ( <NUM_LIT> ) <EOL> self . machine = None <EOL> time . time = self . realTime <EOL> self . realTime = None </s>
