コード例 #1
0
ファイル: test_assemblage.py プロジェクト: EricSchles/braga
    def test_unknown_initial_properties_at_production_time(self):
        cat_factory = Assemblage(components=[Alive, Portable])

        with self.assertRaises(ValueError) as e:
            cat_factory.make(live=True, aliv=True)  # misspell some properties

        self.assertEqual(e.exception.message, "Unknown initial properties: live, aliv")
コード例 #2
0
ファイル: test_assemblage.py プロジェクト: pathunstrom/braga
    def test_assembled_cats_are_independent(self):
        cat_factory = Assemblage([Alive, Portable])

        my_cat = cat_factory.make()
        stray_cat = cat_factory.make()
        self.human.pick_up(my_cat)

        self.assertNotEqual(my_cat.uuid, stray_cat.uuid)
        self.assertIn(my_cat, self.human.inventory)
        self.assertNotIn(stray_cat, self.human.inventory)
コード例 #3
0
ファイル: test_assemblage.py プロジェクト: pathunstrom/braga
    def test_assembling_entity_with_initial_conditions(self):
        zombie_cat_factory = Assemblage([Alive], alive=False)
        zombie_cat = zombie_cat_factory.make()
        self.assertFalse(zombie_cat.alive)
        zombie_cat.resurrect()
        self.assertTrue(zombie_cat.alive)

        fed_cat_factory = Assemblage([Container], inventory=set([self.food]))
        fed_cat = fed_cat_factory.make()
        self.assertEqual(self.food.uuid, fed_cat.inventory.pop().uuid)
コード例 #4
0
ファイル: test_assemblage.py プロジェクト: EricSchles/braga
    def test_assembled_cats_are_independent(self):
        cat_factory = Assemblage([Alive, Portable])

        my_cat = cat_factory.make()
        stray_cat = cat_factory.make()
        self.human.pick_up(my_cat)

        self.assertNotEqual(my_cat.uuid, stray_cat.uuid)
        self.assertIn(my_cat, self.human.inventory)
        self.assertNotIn(stray_cat, self.human.inventory)
コード例 #5
0
ファイル: test_assemblage.py プロジェクト: EricSchles/braga
    def test_assembling_entity_with_initial_conditions(self):
        zombie_cat_factory = Assemblage([Alive], alive=False)
        zombie_cat = zombie_cat_factory.make()
        self.assertFalse(zombie_cat.alive)
        zombie_cat.resurrect()
        self.assertTrue(zombie_cat.alive)

        fed_cat_factory = Assemblage([Container], inventory=set([self.food]))
        fed_cat = fed_cat_factory.make()
        self.assertEqual(self.food.uuid, fed_cat.inventory.pop().uuid)
コード例 #6
0
ファイル: test_assemblage.py プロジェクト: pathunstrom/braga
    def test_unknown_initial_properties_at_production_time(self):
        cat_factory = Assemblage(components=[Alive, Portable])

        with self.assertRaises(ValueError) as e:
            cat_factory.make(live=True, aliv=True)  # misspell some properties

        if six.PY2:
            exception_message = e.exception.message
        if six.PY3:
            exception_message = str(e.exception)

        self.assertEqual(exception_message,
                         "Unknown initial properties: live, aliv")
コード例 #7
0
ファイル: test_assemblage.py プロジェクト: pathunstrom/braga
    def test_initializing_components_at_production_time(self):
        cat_factory = Assemblage(components=[Alive, Portable])
        zombie_cat = cat_factory.make(alive=False)

        self.assertTrue(isinstance(zombie_cat, Entity))
        self.assertFalse(zombie_cat.alive)
        self.assertTrue(zombie_cat.is_portable)
コード例 #8
0
ファイル: test_assemblage.py プロジェクト: pathunstrom/braga
    def test_assemblage_makes_entity(self):
        cat_factory = Assemblage([Alive, Portable])
        cat = cat_factory.make()

        self.assertTrue(isinstance(cat, Entity))
        self.assertTrue(cat.alive)
        self.assertTrue(cat.is_portable)
コード例 #9
0
ファイル: tests.py プロジェクト: EricSchles/braga
class TestContainerSystem(unittest.TestCase):

    def setUp(self):
        self.world = World()
        bucket_factory = Assemblage(components=[duel.Container])
        self.bucket_one = self.world.make_entity(bucket_factory)
        self.bucket_two = self.world.make_entity(bucket_factory)

        self.thing_factory = Assemblage(components=[duel.Moveable])
        self.thing = self.world.make_entity(self.thing_factory, location=self.bucket_one)

        self.container_system = duel.ContainerSystem(world=self.world, auto_update=True)

    def test_move_item_to_new_inventory(self):
        self.container_system.move(self.thing, self.bucket_two)

        self.assertEqual(self.thing.location, self.bucket_two)
        self.assertEqual(self.bucket_two.inventory, set([self.thing]))

    def test_cannot_move_immoveable_item(self):
        bookcase = self.world.make_entity()

        with self.assertRaises(ValueError) as e:
            self.container_system.move(bookcase, self.bucket_two)

        self.assertEqual(e.exception.message, "You cannot move this item")
        self.assertEqual(self.bucket_two.inventory, set([]))

    def test_cannot_move_item_to_non_container(self):
        new_thing = self.thing_factory.make()
        with self.assertRaises(ValueError) as e:
            self.container_system.move(self.thing, new_thing)

        self.assertEqual(e.exception.message, "Invalid destination")
        self.assertEqual(self.thing.location, self.bucket_one)
コード例 #10
0
class TestContainerSystem(unittest.TestCase):

    def setUp(self):
        self.world = World()
        bucket_factory = Assemblage(components=[Container])
        self.bucket_one = self.world.make_entity(bucket_factory)
        self.bucket_two = self.world.make_entity(bucket_factory)

        self.thing_factory = Assemblage(components=[Moveable])
        self.thing = self.world.make_entity(self.thing_factory, location=self.bucket_one)

        self.container_system = ContainerSystem(world=self.world)

    def test_move_item_to_new_inventory(self):
        self.container_system.move(self.thing, self.bucket_two)

        self.assertEqual(self.thing.location, self.bucket_two)
        self.assertEqual(self.bucket_two.inventory, set([self.thing]))

    def test_cannot_move_immoveable_item(self):
        bookcase = self.world.make_entity()

        with self.assertRaises(ValueError) as e:
            self.container_system.move(bookcase, self.bucket_two)

        self.assertEqual(e.exception.message, "You cannot move this item")
        self.assertEqual(self.bucket_two.inventory, set([]))

    def test_cannot_move_item_to_non_container(self):
        new_thing = self.thing_factory.make()
        with self.assertRaises(ValueError) as e:
            self.container_system.move(self.thing, new_thing)

        self.assertEqual(e.exception.message, "Invalid destination")
        self.assertEqual(self.thing.location, self.bucket_one)
コード例 #11
0
ファイル: test_assemblage.py プロジェクト: EricSchles/braga
    def test_initializing_components_at_production_time(self):
        cat_factory = Assemblage(components=[Alive, Portable])
        zombie_cat = cat_factory.make(alive=False)

        self.assertTrue(isinstance(zombie_cat, Entity))
        self.assertFalse(zombie_cat.alive)
        self.assertTrue(zombie_cat.is_portable)
コード例 #12
0
ファイル: test_assemblage.py プロジェクト: EricSchles/braga
    def test_assemblage_makes_entity(self):
        cat_factory = Assemblage([Alive, Portable])
        cat = cat_factory.make()

        self.assertTrue(isinstance(cat, Entity))
        self.assertTrue(cat.alive)
        self.assertTrue(cat.is_portable)
コード例 #13
0
ファイル: test_assemblage.py プロジェクト: pathunstrom/braga
    def test_adding_component_with_initial_components(self):
        cat_factory = Assemblage(components=[Portable])
        cat_factory.add_component(Alive)
        cat = cat_factory.make()

        self.assertTrue(isinstance(cat, Entity))
        self.assertTrue(cat.alive)
        self.assertTrue(cat.is_portable)
コード例 #14
0
ファイル: test_assemblage.py プロジェクト: EricSchles/braga
    def test_adding_component_with_initial_components(self):
        cat_factory = Assemblage(components=[Portable])
        cat_factory.add_component(Alive)
        cat = cat_factory.make()

        self.assertTrue(isinstance(cat, Entity))
        self.assertTrue(cat.alive)
        self.assertTrue(cat.is_portable)
コード例 #15
0
ファイル: test_assemblage.py プロジェクト: pathunstrom/braga
    def test_assembled_entity_interacts_normally(self):
        cat_factory = Assemblage([Alive, Portable, Container])
        cat = cat_factory.make()

        # pick up cat
        self.human.pick_up(cat)
        self.assertIn(cat, self.human.inventory)

        # feed cat
        cat.pick_up(self.food)
        self.assertIn(self.food, cat.inventory)
コード例 #16
0
ファイル: test_assemblage.py プロジェクト: EricSchles/braga
    def test_assembled_entity_interacts_normally(self):
        cat_factory = Assemblage([Alive, Portable, Container])
        cat = cat_factory.make()

        # pick up cat
        self.human.pick_up(cat)
        self.assertIn(cat, self.human.inventory)

        # feed cat
        cat.pick_up(self.food)
        self.assertIn(self.food, cat.inventory)