def setup(self): """ Setup test case """ self.effect = (EffectBuilder() .with_duration(None) .with_frequency(None) .with_tick(None) .build()) self.model = Model() self.character1 = (CharacterBuilder() .as_player_character() .with_model(self.model) .with_tick(10) .build()) self.character2 = (CharacterBuilder() .with_model(self.model) .with_tick(8) .with_effect(self.effect) .build()) (LevelBuilder().with_character(self.character1, (2, 2)) .with_character(self.character2, (5, 5)) .build()) self.model.player = self.character1
def test_adding_effect(self): """ Test that poison effect can be added to a character """ character = CharacterBuilder().build() poison = mock(Poison) character.add_effect(poison) assert_that(character, has_effect(poison))
def setup(self): """ Setup test cases """ self.caster = ( CharacterBuilder().with_name('Carth the Caster').build()) self.target1 = ( CharacterBuilder().with_name('Tammy the Target1').build()) self.level = (LevelBuilder().with_character( self.caster, (10, 5)).with_character( self.target1, (5, 5)).with_floor_tile(FLOOR).with_wall_tile( EMPTY_WALL).with_solid_wall_tile(SOLID_WALL).with_size( (20, 20)).build())
def setup(self): """ Setup test cases """ self.character = (CharacterBuilder() .with_hit_points(10) .with_max_hp(20) .build()) effect_config = {'healing wind': {'type': Heal, 'duration': 0, 'frequency': 0, 'tick': 0, 'healing': 1, 'icon': 'icon', 'title': 'Cure minor wounds', 'description': 'Cures small amount of damage'}} self.effects = get_effect_creator(effect_config) self.effect_handle = EffectHandle(trigger = 'on spell hit', effect = 'healing wind', parameters = {}, charges = 1) self.spell = (SpellBuilder() .with_effect_handle(self.effect_handle) .with_target(self.character) .build())
def setup(self): """ Setup the test case """ self.rng = Random() self.model = mock() self.effect_factory = get_effect_creator({ 'heal': { 'type': Heal, 'duration': 0, 'frequency': 0, 'tick': 0, 'healing': 10, 'icon': 101, 'title': 'title', 'description': 'major heal' } }) drink_factory = DrinkFactory(self.effect_factory) set_action_factory(ActionFactory(self.model, drink_factory)) self.character = ( CharacterBuilder().with_hit_points(1).with_max_hp(5).build()) effect = (HealBuilder().with_duration(0).with_frequency(0).with_tick( 0).with_healing(5).with_target(self.character).build()) self.potion = ( ItemBuilder().with_name('healing potion').with_effect_handle( EffectHandleBuilder().with_trigger('on drink').with_effect( 'heal')).build()) self.character.inventory.append(self.potion)
def __init__(self): """ Default constructor """ super().__init__() self.character = CharacterBuilder().build()
def test_casting_spell_raises_spirit_changed_event(self): """ Since casting spells uses spirit, an appropriate event should be raised """ spell = (SpellBuilder() .with_spirit(10) .build()) caster = (CharacterBuilder() .with_spirit(20) .build()) listener = EventListener() caster.register_for_updates(listener) effects_factory = mock() action = SpellCastingAction(caster = caster, spell = spell, effects_factory = effects_factory) action.execute() events = [event for event in listener.events if e_event_type(event) == 'spirit points changed'] assert_that(len(events), is_(equal_to(1)))
def test_creating_poison_with_paramarray(self): """ Test that poison can be created by passing it a parameter array """ character = CharacterBuilder().build() params = { 'duration': 150, 'frequency': 30, 'tick': 10, 'damage': 1, 'target': character, 'icon': 101, 'title': 'Moderate poison', 'description': 'Causes damage' } effect = Poison(**params) assert_that(effect.duration, is_(equal_to(150))) assert_that(effect.frequency, is_(equal_to(30))) assert_that(effect.damage, is_(equal_to(1))) assert_that(effect.target, is_(equal_to(character))) assert_that(effect.icon, is_(equal_to(101))) assert_that(effect.title, is_(equal_to('Moderate poison'))) assert_that(effect.description, is_(equal_to('Causes damage')))
def test_creating_poison(self): """ Test that poison effect can be created """ character = CharacterBuilder().build() effects = get_effect_creator({ 'poison': { 'type': Poison, 'duration': 150, 'frequency': 30, 'tick': 10, 'damage': 5, 'icon': 101, 'title': 'Moderate poison', 'description': 'Causes damage' } }) effect = effects('poison', target=character) assert_that(effect.duration, is_(equal_to(150))) assert_that(effect.frequency, is_(equal_to(30))) assert_that(effect.damage, is_(equal_to(5))) assert_that(effect.target, is_(equal_to(character))) assert_that(effect.icon, is_(equal_to(101))) assert_that(effect.title, is_(equal_to('Moderate poison'))) assert_that(effect.description, is_(equal_to('Causes damage')))
def setup(self): """ Test setup """ self.level = LevelBuilder().build() self.monster_1 = (CharacterBuilder().with_name('Pete').build()) self.monster_2 = (CharacterBuilder().with_name('Uglak').build()) self.monster_1.artificial_intelligence = lambda: None self.monster_2.artificial_intelligence = lambda: None add_character(self.level, (5, 5), self.monster_1) add_character(self.level, (6, 5), self.monster_2) set_action_factory(ActionFactoryBuilder().build())
def test_add_domain_level(self): """ Test that a domain level can be added """ caster = (CharacterBuilder().with_domain('fire', 1).build()) caster.add_domain_level('fire') assert_that(caster.get_domain_level('fire'), is_(equal_to(2)))
def test_add_multiple_levels(self): """ Adding more than one level should be possible with a single call """ caster = (CharacterBuilder().with_domain('fire', 1).build()) caster.add_domain_level('fire', 5) assert_that(caster.get_domain_level('fire'), is_(equal_to(6)))
def test_is_proficient(self): """ Test that weapon proficiency of character can be checked """ creature = CharacterBuilder().build() weapon = (ItemBuilder().with_name('club').with_tag('weapon').with_tag( 'one-handed weapon').with_tag('melee').with_tag( 'simple weapon').with_damage( 2, 'bashing').with_weapon_type('simple').build()) proficiency = creature.is_proficient(weapon) assert_that(proficiency, is_(equal_to(False))) creature.feats.append(WeaponProficiency('simple')) proficiency = creature.is_proficient(weapon) assert_that(proficiency, is_(equal_to(True)))
def test_casting_spell_raises_spirit_changed_event(self): """ Since casting spells uses spirit, an appropriate event should be raised """ spell = SpellBuilder().with_spirit(10).build() caster = CharacterBuilder().with_spirit(20).build() listener = EventListener() caster.register_for_updates(listener) effects_factory = mock() action = SpellCastingAction(caster=caster, spell=spell, effects_factory=effects_factory) action.execute() events = [event for event in listener.events if e_event_type(event) == "spirit points changed"] assert_that(len(events), is_(equal_to(1)))
def test_negative_damage_is_zeroed(self): """ Test that damage below zero is zeroed """ character = CharacterBuilder().build() damage = new_damage([(-1, 'negative damage')]) damage_inflicted = damage(target=character) assert_that(damage_inflicted[0], is_(equal_to(0)))
def test_event_is_raised_for_hp_change(self): """ Event should be raised when hit points change """ listener = mock() character = (CharacterBuilder().with_update_listener(listener).build()) character.hit_points = 20 verify(listener).receive_update(EventType('hit points changed'))
def Wizard(): """ Creates a wizardcharacter :returns: fully initialised wizard :rtype: Character """ character = (CharacterBuilder().with_hit_points(5).with_max_hp( 5).with_spirit(20).with_max_spirit(20).with_speed(4).with_body( 4).with_mind(8).with_attack(1).with_name('Wizard').build()) return character
def test_wear_boots(self): """ Test that boots can be worn """ character = CharacterBuilder().build() boots = (ItemBuilder().with_name('boots').with_boots_speed_modifier( 1).build()) equip(character, boots) assert_that(character, is_wearing_boots(boots))
def test_wear_armour(self): """ Test that armour can be worn """ character = CharacterBuilder().build() armour = (ItemBuilder().with_damage_reduction(2).with_speed_modifier( 1).with_name('leather armour').build()) equip(character, armour) assert_that(character, is_wearing_armour(armour))
def test_triggering_damage_raises_event(self): """ Triggering damage effect should raise a proper event """ model = mock() target = (CharacterBuilder().with_model(model).build()) effect = (DamageBuilder().with_target(target).build()) effect.trigger() verify(model).raise_event(event_type_of('damage triggered'))
def setup(self): """ Setup test cases """ self.level = LevelBuilder().build() self.character = (CharacterBuilder() .with_level(self.level) .with_location((5, 5)) .build()) self.spell_generator = SpellGeneratorBuilder().build()
def setup(self): """ Setup test case """ self.model = mock() effects = get_effect_creator({'poison': {'type': Poison, 'duration': 12, 'frequency': 3, 'tick': 3, 'damage': 5, 'icon': 101, 'title': 'poison', 'description': 'Causes damage'}}) pyherc.vtable['\ufdd0:create-effect'] = effects set_action_factory(ActionFactoryBuilder() .with_effect_factory(effects) .build()) self.attacker = (CharacterBuilder() .with_location((5, 5)) .with_effect_handle(EffectHandleBuilder() .with_trigger('on attack hit') .with_effect('poison')) .with_model(self.model) .build()) self.defender = (CharacterBuilder() .with_location((5, 4)) .with_hit_points(50) .with_model(self.model) .build()) (LevelBuilder().with_character(self.attacker) .with_character(self.defender) .build())
def test_healing_does_not_heal_over_max_hp(self): """ Test that character does not get healed over his maximum hp when getting healing effect """ character = ( CharacterBuilder().with_hit_points(1).with_max_hp(5).build()) effect = (HealBuilder().with_duration(0).with_frequency(0).with_tick( 0).with_healing(10).with_target(character).build()) effect.trigger() assert_that(character.hit_points, is_(equal_to(5)))
def test_healing_effect(self): """ Test that a healing effect can be applied on a character """ character = ( CharacterBuilder().with_hit_points(1).with_max_hp(15).build()) effect = (HealBuilder().with_duration(0).with_frequency(0).with_tick( 0).with_healing(10).with_target(character).build()) effect.trigger() assert_that(character.hit_points, is_(equal_to(11)))
def test_damage_effect(self): """ Test that a damage effect can be applied on a character """ character = ( CharacterBuilder().with_hit_points(15).with_max_hp(15).build()) effect = (DamageBuilder().with_duration(0).with_frequency(0).with_tick( 0).with_damage(10).with_target(character).build()) effect.trigger() assert_that(character.hit_points, is_(equal_to(5)))
def test_getting_spell_list(self): """ It should be possible to get a list of known spells """ fireball = (SpellEntryBuilder().with_name('fireball').with_domain( 'fire', 1).build()) caster = (CharacterBuilder().with_domain( 'fire', 1).with_spell_entry(fireball).build()) spells = caster.get_known_spells() assert_that(spells, has_item(fireball))
def Adventurer(): """ Creates a adventurer character :returns: fully initialised adventurer :rtype: Character """ character = (CharacterBuilder().with_hit_points(10).with_max_hp( 10).with_speed(5).with_body(5).with_mind(5).with_attack(1).with_name( 'Adventurer').build()) add_history_value(character, 'hit_points') return character
def test_dispatching_event_to_listeners(self): """ Test that events are dispatched to listeners """ event = new_move_event(character=(CharacterBuilder().with_model( self.model).build()), old_location=(5, 5), old_level=self.level, direction=1) self.model.raise_event(event) verify(self.listener).receive_event(event)
def test_moving_when_stairs_are_blocked(self): """ Moving should be possible, even if stairs other end is blocked """ blocker = CharacterBuilder().build() add_character(self.level2, (10, 10), blocker) pyherc.vtable['\ufdd0:move'](character=self.character, direction=Direction.enter) assert_that(blocker.level, is_(equal_to(self.level2))) assert_that(self.character.level, is_(equal_to(self.level2)))
def test_taking_off_boots(self): """ Boots can be removed """ character = CharacterBuilder().build() boots = (ItemBuilder().with_name('boots').with_boots_speed_modifier( 1).build()) character.inventory.boots = boots unequip(character, boots) assert_that(character, is_not(is_wearing_boots(boots)))
def test_raising_event(self): """ Test that character can raise event """ model = mock() character = (CharacterBuilder().with_model(model).build()) character.raise_event( new_move_event(character=character, old_location=character.location, old_level=None, direction=1)) verify(model).raise_event(EventType('move'))
def test_is_proficient(self): """ Test that weapon proficiency of character can be checked """ creature = CharacterBuilder().build() weapon = (ItemBuilder() .with_name('club') .with_tag('weapon') .with_tag('one-handed weapon') .with_tag('melee') .with_tag('simple weapon') .with_damage(2) .with_weapon_type('simple') .build()) proficiency = creature.is_proficient(weapon) assert_that(proficiency, is_(equal_to(False))) creature.feats.append(WeaponProficiency('simple')) proficiency = creature.is_proficient(weapon) assert_that(proficiency, is_(equal_to(True)))
class TestEffectHandling(): """ Test for adding effects """ def __init__(self): """ Default constructor """ super().__init__() self.character = None def setup(self): """ Setup test case """ self.character = CharacterBuilder().build() def test_add_effect(self): """ Adding a single effect should be possible """ effect = EffectBuilder().build() self.character.add_effect(effect) assert_that(self.character, has_effect(effect)) def test_add_multiple_effects(self): """ It should be possible to add multiple effects of different type """ effect_1 = (EffectBuilder() .with_effect_name('spell') .build()) effect_2 = (EffectBuilder() .with_effect_name('curse') .build()) self.character.add_effect(effect_1) self.character.add_effect(effect_2) assert_that(self.character, has_effect(effect_1)) assert_that(self.character, has_effect(effect_2)) def test_add_multiple_effects_of_same_type(self): """ Adding multiple effects of same type should not be possible """ effect_1 = (EffectBuilder() .with_effect_name('spell') .build()) effect_2 = (EffectBuilder() .with_effect_name('spell') .build()) self.character.add_effect(effect_1) self.character.add_effect(effect_2) assert_that(self.character, has_effect(effect_1)) assert_that(self.character, is_not(has_effect(effect_2))) def test_add_multiple_effects_of_same_type_when_allowed(self): """ In special cases, adding multiple effects of same type is allowed """ effect_1 = (EffectBuilder() .with_effect_name('spell') .with_multiple_allowed() .build()) effect_2 = (EffectBuilder() .with_effect_name('spell') .with_multiple_allowed() .build()) self.character.add_effect(effect_1) self.character.add_effect(effect_2) assert_that(self.character, has_effect(effect_1)) assert_that(self.character, has_effect(effect_2)) def test_worn_boots_effects(self): """ Boots' effects are reported as user's effects """ effect = (EffectBuilder() .build()) item = (ItemBuilder() .with_effect(effect) .build()) self.character.inventory.boots = item assert_that(self.character, has_effect(effect))
def setup(self): """ Setup test case """ self.character = CharacterBuilder().build()