def test_feat_bonus_to_base_stat(): '''Feat bonus should be added to base stat''' av = Avatar('dummy') assert av.base_luck == 1, av.base_luck assert av.luck == 1, av.luck av.add_feat('luck') assert av.base_luck == 3, av.base_luck assert av.luck == 3, av.luck
def test_effects_on_skills(): av = Avatar('dummy') av.skills['diplomacy'] = 15 assert av.skill('diplomacy') == 15 av.add_effect(MultiEffect('dummy', 'neg', (('diplomacy', -1), ))) assert av.skill('diplomacy') == 14 # check restoring skill av.heal_injuries() assert av.skill('diplomacy') == 15
def test_heal_only_negative(): '''Healing should remove only negative effects''' av = Avatar('dummy') av.add_effect(Injury('dummy', 'reflexes', -1)) av.add_effect(MultiEffect('dummy', 'neg', (('reflexes', -1), ))) av.add_effect( MultiEffect('dummy', 'pos', (('reflexes', 3), ('vitality', -2)))) assert len(av.effects) == 3 av.heal_injuries() assert len(av.effects) == 1
def test_req_exp(): '''avatar.req_exp should show amount of experience to complete current level''' av = Avatar('dummy') assert av.lvl == 1 assert av.req_exp == 100, av.req_exp av.lvl = 2 assert av.req_exp == 200, av.req_exp av.lvl = 3 assert av.req_exp == 400, av.req_exp av.lvl = 4 assert av.req_exp == 800, av.req_exp
def test_feat_bonus_to_base_skill(): '''Feat bonus should be added to base skill''' av = Avatar('dummy') assert av.base_skill('deceive') == 0 assert av.skill('deceive') == 0 av.add_feat('liar') assert av.base_skill('deceive') == 2 assert av.skill('deceive') == 2
def test_avatar_healing_some_wounds(): '''If heal is called with a number, it should heal that number of wounds''' av = Avatar('dummy') av.heal() assert av.mp == 10 assert av.wounds == 0 av.take_damage(5) assert av.mp == 5 assert av.wounds == 5 av.heal(1) assert av.mp == 5 assert av.wounds == 4 av.heal(6) assert av.mp == 5 assert av.wounds == 0
def test_injuries_dont_drop_stat_below_zero(): '''Injuries should not drop a stat below zero''' av = Avatar('dummy') av.base_reflexes = 12 assert av.reflexes == 12 av.add_effect(Injury('dummy', 'reflexes', -7)) assert av.reflexes == 5 av.add_effect(Injury('dummy', 'reflexes', -7)) assert av.reflexes == 0 av.effects.pop() av.update_stats() assert av.reflexes == 5
def test_av_has_injuries(monkeypatch): avatar = Avatar('dummy') monkeypatch.setattr(rpy_code, 'avatar', avatar, raising=False) avatar.add_effect(MultiEffect('dummy', 'pos', (('luck', -1), ))) assert not av_has_injuries() avatar.add_effect(MultiEffect('dummy', 'neg', (('luck', -1), ))) assert av_has_injuries()
def test_SurvivalismAndCartography_adds_mp(monkeypatch): '''Completing Survivalism and Cartography should add 2 mp to avatar''' av = Avatar('dummy') monkeypatch.setattr(rpy_code, 'avatar', av, raising=False) rs = SurvivalismAndCartography() assert av.base_mp == 10 rs.on_complete() assert av.base_mp == 12
def test_remove_last_item_non_equipped(): '''Removing last non-equpped item in stack should not unequip item with similar slot''' av = Avatar('dummy') av.inventory.add('iron_dagger') av.inventory.add('iron_longsword') av.inventory.equip('iron_longsword') av.inventory.remove('iron_dagger') assert av.inventory.slots['main'] == Item('iron_longsword')
def test_SurveyingAndTelescopics_adds_mp(monkeypatch): '''Completing Survivalism and Cartography should add 2 mp to avatar''' av = Avatar('dummy') monkeypatch.setattr(rpy_code, 'avatar', av, raising=False) rs = SurveyingAndTelescopics() assert av.view_distance == 1 rs.on_complete() assert av.view_distance == 2
def test_heal_injuries(): av = Avatar('dummy') av.add_effect(Injury('dummy', 'reflexes', -7)) av.add_effect(Injury('dummy', 'intelligence', -3)) assert av.reflexes == 0 assert av.intelligence == 0 assert len(av.effects) == 2 av.heal_injuries() assert av.reflexes == 1 assert av.intelligence == 1 assert len(av.effects) == 0
def test_avatar_healing(): '''Healing avatar should set wounds to zero''' av = Avatar('dummy') av.heal() assert av.mp == 10 assert av.wounds == 0 av.take_damage(1) assert av.mp == 9 assert av.wounds == 1 av.heal() assert av.mp == 9 assert av.wounds == 0
def test_one_handed_replaces_two_handed(): '''If normal weapon replaces two-handed, off slot should be unblocked.''' av = Avatar('dummy') # check that gattsu blade is two-handed assert "two-handed" in Item('gattsu_blade').keywords av.inventory.add_items(("gattsu_blade", 'shield', 'iron_sword')) av.inventory.equip('gattsu_blade') assert av.inventory.blocked_slots == set(('off',)) av.inventory.equip('iron_sword') assert 'off' not in av.inventory.blocked_slots
def test_taking_damage_increase_wounds(): '''If avatar takes damage, that should be stored as wounds''' av = Avatar('dummy') av.heal() assert av.base_mp == 10 assert av.mp == 10 assert av.wounds == 0 av.take_damage(3) assert av.wounds == 3 assert av.base_mp == 10 assert av.mp == 7 av.take_damage(30) assert av.wounds == 10 assert av.base_mp == 10 assert av.mp == 0 # check wounds after a week passed av.weekly() assert av.wounds == 10 assert av.base_mp == 10 assert av.mp == 0
def test_weekly_updates(mocker): av = Avatar('dummy') inj = Injury('dummy', 'vitality', -7) inj.weekly = mocker.MagicMock() av.add_effect(inj) assert not inj.weekly.called av.weekly() assert inj.weekly.called
def test_removing_expired_effects(): av = Avatar('dummy') av.add_effect(Injury('dummy', 'reflexes', -7)) assert av.reflexes == 0 assert len(av.effects) == 1 av.weekly() assert len(av.effects) == 0 assert av.reflexes == 1
def test_avatar_reset_mp(): '''New week should reset current MP to their maximum (base MP - wounds)''' av = Avatar('dummy') assert av.mp == 10 av._mp = 4 av._wounds = 3 av.reset_mp() assert av.mp == 7
def test_base_stats_non_negative(): '''Base stats should not go below zero.''' av = Avatar('dummy') for base_stat in ('base_strength', 'base_vitality', 'base_reflexes', 'base_intelligence', 'base_luck', 'base_corruption', 'base_infamy', 'base_guilt'): # check that starting base stats are non-negative assert getattr(av, base_stat) >= 0, base_stat + ' == ' + '{}'.format( getattr(av, base_stat)) # try to set base stats to -1 setattr(av, base_stat, -1) # check that base stats are still non-negative assert getattr(av, base_stat) >= 0, base_stat + ' == ' + '{}'.format( getattr(av, base_stat))
def test_remove_two_handed(): '''Removing eqipped two-handed weapon from inventory (last in its stack) should unequip it and remove its effects''' av = Avatar('dummy') # check that gattsu blade is two-handed assert "two-handed" in Item('gattsu_blade').keywords av.inventory.add_items(("gattsu_blade", 'gattsu_blade')) av.inventory.equip('gattsu_blade') # check that there is the effect of two-handed weapon assert av.inventory.blocked_slots == set(('off',)) av.inventory.remove('gattsu_blade') # check that there is still the effect of two-handed weapon assert av.inventory.blocked_slots == set(('off',)) av.inventory.remove('gattsu_blade') assert av.inventory.blocked_slots == set()
def test_skill_with_penalty_non_negative(): '''Skills should not drop below zero due to armour penalty''' av = Avatar('dummy') av.skills['climb'] = 1 assert av.skill('climb') == 1 av.inventory.add('knights_helm') av.inventory.equip('knights_helm') assert av.skill('climb') == 0 assert av.base_skill('climb') == 1 assert av._armour_penalty == -2
def test_final_stats_non_negative(): '''Final stats should not go below zero (due to items penalties).''' av = Avatar('dummy') # set all base stats to 1 for base_stat in ('base_strength', 'base_vitality', 'base_reflexes', 'base_intelligence', 'base_luck', 'base_corruption', 'base_infamy', 'base_guilt'): setattr(av, base_stat, 1) assert av.base_reflexes == 1 assert av.reflexes == 1 # check that gattsu blade has -2 to reflexes assert all_items['gattsu_blade'][3]['r'] == -2 av.inventory.add_items(('gattsu_blade', )) av.inventory.equip('gattsu_blade') # reflexes should be 0 instead of -1 assert av.reflexes == 0, 'reflexes: {}'.format(av.reflexes)
def test_armour_penalties(): '''Heavy armour items should apply penalties to some skills''' av = Avatar('dummy') av.skills['climb'] = 7 assert av.skill('climb') == 7 av.inventory.add('shield') av.inventory.equip('shield') assert av.skill('climb') == 6 av.inventory.add('knights_helm') av.inventory.equip('knights_helm') assert av.skill('climb') == 4
def test_multieffect(): '''MultiEffect should change multiple target stats''' av = Avatar('dummy') av.base_strength = 5 av.base_reflexes = 5 assert av.strength == 5 assert av.reflexes == 5 av.add_effect( MultiEffect('dummy', 'pos', (('strength', -1), ('reflexes', 2)))) assert av.strength == 4 assert av.reflexes == 7
def test_stats_updating(): '''Stats should be updated when base stat was changed''' av = Avatar('dummy') for base_stat in ('base_strength', 'base_vitality', 'base_reflexes', 'base_intelligence', 'base_luck', 'base_corruption', 'base_infamy', 'base_guilt'): stat = base_stat[5:] # set all base stats to 1 setattr(av, base_stat, 1) # check that all stats == 1 (no inventory or effects) assert getattr( av, stat) == 1, stat + ' == ' + '{}'.format(getattr(av, stat)) # set base stats to 2 setattr(av, base_stat, 2) # check that stats are updated to 2 assert getattr( av, stat) == 2, stat + ' == ' + '{}'.format(getattr(av, stat))
def test_mp_penalty_limits(): av = Avatar('dummy') assert av.base_mp == 10 assert av.mp_penalty == 0 assert av.mp == 10 av.take_damage(3) assert av.mp == 7 av.add_effect(MultiEffect('dummy', 'neg', (('mp', -14), ), 2)) assert av.base_mp == 10 assert av.mp_penalty == 10 assert av.wounds == 3 assert av.mp == 0
def test_new_exp(): '''avatar.new_exp should show unspent experience''' av = Avatar('dummy') assert av.lvl == 1 assert av.new_exp == 0, av.new_exp av.exp += 50 assert av.new_exp == 50, av.new_exp av.lvl = 2 av.exp = 150 assert av.new_exp == 50, av.new_exp av.lvl = 3 av.exp = 370 assert av.new_exp == 70, av.new_exp
def test_mp_reducing(): av = Avatar('dummy') assert av.base_mp == 10 assert av.wounds == 0 assert av.mp_penalty == 0 assert av.mp == 10 av.add_effect(MultiEffect('dummy', 'neg', (('mp', -3), ), 2)) assert av.base_mp == 10 assert av.wounds == 0 assert av.mp_penalty == 3 assert av.mp == 7 av.weekly() assert av.base_mp == 10 assert av.wounds == 0 assert av.mp_penalty == 3 assert av.mp == 7 av.weekly() # status effect ended assert av.base_mp == 10 assert av.wounds == 0 assert av.mp_penalty == 0 assert av.mp == 10
def test_keyword_effect_two_handed(): '''If "two-handed" item is equiped, offhand slot should be cleared and blocked.''' av = Avatar('dummy') # check that gattsu blade is two-handed assert "two-handed" in Item('gattsu_blade').keywords av.inventory.add_items(("gattsu_blade", 'shield')) # equip shield in off hand and check it is equipped av.inventory.equip('shield') assert av.inventory.slots['off'] == Item('shield') # equip gattsu blade and check that off hand is empty and blocked av.inventory.equip('gattsu_blade') assert av.inventory.slots['off'] is None assert av.inventory.blocked_slots == set(('off',)) # try to equip shield to off hand and check that it is impossible av.inventory.equip( 'shield') assert av.inventory.slots['off'] is None #~ assert 'shield' in av.inventory.bp # unequip gattsu blade and now shield should be equippable av.inventory.clear_slot('main') assert 'off' not in av.inventory.blocked_slots av.inventory.equip('shield') assert av.inventory.slots['off'] == Item('shield')
def test_injury_decrease_stat(): av = Avatar('dummy') av.base_strength = 10 assert av.strength == 10 av.add_effect(Injury('dummy', 'strength', -3)) assert av.strength == 7