Example #1
0
    def test_imports(self):
        module = self.analyzer.analyze(SOURCE_ANALYZER_NATIVE)

        type1 = model._TypeData(None, 'sys', 'import sys', None)
        type2 = model._TypeData(None, 'os', 'import os', None)
        type3 = model._TypeData(None, 'sys.exit', 'import sys.exit', None)
        expected = {'sys': type1, 'os': type2, 'exit': type3}

        for imp in module.imports:
            data = expected[imp]
            impo = module.imports[imp]
            self.assertEqual(data.data_type, impo.data_type)
            self.assertEqual(data.line_content, impo.line_content)
    def test_imports(self):
        module = self.analyzer.analyze(SOURCE_ANALYZER_NATIVE)

        type1 = model._TypeData(None, 'sys', 'import sys', None)
        type2 = model._TypeData(None, 'os', 'import os', None)
        type3 = model._TypeData(None, 'sys.exit', 'import sys.exit', None)
        expected = {'sys': type1, 'os': type2, 'exit': type3}

        for imp in module.imports:
            data = expected[imp]
            impo = module.imports[imp]
            self.assertEqual(data.data_type, impo.data_type)
            self.assertEqual(data.line_content, impo.line_content)
    def test_var_attribute_assign(self):
        module = self.analyzer.analyze(SOURCE_LATE_RESOLUTION)

        type1 = model._TypeData(None, "os", "import os", None)
        type2 = model.Assign("p")
        type2.add_data(4, model.late_resolution, "p = os.path", _ast.Attribute)
        expected = {"os": type1}

        for imp in module.imports:
            data = expected[imp]
            impo = module.imports[imp]
            self.assertEqual(data.data_type, impo.data_type)
            self.assertEqual(data.line_content, impo.line_content)
            self.assertEqual(module.attributes["p"].data[0].lineno, type2.data[0].lineno)
            self.assertEqual(module.attributes["p"].data[0].data_type, type2.data[0].data_type)
            self.assertEqual(module.attributes["p"].data[0].operation, type2.data[0].operation)
            self.assertEqual(module.attributes["p"].data[0].line_content, type2.data[0].line_content)
    def test_var_attribute_assign(self):
        module = self.analyzer.analyze(SOURCE_LATE_RESOLUTION)

        type1 = model._TypeData(None, 'os', 'import os', None)
        type2 = model.Assign('p')
        type2.add_data(4, model.late_resolution, 'p = os.path', _ast.Attribute)
        expected = {'os': type1}

        for imp in module.imports:
            data = expected[imp]
            impo = module.imports[imp]
            self.assertEqual(data.data_type, impo.data_type)
            self.assertEqual(data.line_content, impo.line_content)
            self.assertEqual(module.attributes['p'].data[0].lineno,
                             type2.data[0].lineno)
            self.assertEqual(module.attributes['p'].data[0].data_type,
                             type2.data[0].data_type)
            self.assertEqual(module.attributes['p'].data[0].operation,
                             type2.data[0].operation)
            self.assertEqual(module.attributes['p'].data[0].line_content,
                             type2.data[0].line_content)
    def test_attrs_in_class_func_extended(self):
        module = self.analyzer.analyze(SOURCE_ANALYZER_NATIVE)

        clazz = module.classes['Test']
        func = clazz.functions['func_args']

        #Args
        args_names = ['var', 'inte', 'num', 'li', 'arggg', 'kwarggg']
        args_names.sort()
        func_args = func.args.keys()
        func_args.sort()
        self.assertEqual(func_args, args_names)
        #For: var
        type_var = model._TypeData(0, model.late_resolution, None, None)
        func_arg_obj = func.args['var']
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, 'var')
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertFalse(type_arg_func.is_native)
        #For: inte
        type_var = model._TypeData(0, model.late_resolution, None, None)
        func_arg_obj = func.args['inte']
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, 'inte')
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertFalse(type_arg_func.is_native)
        #For: num
        type_var = model._TypeData(0, '__builtin__.int', None, None)
        func_arg_obj = func.args['num']
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, 'num')
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertTrue(type_arg_func.is_native)
        #For: li
        type_var = model._TypeData(0, '__builtin__.str', None, None)
        func_arg_obj = func.args['li']
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, 'li')
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertTrue(type_arg_func.is_native)
        #For: arggg
        type_var = model._TypeData(0, '__builtin__.list', None, None)
        func_arg_obj = func.args['arggg']
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, 'arggg')
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertTrue(type_arg_func.is_native)
        #For: kwarggg
        type_var = model._TypeData(0, '__builtin__.dict', None, None)
        func_arg_obj = func.args['kwarggg']
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, 'kwarggg')
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertTrue(type_arg_func.is_native)

        #Decorators
        self.assertEqual(func.decorators, [])
        #Return Type
        self.assertEqual(func.return_type, [])
        #Attributes
        self.assertEqual(func.name, 'func_args')
        self.assertEqual(func.functions, {})
        #Assign
        result_a = func.attributes.keys()
        expected = ['nothing']
        self.assertEqual(result_a, expected)
        assign = func.attributes['nothing']
        self.assertEqual(assign.name, 'nothing')
        assign_test1 = model.Assign('nothing')
        assign_test1.add_data(0, '__builtin__.bool', "        nothing = False",
                              None)
        expected_data = assign_test1.data[0]
        result_data = assign.data[0]
        self.assertEqual(result_data.data_type, expected_data.data_type)
        self.assertEqual(result_data.line_content, expected_data.line_content)
        self.assertEqual(result_data.operation, expected_data.operation)
        self.assertTrue(result_data.is_native)
        self.assertFalse(result_data.from_import)
Example #6
0
    def test_attrs_in_class_func_extended(self):
        module = self.analyzer.analyze(SOURCE_ANALYZER_NATIVE)

        clazz = module.classes['Test']
        func = clazz.functions['func_args']

        #Args
        args_names = ['var', 'inte', 'num', 'li', 'arggg', 'kwarggg']
        args_names.sort()
        func_args = func.args.keys()
        func_args.sort()
        self.assertEqual(func_args, args_names)
        #For: var
        type_var = model._TypeData(0, model.late_resolution, None, None)
        func_arg_obj = func.args['var']
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, 'var')
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertFalse(type_arg_func.is_native)
        #For: inte
        type_var = model._TypeData(0, model.late_resolution, None, None)
        func_arg_obj = func.args['inte']
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, 'inte')
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertFalse(type_arg_func.is_native)
        #For: num
        type_var = model._TypeData(0, '__builtin__.int', None, None)
        func_arg_obj = func.args['num']
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, 'num')
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertTrue(type_arg_func.is_native)
        #For: li
        type_var = model._TypeData(0, '__builtin__.str', None, None)
        func_arg_obj = func.args['li']
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, 'li')
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertTrue(type_arg_func.is_native)
        #For: arggg
        type_var = model._TypeData(0, '__builtin__.list', None, None)
        func_arg_obj = func.args['arggg']
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, 'arggg')
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertTrue(type_arg_func.is_native)
        #For: kwarggg
        type_var = model._TypeData(0, '__builtin__.dict', None, None)
        func_arg_obj = func.args['kwarggg']
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, 'kwarggg')
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertTrue(type_arg_func.is_native)

        #Decorators
        self.assertEqual(func.decorators, [])
#        #Return Type
        self.assertEqual(func.return_type, [])
        #Attributes
        self.assertEqual(func.name, 'func_args')
        self.assertEqual(func.functions, {})
        #Assign
        result_a = func.attributes.keys()
        expected = ['nothing']
        self.assertEqual(result_a, expected)
        assign = func.attributes['nothing']
        self.assertEqual(assign.name, 'nothing')
        assign_test1 = model.Assign('nothing')
        assign_test1.add_data(0, '__builtin__.bool', "        nothing = False",
            None)
        expected_data = assign_test1.data[0]
        result_data = assign.data[0]
        self.assertEqual(result_data.data_type, expected_data.data_type)
        self.assertEqual(result_data.line_content, expected_data.line_content)
        self.assertEqual(result_data.operation, expected_data.operation)
        self.assertTrue(result_data.is_native)
        self.assertFalse(result_data.from_import)
Example #7
0
    def test_attrs_in_class_func_extended(self):
        module = self.analyzer.analyze(SOURCE_ANALYZER_NATIVE)

        clazz = module.classes["Test"]
        func = clazz.functions["func_args"]

        # Args
        args_names = ["var", "inte", "num", "li", "arggg", "kwarggg"]
        args_names.sort()
        func_args = func.args.keys()
        func_args.sort()
        self.assertEqual(func_args, args_names)
        # For: var
        type_var = model._TypeData(0, model.late_resolution, None, None)
        func_arg_obj = func.args["var"]
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, "var")
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertFalse(type_arg_func.is_native)
        # For: inte
        type_var = model._TypeData(0, model.late_resolution, None, None)
        func_arg_obj = func.args["inte"]
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, "inte")
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertFalse(type_arg_func.is_native)
        # For: num
        type_var = model._TypeData(0, "__builtin__.int", None, None)
        func_arg_obj = func.args["num"]
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, "num")
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertTrue(type_arg_func.is_native)
        # For: li
        type_var = model._TypeData(0, "__builtin__.str", None, None)
        func_arg_obj = func.args["li"]
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, "li")
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertTrue(type_arg_func.is_native)
        # For: arggg
        type_var = model._TypeData(0, "__builtin__.list", None, None)
        func_arg_obj = func.args["arggg"]
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, "arggg")
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertTrue(type_arg_func.is_native)
        # For: kwarggg
        type_var = model._TypeData(0, "__builtin__.dict", None, None)
        func_arg_obj = func.args["kwarggg"]
        type_arg_func = func_arg_obj.data[0]
        self.assertEqual(func_arg_obj.name, "kwarggg")
        self.assertEqual(type_arg_func.data_type, type_var.data_type)
        self.assertEqual(type_arg_func.line_content, type_var.line_content)
        self.assertEqual(type_arg_func.operation, type_var.operation)
        self.assertTrue(type_arg_func.is_native)

        # Decorators
        self.assertEqual(func.decorators, [])
        #        #Return Type
        self.assertEqual(func.return_type, [])
        # Attributes
        self.assertEqual(func.name, "func_args")
        self.assertEqual(func.functions, {})
        # Assign
        result_a = func.attributes.keys()
        expected = ["nothing"]
        self.assertEqual(result_a, expected)
        assign = func.attributes["nothing"]
        self.assertEqual(assign.name, "nothing")
        assign_test1 = model.Assign("nothing")
        assign_test1.add_data(0, "__builtin__.bool", "        nothing = False", None)
        expected_data = assign_test1.data[0]
        result_data = assign.data[0]
        self.assertEqual(result_data.data_type, expected_data.data_type)
        self.assertEqual(result_data.line_content, expected_data.line_content)
        self.assertEqual(result_data.operation, expected_data.operation)
        self.assertTrue(result_data.is_native)
        self.assertFalse(result_data.from_import)