Exemple #1
0
    def test_02(self):
        logger = FoxylibLogger.func_level2logger(self.test_01, logging.DEBUG)

        a1 = A()
        a2 = A()
        self.assertTrue(ClassTool.cls_name2has_variable(A, "_h"))
        self.assertFalse(ObjectTool.obj_name2has_variable(a1, "_h"))

        A.put("0", "0")

        self.assertIn("0", A._h)
        self.assertIn("0", a1._h)

        a1._h = {}
        self.assertNotIn("0", a1._h)

        a1.put("1", "one")
        self.assertIn("1", A._h)
        self.assertNotIn("1", a1._h)

        a1._h["2"] = "two"
        # self.assertNotIn("2", A._h) # system-dependent ?
        self.assertIn("2", a1._h)

        self.assertIsNotNone(a1.lookup("2"))
Exemple #2
0
    def func2class_func_name_list(cls, f):
        l = []

        clazz = FunctionTool.func2cls(f)
        if clazz: l.append(ClassTool.cls2name(clazz))
        l.append(FunctionTool.func2name(f))

        return l
Exemple #3
0
    def test_03(self):
        hyp = smap(str, ClassTool.class2child_classes(A))
        ref = {
            "<class 'foxylib.tools.native.clazz.tests.test_class_tool.A.B'>",
            "<class 'foxylib.tools.native.clazz.tests.test_class_tool.A.B.C'>"
        }

        # pprint(hyp)
        self.assertEqual(hyp, ref)
Exemple #4
0
    def module2classes_within(cls, module):
        from foxylib.tools.native.clazz.class_tool import ClassTool

        member_list = inspect.getmembers(module, inspect.isclass)
        clazzes = filter(lambda x: x.__module__ == module.__name__,
                         map(ig(1), member_list))

        for clazz in clazzes:
            yield from ClassTool.class2child_classes(clazz)
            yield clazz
Exemple #5
0
 def entity_type(cls):
     return ClassTool.class2fullpath(cls)
Exemple #6
0
    def test_04(self):
        hyp = ClassTool.class2fullpath(A.B.C)
        ref = "foxylib.tools.native.clazz.tests.test_class_tool.A.B.C"

        # pprint(hyp)
        self.assertEqual(hyp, ref)
Exemple #7
0
 def class2entity_type(cls, clazz):
     return ClassTool.class2fullpath(clazz)