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
class TestEventDispatching(object): """ Tests for event dispatching relating to moving """ def __init__(self): """ Default constructor """ super(TestEventDispatching, self).__init__() self.model = None self.character = None self.level = None self.listener = None def setup(self): """ Setup test case """ self.model = Model() action_factory = (ActionFactoryBuilder() .with_move_factory() .build()) self.character = (CharacterBuilder() .with_action_factory(action_factory) .with_model(self.model) .with_location((10, 10)) .build()) self.level = (LevelBuilder() .with_character(self.character) .build()) self.listener = EventListener() self.model.register_event_listener(self.listener) def test_event_is_relayed(self): """ Test that moving will create an event and send it forward """ self.character.move(3) assert_that(len(self.listener.events), is_(equal_to(1))) def test_affected_tiles_are_marked(self): """ Test that moving marks tiles for redrawing """ expected_redraws = [(10, 10), (10, 11)] self.character.move(5) event = self.listener.events[0] assert_that(event, has_marked_for_redrawing(expected_redraws))
class TestEternalEffects(): """ Tests related to effects that do not time out """ def __init__(self): """ Default constructor """ super().__init__() self.model = None self.character1 = None self.effect = None self.character2 = None 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_reducing_tick(self): """ Test that effect with duration, frequency and tick None does not cause null reference exception """ self.model.get_next_creature(mock()) def test_effect_is_not_removed(self): """ Eternal effects should not be removed due to time out """ self.model.get_next_creature(mock()) assert_that(self.character2, has_effect(self.effect))
def setup(self): """ Setup test cases """ self.model = Model() self.listener = mock() self.level = LevelBuilder().build() self.model.register_event_listener(self.listener)
def test_player_moving_updates_whole_screen(self): """ Test that moving player character reports whole screen updated """ model = Model() surface = mock() player = (CharacterBuilder() .with_model(model) .as_player_character() .with_action_factory(ActionFactoryBuilder() .with_model(model) .with_move_factory()) .with_name('player') .with_location((11, 11)) .build()) monster = (CharacterBuilder() .with_model(model) .with_action_factory(ActionFactoryBuilder() .with_model(model) .with_move_factory()) .with_name('rat') .with_location((5, 5)) .build()) level = (LevelBuilder() .with_character(player) .with_character(monster) .build()) application = Application() application.world = model game_gui = GameArea(application = application, surface_manager = mock(), decorate = False, width = 800, height = 600) game_gui.old_location = player.location model.register_event_listener(game_gui) player.move(7) rects = game_gui.update(surface) assert_that(rects, has_items(Rect(0, 0, 800, 600)))
def test_updating_screen_while_monster_moves(self): """ Test that only needed spots are reported as updated as a monster moves """ model = Model() surface = mock() player = (CharacterBuilder() .with_model(model) .as_player_character() .with_name('player') .with_location((11, 11)) .build()) monster = (CharacterBuilder() .with_model(model) .with_action_factory(ActionFactoryBuilder() .with_model(model) .with_move_factory()) .with_name('rat') .with_location((5, 5)) .build()) level = (LevelBuilder() .with_character(player) .with_character(monster) .build()) application = Application() application.world = model game_gui = GameArea(application = application, surface_manager = mock(), decorate = False, width = 800, height = 600) game_gui.old_location = player.location model.register_event_listener(game_gui) game_gui.paint(surface) monster.move(7) rects = game_gui.update(surface) assert_that(rects, has_items(Rect(160, 88, 192, 120), Rect(192, 88, 224, 120)))
def setup(self): """ Setup test case """ self.model = Model() self.character = (CharacterBuilder().with_model( self.model).with_location((1, 1)).build()) self.model.dungeon = (LevelBuilder().with_character( self.character).build()) self.listener = mock() self.model.register_event_listener(self.listener) set_action_factory(ActionFactoryBuilder().build())
def setup(self): """ Setup test case """ self.config = Configuration(Model(), herculeum.config.levels, mock(), mock()) self.config.initialise()
class TestEventDispatching(): """ Tests for event dispatching relating to moving """ def __init__(self): """ Default constructor """ super().__init__() self.model = None self.character = None self.level = None self.listener = None self.actions = None def setup(self): """ Setup test case """ self.model = Model() self.character = (CharacterBuilder() .with_model(self.model) .with_location((1, 1)) .build()) self.model.dungeon = (LevelBuilder() .with_character(self.character) .build()) self.listener = mock() self.model.register_event_listener(self.listener) set_action_factory(ActionFactoryBuilder() .build()) def test_event_is_relayed(self): """ Test that moving will create an event and send it forward """ pyherc.vtable['\ufdd0:move'](character=self.character, direction=Direction.east) verify(self.listener).receive_event(EventType('move'))
class TestModel(): """ Class for testing Model """ def __init__(self): """ Default constructor """ super(TestModel, self).__init__() self.model = None self.listener = None self.level = None def setup(self): """ Setup test cases """ self.model = Model() self.listener = mock() self.level = LevelBuilder().build() self.model.register_event_listener(self.listener) def test_registering_event_listener(self): """ Test that event listener can be registered on the model """ assert_that(self.model, has_event_listener(self.listener)) 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)
class TestModel(): """ Class for testing Model """ def __init__(self): """ Default constructor """ super(TestModel, self).__init__() self.model = None self.listener = None self.level = None def setup(self): """ Setup test cases """ self.model = Model() self.listener = mock() self.level = LevelBuilder().build() self.model.register_event_listener(self.listener) def test_registering_event_listener(self): """ Test that event listener can be registered on the model """ assert_that(self.model, has_event_listener(self.listener)) 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)
class TestEventDispatching(): """ Tests for event dispatching relating to moving """ def __init__(self): """ Default constructor """ super().__init__() self.model = None self.character = None self.level = None self.listener = None self.actions = None def setup(self): """ Setup test case """ self.model = Model() self.character = (CharacterBuilder().with_model( self.model).with_location((1, 1)).build()) self.model.dungeon = (LevelBuilder().with_character( self.character).build()) self.listener = mock() self.model.register_event_listener(self.listener) set_action_factory(ActionFactoryBuilder().build()) def test_event_is_relayed(self): """ Test that moving will create an event and send it forward """ pyherc.vtable['\ufdd0:move'](character=self.character, direction=Direction.east) verify(self.listener).receive_event(EventType('move'))
def __init__(self): """ Default constructor """ super().__init__() self.characters = [] self.level_size = (10, 10) self.floor_tile = 1 self.wall_tile = None self.empty_wall_tile = None self.solid_wall_tile = 11 self.walls = [] self.model = Model()
def observe(*args, **kwargs): """ Inject observer """ context = args[0] if not hasattr(context, 'observer'): context.observer = EventListener() if not hasattr(context, 'model'): context.model = Model() context.model.register_event_listener(context.observer) return fn(*args, **kwargs)
def context_setup(*args, **kwargs): """ Set up context """ context = args[0] if not hasattr(context, 'model'): context.model = Model() if not hasattr(context, 'items'): context.items = [] if not hasattr(context, 'characters'): context.characters = [] if not hasattr(context, 'places'): context.places = [] return fn(*args, **kwargs)
def setup(self): """ Setup test case """ self.model = Model() self.character = (CharacterBuilder() .with_model(self.model) .with_location((1, 1)) .build()) self.model.dungeon = (LevelBuilder() .with_character(self.character) .build()) self.listener = mock() self.model.register_event_listener(self.listener) set_action_factory(ActionFactoryBuilder() .build())
def setup(self): """ Setup test cases """ self.item = (ItemBuilder() .build()) self.model = Model() self.level = LevelBuilder().build() self.character = (CharacterBuilder() .with_location((5, 5)) .with_level(self.level) .with_model(self.model) .build()) add_item(self.level, (5, 5), self.item) set_action_factory(ActionFactoryBuilder() .with_inventory_factory() .build())
def setup(self): """ Setup the test case """ self.character = (CharacterBuilder().with_model(Model()).build()) self.level1 = (LevelBuilder().with_floor_tile("floor").with_wall_at( (1, 0)).build()) self.level2 = (LevelBuilder().with_floor_tile("floor").build()) self.portal1 = Portal((None, None), None) self.portal1.icon = 1 self.portal2 = Portal(("stairs", "stairs"), None) self.portal2 = Portal(("stairs", "stairs"), None) add_portal(self.level1, (5, 5), self.portal1) add_portal(self.level2, (10, 10), self.portal2, self.portal1) add_character(self.level1, (5, 5), self.character) set_action_factory(ActionFactoryBuilder().build())
def setup(self): """ Setup test case """ self.model = Model() action_factory = (ActionFactoryBuilder() .with_move_factory() .build()) self.character = (CharacterBuilder() .with_action_factory(action_factory) .with_model(self.model) .with_location((10, 10)) .build()) self.level = (LevelBuilder() .with_character(self.character) .build()) self.listener = EventListener() self.model.register_event_listener(self.listener)
def setup(self): """ Setup for testcases """ self.model = Model() set_action_factory(ActionFactoryBuilder().build()) self.character1 = (CharacterBuilder().with_model( self.model).with_hit_points(10).with_attack(3).with_body( 5).build()) self.effect = DamageModifier(modifier=1, damage_type='crushing', duration=None, frequency=None, tick=None, icon=101, title='Weakness against crushing', description='This character is weak') self.effect.multiple_allowed = True self.character2 = (CharacterBuilder().with_model( self.model).with_hit_points(10).with_attack(3).with_body( 5).with_effect(self.effect).build()) self.model.dungeon = Dungeon() self.level = (LevelBuilder().with_character(self.character1, at_(5, 5)).with_character( self.character2, at_(6, 5)).build()) self.model.dungeon.levels = self.level self.rng = mock() when(self.rng).randint(1, 6).thenReturn(1)