def build_tree(): effect_one = Effect(effect_descriptor=EffectDescriptor.INFLUENCE, value=5) effect_two = Effect(effect_descriptor=EffectDescriptor.ECOLOGY, value=0.1) effect_three = Effect(effect_descriptor=EffectDescriptor.ECONOMY, value=0.1) effect_four = Effect(effect_descriptor=EffectDescriptor.SOCIAL, value=0.1) farming = Improvements( 'Farming', (Improvement(title='My Title', effects=Effects([effect_one])), Improvement(title='a', effects=Effects([effect_two, effect_three, effect_four ])))) education = Improvements( 'Education', (Improvement(title='b', effects=Effects([effect_one])), Improvement(title='c', effects=Effects([effect_two, effect_three, effect_four ])))) energy = Improvements( 'Energy', (Improvement(title='d', effects=Effects([effect_one])), Improvement(title='e', effects=Effects( [effect_two, effect_three, effect_four])))) politic = Improvements( 'Politic', (Improvement(title='f', effects=Effects([effect_one])), Improvement(title='g', effects=Effects( [effect_two, effect_three, effect_four])))) economy = Improvements( 'Economy', (Improvement(title='h', effects=Effects([effect_one])), Improvement(title='i', effects=Effects( [effect_two, effect_three, effect_four])))) return ProgressionTree((farming, education, energy, politic, economy))
def test_get_current_effects(mocker): value = {EffectDescriptor.INFLUENCE: 3} effects = Effects([Effect(), Effect(), Effect()]) mocker.patch.object(ef, 'merge_effects', return_value=value) mocker.patch.object(Effect, 'get_current_effect', return_value=None) effects_dict = effects.get_current_effects() assert ef.merge_effects.call_count == len(effects.effects) assert Effect.get_current_effect.call_count == len(effects.effects) assert effects_dict == value
def test_get_current_effect_on(): value = 4 effect_in_progress = Effect(effect_descriptor=EffectDescriptor.INFLUENCE, value=value, start_effect=2, end_effect=4) effect_in_progress.turn_since_done = 3 assert effect_in_progress.get_current_effect() == { EffectDescriptor.INFLUENCE: value }
def test_constructor_effect(): effect_normal = Effect(effect_descriptor=EffectDescriptor.INFLUENCE, start_effect=2, end_effect=4) assert effect_normal.start_effect == 2 assert effect_normal.end_effect == 4 effect_lobbying = Effect(effect_descriptor=EffectDescriptor.LOBBYING, start_effect=2, end_effect=4) assert effect_lobbying.start_effect == 0 assert effect_lobbying.end_effect == 1
def test_get_current_effect_off(): effect_not_started = Effect(effect_descriptor=EffectDescriptor.INFLUENCE, start_effect=2, end_effect=4) effect_not_started.turn_since_done = 1 assert effect_not_started.get_current_effect() == {} effect_finished = Effect(effect_descriptor=EffectDescriptor.INFLUENCE, start_effect=2, end_effect=4) effect_finished.turn_since_done = 5 assert effect_finished.get_current_effect() == {}
def test_str(): effect_descriptor = EffectDescriptor.INFLUENCE value = 3 start_effect = 5 duration = 2 effect = Effect(effect_descriptor=effect_descriptor, value=value, start_effect=start_effect, end_effect=start_effect + duration) str_effect = str(effect) assert str_effect.find(effect_descriptor) != -1 assert str_effect.find(str(value)) != -1 assert str_effect.find(str(start_effect)) != -1 assert str_effect.find(str(duration)) != -1 effect_inf = Effect(effect_descriptor=effect_descriptor, value=value, start_effect=start_effect, end_effect=float('inf')) str_effect_inf = str(effect_inf) assert str_effect_inf.find(effect_descriptor) != -1 assert str_effect_inf.find(str(value)) != -1 assert str_effect_inf.find(str(start_effect)) != -1 assert str_effect_inf.find('permanently') != -1
def test_display_effects(mocker): effects = Effects([Effect(), Effect()]) mocker.patch.object(Effect, '__str__', return_value='Effect') str_effects = outputs.effects_to_str(effects) assert Effect.__str__.call_count == len(effects.effects) assert str_effects.count('Effect') == len(effects.effects)
def test_effects_new_turn(mocker): mocker.patch.object(Effect, 'new_turn', return_value=None) effects = Effects([Effect(), Effect(), Effect()]) effects.new_turn() assert Effect.new_turn.call_count == len(effects.effects)
def test_new_turn(): effect = Effect() turn = effect.turn_since_done effect.new_turn() assert effect.turn_since_done == turn + 1