Exemplo n.º 1
0
    def test_prototype_storage(self):

        # from evennia import set_trace;set_trace(term_size=(180, 50))
        prot1 = protlib.create_prototype(self.prot1)

        self.assertTrue(bool(prot1))
        self.assertEqual(prot1, self.prot1)

        self.assertEqual(prot1["prototype_desc"], "testdesc1")

        self.assertEqual(prot1["prototype_tags"], [("foo1", _PROTOTYPE_TAG_META_CATEGORY)])
        self.assertEqual(
            protlib.DbPrototype.objects.get_by_tag("foo1", _PROTOTYPE_TAG_META_CATEGORY)[
                0
            ].db.prototype,
            prot1,
        )

        prot2 = protlib.create_prototype(self.prot2)
        self.assertEqual(
            [
                pobj.db.prototype
                for pobj in protlib.DbPrototype.objects.get_by_tag(
                    "foo1", _PROTOTYPE_TAG_META_CATEGORY
                )
            ],
            [prot1, prot2],
        )

        # add to existing prototype
        prot1b = protlib.create_prototype(
            {"prototype_key": "testprototype1", "foo": "bar", "prototype_tags": ["foo2"]}
        )

        self.assertEqual(
            [
                pobj.db.prototype
                for pobj in protlib.DbPrototype.objects.get_by_tag(
                    "foo2", _PROTOTYPE_TAG_META_CATEGORY
                )
            ],
            [prot1b],
        )

        self.assertEqual(list(protlib.search_prototype("testprototype2")), [prot2])
        self.assertNotEqual(list(protlib.search_prototype("testprototype1")), [prot1])
        self.assertEqual(list(protlib.search_prototype("testprototype1")), [prot1b])

        prot3 = protlib.create_prototype(self.prot3)

        # partial match
        with mock.patch("evennia.prototypes.prototypes._MODULE_PROTOTYPES", {}):
            self.assertCountEqual(protlib.search_prototype("prot"), [prot1b, prot2, prot3])
            self.assertCountEqual(protlib.search_prototype(tags="foo1"), [prot1b, prot2, prot3])

        self.assertTrue(str(str(protlib.list_prototypes(self.char1))))
Exemplo n.º 2
0
    def test_prototype_storage(self):

        # from evennia import set_trace;set_trace(term_size=(180, 50))
        prot1 = protlib.create_prototype(**self.prot1)

        self.assertTrue(bool(prot1))
        self.assertEqual(prot1, self.prot1)

        self.assertEqual(prot1['prototype_desc'], "testdesc1")

        self.assertEqual(prot1['prototype_tags'],
                         [("foo1", _PROTOTYPE_TAG_META_CATEGORY)])
        self.assertEqual(
            protlib.DbPrototype.objects.get_by_tag(
                "foo1", _PROTOTYPE_TAG_META_CATEGORY)[0].db.prototype, prot1)

        prot2 = protlib.create_prototype(**self.prot2)
        self.assertEqual([
            pobj.db.prototype
            for pobj in protlib.DbPrototype.objects.get_by_tag(
                "foo1", _PROTOTYPE_TAG_META_CATEGORY)
        ], [prot1, prot2])

        # add to existing prototype
        prot1b = protlib.create_prototype(prototype_key='testprototype1',
                                          foo='bar',
                                          prototype_tags=['foo2'])

        self.assertEqual([
            pobj.db.prototype
            for pobj in protlib.DbPrototype.objects.get_by_tag(
                "foo2", _PROTOTYPE_TAG_META_CATEGORY)
        ], [prot1b])

        self.assertEqual(list(protlib.search_prototype("testprototype2")),
                         [prot2])
        self.assertNotEqual(list(protlib.search_prototype("testprototype1")),
                            [prot1])
        self.assertEqual(list(protlib.search_prototype("testprototype1")),
                         [prot1b])

        prot3 = protlib.create_prototype(**self.prot3)

        # partial match
        self.assertEqual(list(protlib.search_prototype("prot")),
                         [prot1b, prot2, prot3])
        self.assertEqual(list(protlib.search_prototype(tags="foo1")),
                         [prot1b, prot2, prot3])

        self.assertTrue(str(unicode(protlib.list_prototypes(self.char1))))
Exemplo n.º 3
0
    def test_spawn(self):
        def getObject(commandTest, objKeyStr):
            # A helper function to get a spawned object and
            # check that it exists in the process.
            query = search_object(objKeyStr)
            commandTest.assertIsNotNone(query)
            commandTest.assertTrue(bool(query))
            obj = query[0]
            commandTest.assertIsNotNone(obj)
            return obj

        # Tests "spawn" without any arguments.
        self.call(building.CmdSpawn(), " ", "Usage: spawn")

        # Tests "spawn <prototype_dictionary>" without specifying location.

        self.call(
            building.CmdSpawn(),
            "/save {'prototype_key': 'testprot', 'key':'Test Char', "
            "'typeclass':'evennia.objects.objects.DefaultCharacter'}",
            "Saved prototype: testprot",
            inputs=["y"],
        )

        self.call(building.CmdSpawn(), "/search ", "Key ")
        self.call(building.CmdSpawn(), "/search test;test2", "")

        self.call(
            building.CmdSpawn(),
            "/save {'key':'Test Char', "
            "'typeclass':'evennia.objects.objects.DefaultCharacter'}",
            "To save a prototype it must have the 'prototype_key' set.",
        )

        self.call(building.CmdSpawn(), "/list", "Key ")

        self.call(building.CmdSpawn(), "testprot", "Spawned Test Char")
        # Tests that the spawned object's location is the same as the caharacter's location, since
        # we did not specify it.
        testchar = getObject(self, "Test Char")
        self.assertEqual(testchar.location, self.char1.location)
        testchar.delete()

        # Test "spawn <prototype_dictionary>" with a location other than the character's.
        spawnLoc = self.room2
        if spawnLoc == self.char1.location:
            # Just to make sure we use a different location, in case someone changes
            # char1's default location in the future...
            spawnLoc = self.room1

        self.call(
            building.CmdSpawn(),
            "{'prototype_key':'GOBLIN', 'typeclass':'evennia.objects.objects.DefaultCharacter', "
            "'key':'goblin', 'location':'%s'}" % spawnLoc.dbref,
            "Spawned goblin",
        )
        goblin = getObject(self, "goblin")
        # Tests that the spawned object's type is a DefaultCharacter.
        self.assertIsInstance(goblin, DefaultCharacter)
        self.assertEqual(goblin.location, spawnLoc)

        goblin.delete()

        # create prototype
        protlib.create_prototype({
            "key": "Ball",
            "typeclass": "evennia.objects.objects.DefaultCharacter",
            "prototype_key": "testball",
        })

        # Tests "spawn <prototype_name>"
        self.call(building.CmdSpawn(), "testball", "Spawned Ball")

        ball = getObject(self, "Ball")
        self.assertEqual(ball.location, self.char1.location)
        self.assertIsInstance(ball, DefaultObject)
        ball.delete()

        # Tests "spawn/n ..." without specifying a location.
        # Location should be "None".
        self.call(building.CmdSpawn(), "/n 'BALL'",
                  "Spawned Ball")  # /n switch is abbreviated form of /noloc
        ball = getObject(self, "Ball")
        self.assertIsNone(ball.location)
        ball.delete()

        self.call(
            building.CmdSpawn(),
            "/noloc {'prototype_parent':'TESTBALL', 'prototype_key': 'testball', 'location':'%s'}"
            % spawnLoc.dbref,
            "Error: Prototype testball tries to parent itself.",
        )

        # Tests "spawn/noloc ...", but DO specify a location.
        # Location should be the specified location.
        self.call(
            building.CmdSpawn(),
            "/noloc {'prototype_parent':'TESTBALL', 'key': 'Ball', 'prototype_key': 'foo', 'location':'%s'}"
            % spawnLoc.dbref,
            "Spawned Ball",
        )
        ball = getObject(self, "Ball")
        self.assertEqual(ball.location, spawnLoc)
        ball.delete()

        # test calling spawn with an invalid prototype.
        self.call(building.CmdSpawn(), "'NO_EXIST'",
                  "No prototype named 'NO_EXIST'")

        # Test listing commands
        self.call(building.CmdSpawn(), "/list", "Key ")

        # spawn/edit (missing prototype)
        # brings up olc menu
        msg = self.call(building.CmdSpawn(), "/edit")
        assert "Prototype wizard" in msg

        # spawn/edit with valid prototype
        # brings up olc menu loaded with prototype
        msg = self.call(building.CmdSpawn(), "/edit testball")
        assert "Prototype wizard" in msg
        assert hasattr(self.char1.ndb._menutree, "olc_prototype")
        assert (dict == type(self.char1.ndb._menutree.olc_prototype)
                and "prototype_key" in self.char1.ndb._menutree.olc_prototype
                and "key" in self.char1.ndb._menutree.olc_prototype
                and "testball"
                == self.char1.ndb._menutree.olc_prototype["prototype_key"]
                and "Ball" == self.char1.ndb._menutree.olc_prototype["key"])
        assert "Ball" in msg and "testball" in msg

        # spawn/edit with valid prototype (synomym)
        msg = self.call(building.CmdSpawn(), "/edit BALL")
        assert "Prototype wizard" in msg
        assert "Ball" in msg and "testball" in msg

        # spawn/edit with invalid prototype
        msg = self.call(building.CmdSpawn(), "/edit NO_EXISTS",
                        "No prototype 'NO_EXISTS' was found.")

        # spawn/examine (missing prototype)
        # lists all prototypes that exist
        msg = self.call(building.CmdSpawn(), "/examine")
        assert "testball" in msg and "testprot" in msg

        # spawn/examine with valid prototype
        # prints the prototype
        msg = self.call(building.CmdSpawn(), "/examine BALL")
        assert "Ball" in msg and "testball" in msg

        # spawn/examine with invalid prototype
        # shows error
        self.call(building.CmdSpawn(), "/examine NO_EXISTS",
                  "No prototype 'NO_EXISTS' was found.")
Exemplo n.º 4
0
    def test_spawn(self):
        def getObject(commandTest, objKeyStr):
            # A helper function to get a spawned object and
            # check that it exists in the process.
            query = search_object(objKeyStr)
            commandTest.assertIsNotNone(query)
            commandTest.assertTrue(bool(query))
            obj = query[0]
            commandTest.assertIsNotNone(obj)
            return obj

        # Tests "@spawn" without any arguments.
        self.call(building.CmdSpawn(), " ", "Usage: @spawn")

        # Tests "@spawn <prototype_dictionary>" without specifying location.

        self.call(building.CmdSpawn(),
                  "/save {'prototype_key': 'testprot', 'key':'Test Char', "
                  "'typeclass':'evennia.objects.objects.DefaultCharacter'}",
                  "Saved prototype: testprot", inputs=['y'])

        self.call(building.CmdSpawn(), "/list", "Key ")

        self.call(building.CmdSpawn(), 'testprot', "Spawned Test Char")
        # Tests that the spawned object's location is the same as the caharacter's location, since
        # we did not specify it.
        testchar = getObject(self, "Test Char")
        self.assertEqual(testchar.location, self.char1.location)
        testchar.delete()

        # Test "@spawn <prototype_dictionary>" with a location other than the character's.
        spawnLoc = self.room2
        if spawnLoc == self.char1.location:
            # Just to make sure we use a different location, in case someone changes
            # char1's default location in the future...
            spawnLoc = self.room1

        self.call(building.CmdSpawn(),
                "{'prototype_key':'GOBLIN', 'typeclass':'evennia.objects.objects.DefaultCharacter', "
                "'key':'goblin', 'location':'%s'}" % spawnLoc.dbref, "Spawned goblin")
        goblin = getObject(self, "goblin")
        # Tests that the spawned object's type is a DefaultCharacter.
        self.assertIsInstance(goblin, DefaultCharacter)
        self.assertEqual(goblin.location, spawnLoc)

        goblin.delete()

        # create prototype
        protlib.create_prototype(**{'key': 'Ball',
                                    'typeclass': 'evennia.objects.objects.DefaultCharacter',
                                    'prototype_key': 'testball'})

        # Tests "@spawn <prototype_name>"
        self.call(building.CmdSpawn(), "testball", "Spawned Ball")

        ball = getObject(self, "Ball")
        self.assertEqual(ball.location, self.char1.location)
        self.assertIsInstance(ball, DefaultObject)
        ball.delete()

        # Tests "@spawn/n ..." without specifying a location.
        # Location should be "None".
        self.call(building.CmdSpawn(), "/n 'BALL'", "Spawned Ball")   # /n switch is abbreviated form of /noloc
        ball = getObject(self, "Ball")
        self.assertIsNone(ball.location)
        ball.delete()

        self.call(building.CmdSpawn(),
                "/noloc {'prototype_parent':'TESTBALL', 'prototype_key': 'testball', 'location':'%s'}"
                % spawnLoc.dbref, "Error: Prototype testball tries to parent itself.")

        # Tests "@spawn/noloc ...", but DO specify a location.
        # Location should be the specified location.
        self.call(building.CmdSpawn(),
                "/noloc {'prototype_parent':'TESTBALL', 'key': 'Ball', 'prototype_key': 'foo', 'location':'%s'}"
                  % spawnLoc.dbref, "Spawned Ball")
        ball = getObject(self, "Ball")
        self.assertEqual(ball.location, spawnLoc)
        ball.delete()

        # test calling spawn with an invalid prototype.
        self.call(building.CmdSpawn(), "'NO_EXIST'", "No prototype named 'NO_EXIST'")

        # Test listing commands
        self.call(building.CmdSpawn(), "/list", "Key ")
Exemplo n.º 5
0
    def test_spawn(self):
        def getObject(commandTest, objKeyStr):
            # A helper function to get a spawned object and
            # check that it exists in the process.
            query = search_object(objKeyStr)
            commandTest.assertIsNotNone(query)
            commandTest.assertTrue(bool(query))
            obj = query[0]
            commandTest.assertIsNotNone(obj)
            return obj

        # Tests "@spawn" without any arguments.
        self.call(building.CmdSpawn(), " ", "Usage: @spawn")

        # Tests "@spawn <prototype_dictionary>" without specifying location.

        self.call(building.CmdSpawn(),
                  "/save {'prototype_key': 'testprot', 'key':'Test Char', "
                  "'typeclass':'evennia.objects.objects.DefaultCharacter'}",
                  "Saved prototype: testprot",
                  inputs=['y'])

        self.call(building.CmdSpawn(), "/list", "Key ")

        self.call(building.CmdSpawn(), 'testprot', "Spawned Test Char")
        # Tests that the spawned object's location is the same as the caharacter's location, since
        # we did not specify it.
        testchar = getObject(self, "Test Char")
        self.assertEqual(testchar.location, self.char1.location)
        testchar.delete()

        # Test "@spawn <prototype_dictionary>" with a location other than the character's.
        spawnLoc = self.room2
        if spawnLoc == self.char1.location:
            # Just to make sure we use a different location, in case someone changes
            # char1's default location in the future...
            spawnLoc = self.room1

        self.call(
            building.CmdSpawn(),
            "{'prototype_key':'GOBLIN', 'typeclass':'evennia.objects.objects.DefaultCharacter', "
            "'key':'goblin', 'location':'%s'}" % spawnLoc.dbref,
            "Spawned goblin")
        goblin = getObject(self, "goblin")
        # Tests that the spawned object's type is a DefaultCharacter.
        self.assertIsInstance(goblin, DefaultCharacter)
        self.assertEqual(goblin.location, spawnLoc)

        goblin.delete()

        # create prototype
        protlib.create_prototype(
            **{
                'key': 'Ball',
                'typeclass': 'evennia.objects.objects.DefaultCharacter',
                'prototype_key': 'testball'
            })

        # Tests "@spawn <prototype_name>"
        self.call(building.CmdSpawn(), "testball", "Spawned Ball")

        ball = getObject(self, "Ball")
        self.assertEqual(ball.location, self.char1.location)
        self.assertIsInstance(ball, DefaultObject)
        ball.delete()

        # Tests "@spawn/n ..." without specifying a location.
        # Location should be "None".
        self.call(building.CmdSpawn(), "/n 'BALL'",
                  "Spawned Ball")  # /n switch is abbreviated form of /noloc
        ball = getObject(self, "Ball")
        self.assertIsNone(ball.location)
        ball.delete()

        self.call(
            building.CmdSpawn(),
            "/noloc {'prototype_parent':'TESTBALL', 'prototype_key': 'testball', 'location':'%s'}"
            % spawnLoc.dbref,
            "Error: Prototype testball tries to parent itself.")

        # Tests "@spawn/noloc ...", but DO specify a location.
        # Location should be the specified location.
        self.call(
            building.CmdSpawn(),
            "/noloc {'prototype_parent':'TESTBALL', 'key': 'Ball', 'prototype_key': 'foo', 'location':'%s'}"
            % spawnLoc.dbref, "Spawned Ball")
        ball = getObject(self, "Ball")
        self.assertEqual(ball.location, spawnLoc)
        ball.delete()

        # test calling spawn with an invalid prototype.
        self.call(building.CmdSpawn(), "'NO_EXIST'",
                  "No prototype named 'NO_EXIST'")

        # Test listing commands
        self.call(building.CmdSpawn(), "/list", "Key ")