Exemplo n.º 1
0
    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
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
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))
Exemplo n.º 4
0
    def setup(self):
        """
        Setup test cases
        """
        self.model = Model()
        self.listener = mock()
        self.level = LevelBuilder().build()

        self.model.register_event_listener(self.listener)
Exemplo n.º 5
0
    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)))
Exemplo n.º 6
0
    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)))
Exemplo n.º 7
0
    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())
Exemplo n.º 8
0
    def setup(self):
        """
        Setup test case
        """
        self.config = Configuration(Model(), herculeum.config.levels, mock(),
                                    mock())

        self.config.initialise()
Exemplo n.º 9
0
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'))
Exemplo n.º 10
0
    def setup(self):
        """
        Setup test cases
        """
        self.model = Model()
        self.listener = mock()
        self.level = LevelBuilder().build()

        self.model.register_event_listener(self.listener)
Exemplo n.º 11
0
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)
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
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'))
Exemplo n.º 14
0
 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()
Exemplo n.º 15
0
    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)
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
    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())
Exemplo n.º 18
0
    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())
Exemplo n.º 19
0
    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())
Exemplo n.º 20
0
    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)
Exemplo n.º 21
0
    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)