예제 #1
0
    def test_destroy(self):
        r = self.world.getByID(1)
        b = BerinObject(self.world, r, oshort="doomed object")
        b.moveTo(self.o)
        world.destroy(self.o)

        unittest.assertEquals(r.getItem(self.o.getAttribute("oshort")), None)

        unittest.assertEquals(self.world.getByID(self.o.getID()), None)
        unittest.assertEquals(self.world.getByID(b.getID()), None)

        unittest.assertFalse(b in self.o.contents)
        unittest.assertFalse(o in self.o.contents)
예제 #2
0
class BerinObjectTester(TestCase):
    def setUp(self):
        self.world = DummyWorld( )
        self.wrath = BerinObject(self.world, None, oshort="Lis0r's wrath",
                odesc="Lis0r's wrath has been condensed into physical form and placed in a jar. The jar is hot.")
        self.box = BerinObject(self.world, None, oshort="a braced steel box",
                odesc="A reinforced box made of 3 inch steel.")

    def test_creation(self):
        a = BerinObject(self.world, None, oshort="an orange",
                odesc="Luckily, the orange is just an object and nothing special.")
        # Initialisation assertions
        self.assertEquals(a.getLocation( ), None)
        self.assertEquals(a.getID( ), self.world.latestID)
        self.assertEquals(a.getLocation( ), a.loc)

    def test_moveTo(self):
        # Moving a into b causes a to be inside b, and b to contain a
        self.wrath.moveTo(self.box)
        self.assertEquals(self.wrath.getLocation(), self.box)
        self.assertTrue(self.wrath in self.box.contents)

        # BerinObject.hasItem( item ) accepts item as an item or item ID
        self.assertTrue(self.box.hasItem(self.wrath))
        self.assertTrue(self.box.hasItem(self.wrath.getID()))

    def test_moveToSpecifics(self):
        self.wrath.pushItem(self.box)
        self.assertTrue(self.wrath.hasItem(self.box))
        
        self.assertTrue(self.box.getLocation() != self.wrath)

    def test_moveOut(self):
        self.wrath.moveTo(None)
        self.box.moveTo(None)

        self.assertEquals(self.wrath.loc, None)
        self.assertEquals(self.box.loc, None)

    def test_idAssignment(self):
        c = BerinObject(self.world, None, id=131)
        self.assertEquals(c.ident, 131)
        self.assertEquals(c.getID(), c.ident)

        self.assertRaises(ValueError, BerinObject, self.world, None, id="bacon")