<s> import datetime <EOL> import time <EOL> from bzt . modules . provisioning import Local <EOL> from tests import BZTestCase <EOL> from tests . mocks import EngineEmul <EOL> class ScenarioExecutorEmul ( object ) : <EOL> def __init__ ( self ) : <EOL> pass <EOL> def startup ( self ) : <EOL> pass <EOL> class LocalProvisioningEmul ( Local ) : <EOL> def __init__ ( self ) : <EOL> self . engine = EngineEmul ( ) <EOL> class LocalProvisioningTest ( BZTestCase ) : <EOL> def check_started_list ( self , start_time , delay , prepared , started ) : <EOL> executor = ScenarioExecutorEmul ( ) <EOL> executor . delay = delay <EOL> prov = LocalProvisioningEmul ( ) <EOL> prov . executors = [ executor ] <EOL> prov . start_time = start_time <EOL> if prepared : <EOL> prov . engine . prepared = [ executor ] <EOL> else : <EOL> prov . engine . prepared = [ ] <EOL> if started : <EOL> prov . engine . started = [ executor ] <EOL> else : <EOL> prov . engine . started = [ ] <EOL> prov . _start_modules ( ) <EOL> if executor in prov . engine . started : <EOL> return True <EOL> else : <EOL> return False <EOL> def test_delay_cycle ( self ) : <EOL> cur_time = time . time ( ) <EOL> self . assertTrue ( self . check_started_list ( cur_time , <NUM_LIT:0> , True , False ) ) <EOL> self . assertFalse ( self . check_started_list ( cur_time , <NUM_LIT:0> , False , False ) ) <EOL> self . assertTrue ( self . check_started_list ( cur_time - <NUM_LIT:10> , <NUM_LIT:5> , True , False ) ) <EOL> self . assertFalse ( self . check_started_list ( cur_time - <NUM_LIT:10> , <NUM_LIT:20> , True , False ) ) <EOL> self . assertFalse ( self . check_started_list ( cur_time - <NUM_LIT:10> , <NUM_LIT:5> , False , False ) ) <EOL> def test_start_shift ( self ) : <EOL> local = Local ( ) <EOL> _today = datetime . date . today ( ) <EOL> _yesterday = _today - datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> _tomorrow = _today + datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> _start_time = datetime . time ( <NUM_LIT:12> , <NUM_LIT:30> , <NUM_LIT:5> ) <EOL> _scheduled_time = datetime . time ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> ) <EOL> local . start_time = time . mktime ( datetime . datetime . combine ( _today , _start_time ) . timetuple ( ) ) <EOL> date = datetime . datetime . combine ( _tomorrow , _scheduled_time ) . strftime ( '<STR_LIT>' ) <EOL> shift = local . _get_start_shift ( date ) <EOL> self . assertEqual ( shift , <NUM_LIT> ) <EOL> date = datetime . datetime . combine ( _yesterday , _scheduled_time ) . strftime ( '<STR_LIT>' ) <EOL> shift = local . _get_start_shift ( date ) <EOL> self . assertEqual ( shift , <NUM_LIT> ) <EOL> date = datetime . datetime . combine ( _today , _scheduled_time ) . strftime ( '<STR_LIT>' ) <EOL> shift = local . _get_start_shift ( date ) <EOL> self . assertEqual ( shift , <NUM_LIT> ) <EOL> date = datetime . datetime . combine ( _today , _scheduled_time ) . strftime ( '<STR_LIT>' ) <EOL> shift = local . _get_start_shift ( date ) <EOL> self . assertEqual ( shift , <NUM_LIT> ) <EOL> shift = local . _get_start_shift ( '<STR_LIT>' ) <EOL> self . assertEqual ( shift , <NUM_LIT:0> ) <EOL> shift = local . _get_start_shift ( '<STR_LIT>' ) <EOL> self . assertEqual ( shift , <NUM_LIT:0> ) </s>
