Пример #1
0
    def test_level_type_is_checked(self):
        """
        Check that room generator with incorrect level type is not used
        """
        mock_action_factory = mock(ActionFactory)
        mock_partitioner = mock(GridPartitioner)
        mock_partitioner.level_types = ['crypt']
        mock_room_generator = mock()
        mock_room_generator.level_types = ['swamp']
        mock_decorator = mock()

        mock_config = mock(LevelGeneratorFactoryConfig)
        mock_config.level_partitioners = [mock_partitioner]
        mock_config.room_generators = [mock_room_generator]
        mock_config.decorators = [mock_decorator]
        random_generator = random.Random()

        exception_was_thrown = False

        factory = LevelGeneratorFactory(mock_action_factory,
                                        mock(),
                                        mock_config,
                                        random_generator)

        try:
            generator = factory.get_generator('crypt')
        except RuntimeError, err:
            assert_that(str(err), contains_string("No room for type crypt"))
            exception_was_thrown = True
Пример #2
0
    def test_passing_partitioner_to_generator(self):
        """
        Test that LevelPartitioner is correctly passed to LevelGenerator
        """
        mock_action_factory = mock(ActionFactory)
        mock_partitioner = mock(GridPartitioner)
        mock_partitioner.level_types = ['crypt']
        mock_room_generator = mock()
        mock_room_generator.level_types = ['crypt']
        mock_decorator = mock()
        mock_decorator.level_types = ['crypt']
        mock_item_adder = mock()
        mock_item_adder.level_types = ['crypt']
        mock_creature_adder = mock()
        mock_creature_adder.level_types = ['crypt']
        mock_portal_adder = mock()
        mock_portal_adder.level_types = ['crypt']

        mock_config = mock(LevelGeneratorFactoryConfig)
        mock_config.level_partitioners = [mock_partitioner]
        mock_config.room_generators = [mock_room_generator]
        mock_config.decorators = [mock_decorator]
        mock_config.item_adders = [mock_item_adder]
        mock_config.creature_adders = [mock_creature_adder]
        mock_config.portal_adders = [mock_portal_adder]

        factory = LevelGeneratorFactory(mock_action_factory,
                                        mock(),
                                        mock_config,
                                        random.Random())

        generator = factory.get_generator(level_type = 'crypt')

        assert_that(generator.partitioner, is_(same_instance(mock_partitioner)))
Пример #3
0
    def setup(self):
        """
        Setup test case
        """
        self.mock_action_factory = mock(ActionFactory)
        self.mock_config = mock(LevelGeneratorFactoryConfig)
        self.mock_partitioner = mock()
        self.mock_partitioner.level_types = ['crypt']
        self.mock_room_generator = mock()
        self.mock_room_generator.level_types = ['crypt']
        self.decorator = mock()
        self.decorator.level_types = ['crypt']
        self.mock_item_adder = mock()
        self.mock_item_adder.level_types = ['crypt']
        self.mock_creature_adder = mock()
        self.mock_creature_adder.level_types = ['crypt']
        self.mock_portal_adder = mock()
        self.mock_portal_adder.level_types = ['crypt']
        self.rng = random.Random()

        self.mock_config.level_partitioners = [self.mock_partitioner]
        self.mock_config.room_generators = [self.mock_room_generator]
        self.mock_config.decorators = [self.decorator]
        self.mock_config.item_adders = [self.mock_item_adder]
        self.mock_config.creature_adders = [self.mock_creature_adder]
        self.mock_config.portal_adders = [self.mock_portal_adder]

        self.factory = LevelGeneratorFactory(self.mock_action_factory,
                                             mock(),
                                             self.mock_config,
                                             self.rng)
Пример #4
0
class TestLeveltGeneratorFactory:
    """
    Class for testing LevelGeneratorFactory
    """
    def __init__(self):
        """
        Default constructor
        """
        self.mock_action_factory = None
        self.mock_config = None
        self.mock_partitioner = None
        self.mock_room_generator = None
        self.decorator = None
        self.mock_item_adder = None
        self.mock_creature_adder = None
        self.factory = None
        self.rng = None

    def setup(self):
        """
        Setup test case
        """
        self.mock_action_factory = mock(ActionFactory)
        self.mock_config = mock(LevelGeneratorFactoryConfig)
        self.mock_partitioner = mock()
        self.mock_partitioner.level_types = ['crypt']
        self.mock_room_generator = mock()
        self.mock_room_generator.level_types = ['crypt']
        self.decorator = mock()
        self.decorator.level_types = ['crypt']
        self.mock_item_adder = mock()
        self.mock_item_adder.level_types = ['crypt']
        self.mock_creature_adder = mock()
        self.mock_creature_adder.level_types = ['crypt']
        self.mock_portal_adder = mock()
        self.mock_portal_adder.level_types = ['crypt']
        self.rng = random.Random()

        self.mock_config.level_partitioners = [self.mock_partitioner]
        self.mock_config.room_generators = [self.mock_room_generator]
        self.mock_config.decorators = [self.decorator]
        self.mock_config.item_adders = [self.mock_item_adder]
        self.mock_config.creature_adders = [self.mock_creature_adder]
        self.mock_config.portal_adders = [self.mock_portal_adder]

        self.factory = LevelGeneratorFactory(self.mock_action_factory,
                                             mock(),
                                             self.mock_config,
                                             self.rng)

    def test_generating_level_generator(self):
        """
        Test that LevelGeneratorFactory can generate level generator
        """
        generator = self.factory.get_generator('crypt')

        assert generator != None
        assert generator.action_factory == self.mock_action_factory
Пример #5
0
    def setup(self):
        """
        Setup test case
        """
        mock_action_factory = mock(ActionFactory)
        self.partitioner_1 = mock(GridPartitioner)
        self.partitioner_1.level_types = ['crypt', 'castle']
        self.partitioner_2 = mock(GridPartitioner)
        self.partitioner_2.level_types = ['swamp']

        self.room_generator_1 = mock(SquareRoomGenerator)
        self.room_generator_1.level_types = ['crypt']
        self.room_generator_2 = mock(SquareRoomGenerator)
        self.room_generator_2.level_types = ['swamp', 'castle']

        self.decorator_1 = mock(ReplacingDecorator)
        self.decorator_1.level_types = ['crypt', 'swamp']
        self.decorator_2 = mock(ReplacingDecorator)
        self.decorator_2.level_types = ['castle']

        self.item_adder_1 = mock(ItemAdder)
        self.item_adder_1.level_types = ['crypt']
        self.item_adder_2 = mock(ItemAdder)
        self.item_adder_2.level_types = ['castle']

        self.creature_adder_1 = mock(CreatureAdder)
        self.creature_adder_1.level_types = ['crypt', 'castle']
        self.creature_adder_2 = mock(CreatureAdder)
        self.creature_adder_2.level_types = ['swamp']

        mock_config = mock(LevelGeneratorFactoryConfig)
        mock_config.level_partitioners = [self.partitioner_1,
                                          self.partitioner_2]
        mock_config.room_generators = [self.room_generator_1,
                                       self.room_generator_2]
        mock_config.decorators = [self.decorator_1,
                                  self.decorator_2]
        mock_config.item_adders = [self.item_adder_1,
                                   self.item_adder_2]
        mock_config.creature_adders = [self.creature_adder_1,
                                       self.creature_adder_2]
        mock_config.portal_adder_configurations = []

        self.random_generator = random.Random()

        self.factory = LevelGeneratorFactory(mock_action_factory,
                                             mock(),
                                             mock_config,
                                             self.random_generator)
Пример #6
0
class TestFactorySupportForLevelTypes:
    """
    Class for testing configuring of LevelGeneratorFactory with level types
    """
    def __init__(self):
        """
        Default constructor
        """
        self.partitioner_1 = None
        self.partitioner_2 = None
        self.room_generator_1 = None
        self.room_generator_2 = None
        self.decorator_1 = None
        self.decorator_2 = None
        self.item_adder_1 = None
        self.item_adder_2 = None
        self.creature_adder_1 = None
        self.creature_adder_2 = None
        mock_config = None
        self.random_generator = None
        self.factory = None

    def setup(self):
        """
        Setup test case
        """
        mock_action_factory = mock(ActionFactory)
        self.partitioner_1 = mock(GridPartitioner)
        self.partitioner_1.level_types = ['crypt', 'castle']
        self.partitioner_2 = mock(GridPartitioner)
        self.partitioner_2.level_types = ['swamp']

        self.room_generator_1 = mock(SquareRoomGenerator)
        self.room_generator_1.level_types = ['crypt']
        self.room_generator_2 = mock(SquareRoomGenerator)
        self.room_generator_2.level_types = ['swamp', 'castle']

        self.decorator_1 = mock(ReplacingDecorator)
        self.decorator_1.level_types = ['crypt', 'swamp']
        self.decorator_2 = mock(ReplacingDecorator)
        self.decorator_2.level_types = ['castle']

        self.item_adder_1 = mock(ItemAdder)
        self.item_adder_1.level_types = ['crypt']
        self.item_adder_2 = mock(ItemAdder)
        self.item_adder_2.level_types = ['castle']

        self.creature_adder_1 = mock(CreatureAdder)
        self.creature_adder_1.level_types = ['crypt', 'castle']
        self.creature_adder_2 = mock(CreatureAdder)
        self.creature_adder_2.level_types = ['swamp']

        mock_config = mock(LevelGeneratorFactoryConfig)
        mock_config.level_partitioners = [self.partitioner_1,
                                          self.partitioner_2]
        mock_config.room_generators = [self.room_generator_1,
                                       self.room_generator_2]
        mock_config.decorators = [self.decorator_1,
                                  self.decorator_2]
        mock_config.item_adders = [self.item_adder_1,
                                   self.item_adder_2]
        mock_config.creature_adders = [self.creature_adder_1,
                                       self.creature_adder_2]
        mock_config.portal_adder_configurations = []

        self.random_generator = random.Random()

        self.factory = LevelGeneratorFactory(mock_action_factory,
                                             mock(),
                                             mock_config,
                                             self.random_generator)

    def test_partitioner_type(self):
        """
        Test that partitioners can be retrieved by level types
        """
        generator = self.factory.get_generator('crypt')

        assert_that(generator.partitioner,
                    is_(same_instance(self.partitioner_1)))

    def test_room_generator_type(self):
        """
        Test that room generators can be retrieved by level types
        """
        generator = self.factory.get_generator('crypt')

        assert_that(generator.room_generators,
                    has_item(self.room_generator_1))

    def test_decorator_type(self):
        """
        Test that decorators can be retrieved by level types
        """
        generator = self.factory.get_generator('crypt')

        assert_that(generator.decorator,
                    is_(same_instance(self.decorator_1)))

    def test_item_adder_type(self):
        """
        Test that item adders can be retrieved by level types
        """
        generator = self.factory.get_generator('crypt')

        assert_that(generator.item_adder,
                    is_(same_instance(self.item_adder_1)))

    def test_creature_adder_type(self):
        """
        Test that creature adders can be retrieved by level types
        """
        generator = self.factory.get_generator('crypt')

        assert_that(generator.creature_adder,
                    is_(same_instance(self.creature_adder_1)))