Ejemplo n.º 1
0
    def testVariableInfo(self):
        lwob = ldmud.LWObject("/testob")
        self.assertIsNotNone(lwob)

        self.assertTrue('testvar' in dir(lwob.variables))
        self.assertTrue('testvar' in lwob.variables.__dict__)

        var = lwob.variables.testvar
        self.assertIsNotNone(var)
        self.assertTrue(var)
        self.assertEqual(var.name, "testvar")
        self.assertEqual(var.value, 42)
        self.assertSetEqual(set(var.type), set((
            int,
            float,
        )))
        self.assertEqual(var.flags, ldmud.VF_NOSAVE)
        self.assertEqual(var.visibility, ldmud.VIS_PROTECTED)
        self.assertTrue("testvar" in repr(var) and "testob" in repr(var))
        self.assertEqual(hash(var), hash(lwob.variables.testvar))
        self.assertEqual(var, lwob.variables.testvar)
        self.assertNotEqual(var, lwob.variables.var_testob)

        var.value = 84
        self.assertEqual(var.value, 84)

        with self.assertRaises(TypeError):
            var.value = "42"
        self.assertEqual(var.value, 84)
Ejemplo n.º 2
0
    def testFunctionInfo(self):
        lwob = ldmud.LWObject("/testob")
        self.assertIsNotNone(lwob)

        self.assertTrue('testfun' in dir(lwob.functions))
        self.assertTrue('testfun' in lwob.functions.__dict__)

        fun = lwob.functions.testfun
        self.assertIsNotNone(fun)
        self.assertTrue(fun)
        self.assertEqual(fun.name, "testfun")
        self.assertEqual(fun.file_name, "/testob.c")
        self.assertGreater(fun.line_number, 0)
        self.assertEqual(fun.return_type, int)
        self.assertEqual(fun.flags, ldmud.LF_NOMASK)
        self.assertEqual(fun.visibility, ldmud.VIS_PROTECTED)
        self.assertTrue("testfun" in repr(fun) and "testob" in repr(fun))
        self.assertEqual(hash(fun), hash(lwob.functions.testfun))
        self.assertEqual(fun, lwob.functions.testfun)
        self.assertNotEqual(fun, lwob.functions.fun_testob)

        args = fun.arguments
        self.assertEqual(len(args), 2)
        self.assertEqual(args[0].position, 1)
        self.assertSetEqual(set(args[0].type), set((
            int,
            float,
        )))
        self.assertEqual(args[1].position, 2)
        self.assertEqual(args[1].flags, ldmud.LA_VARARGS)
        self.assertEqual(args[1].type, ldmud.Array)

        self.assertEqual(fun(10, "A", "B", "C"), 3)
Ejemplo n.º 3
0
 def testLWOLfun(self):
     lwob = ldmud.LWObject("/testob")
     s = ldmud.Closure(lwob, "testfun", lwob)
     self.assertIsNotNone(s)
     self.assertEqual(s(42, "A", "B", "C"), 3)
     s2 = ldmud.Closure(lwob, "testfun", lwob)
     self.assertEqual(s2, s)
     self.assertIn(s2, set((s, )))
Ejemplo n.º 4
0
 def testLWOEfun(self):
     lwob = ldmud.LWObject("/testob")
     s = ldmud.Closure(lwob, "this_object")
     self.assertIsNotNone(s)
     self.assertEqual(s(), lwob)
     s2 = ldmud.Closure(lwob, "this_object")
     self.assertEqual(s2, s)
     self.assertIn(s2, set((s, )))
Ejemplo n.º 5
0
 def testInitLoad(self):
     oldob = ldmud.efuns.find_object("/testob")
     if oldob:
         ldmud.efuns.destruct(oldob)
     lwob = ldmud.LWObject("/testob")
     self.assertIsNotNone(lwob)
     self.assertEqual(lwob.program_name, "/testob.c")
     self.assertIn("testob", repr(lwob))
Ejemplo n.º 6
0
 def setUp(self):
     self.ob = ldmud.Object("/testob")
     self.lwob = ldmud.LWObject("/testob")
Ejemplo n.º 7
0
 def testInitNonExisting(self):
     with self.assertRaises(RuntimeError):
         lwob = ldmud.LWObject("/imnotthere")
Ejemplo n.º 8
0
 def testInitLoaded(self):
     blueprint = ldmud.Object("/testob")
     lwob = ldmud.LWObject("/testob")
     self.assertIsNotNone(lwob)
     self.assertTrue(lwob)
     self.assertIn("testob", repr(lwob))