当前位置: 首页>>代码示例>>Python>>正文


Python manager.AstroidManager类代码示例

本文整理汇总了Python中astroid.manager.AstroidManager的典型用法代码示例。如果您正苦于以下问题:Python AstroidManager类的具体用法?Python AstroidManager怎么用?Python AstroidManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AstroidManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_borg

    def test_borg(self):
        """test that the AstroidManager is really a borg, i.e. that two different
        instances has same cache"""
        first_manager = AstroidManager()
        built = first_manager.ast_from_module_name(BUILTINS)

        second_manager = AstroidManager()
        second_built = first_manager.ast_from_module_name(BUILTINS)
        self.assertIs(built, second_built)
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:9,代码来源:unittest_manager.py

示例2: brainless_manager

 def brainless_manager(self):
     manager = AstroidManager()
     # avoid caching into the AstroidManager borg since we get problems
     # with other tests :
     manager.__dict__ = {}
     manager.astroid_cache = {}
     manager._mod_file_cache = {}
     manager.transforms = {}
     return manager
开发者ID:cbonzi,项目名称:nupic-darwin64,代码行数:9,代码来源:unittest_regrtest.py

示例3: parse

    def parse(self):
        manager = AstroidManager()
        project = manager.project_from_files(list(self.file_paths),
                            func_wrapper=astroid_ignore_modname_wrapper)

        # First collect all definitions (e.g. module X, function foo) before
        # trying to relate one definition with another (e.g. module X depends on
        # module Y)
        DefsVisitor(self.modelers).visit(project)
        RelationsVisitor(self.modelers).visit(project)
开发者ID:qdamian,项目名称:dissect,代码行数:10,代码来源:source_code_parser.py

示例4: PyreverseAdapter

class PyreverseAdapter(Run):
    """Integrate with pyreverse by overriding its CLI Run class to
    create diagram definitions that can be passed to a writer."""

    def __init__(self, args):
        ConfigurationMixIn.__init__(self, usage=__doc__)
        insert_default_options()
        self.manager = AstroidManager()
        self.register_options_provider(self.manager)
        self.args = self.load_command_line_configuration()

    def run(self):
        if not self.args:
            print(self.help())
            return
        # Insert current working directory to the python path to recognize
        # dependencies to local modules even if cwd is not in the PYTHONPATH.
        sys.path.insert(0, os.getcwd())
        try:
            project = self.manager.project_from_files(self.args)
            linker = Linker(project, tag=True)
            handler = DiadefsHandler(self.config)
            diadefs = handler.get_diadefs(project, linker)
        finally:
            sys.path.pop(0)

        return diadefs
开发者ID:cb109,项目名称:pyplantuml,代码行数:27,代码来源:adapter.py

示例5: __init__

 def __init__(self, args):
     ConfigurationMixIn.__init__(self, usage=__doc__)
     insert_default_options()
     self.manager = AstroidManager()
     self.register_options_provider(self.manager)
     args = self.load_command_line_configuration()
     sys.exit(self.run(args))
开发者ID:JacobNinja,项目名称:exercism-analysis,代码行数:7,代码来源:main.py

示例6: Run

class Run(ConfigurationMixIn):
    """base class providing common behaviour for pyreverse commands"""

    options = OPTIONS

    def __init__(self, args):
        ConfigurationMixIn.__init__(self, usage=__doc__)
        insert_default_options()
        self.manager = AstroidManager()
        self.register_options_provider(self.manager)
        args = self.load_command_line_configuration()
        sys.exit(self.run(args))

    def run(self, args):
        """checking arguments and run project"""
        if not args:
            print self.help()
            return 1
        # insert current working directory to the python path to recognize
        # dependencies to local modules even if cwd is not in the PYTHONPATH
        sys.path.insert(0, os.getcwd())
        try:
            project = self.manager.project_from_files(args)
            linker = Linker(project, tag=True)
            handler = DiadefsHandler(self.config)
            diadefs = handler.get_diadefs(project, linker)
        finally:
            sys.path.pop(0)

        if self.config.output_format == "vcg":
            writer.VCGWriter(self.config).write(diadefs)
        else:
            writer.DotWriter(self.config).write(diadefs)
        return 0
开发者ID:JacobNinja,项目名称:exercism-analysis,代码行数:34,代码来源:main.py

示例7: brainless_manager

 def brainless_manager(self):
     manager = AstroidManager()
     # avoid caching into the AstroidManager borg since we get problems
     # with other tests :
     manager.__dict__ = {}
     manager._failed_import_hooks = []
     manager.astroid_cache = {}
     manager._mod_file_cache = {}
     manager._transform = transforms.TransformVisitor()
     manager.clear_cache() # trigger proper bootstraping
     return manager
开发者ID:esabelhaus,项目名称:pylintr,代码行数:11,代码来源:unittest_regrtest.py

示例8: __init__

 def __init__(self, args,out_file='test.xml'):
     ConfigurationMixIn.__init__(self, usage=__doc__)
     IdGeneratorMixIn.__init__(self)
     insert_default_options()
     self.manager = AstroidManager()
     self.register_options_provider(self.manager)
     args = self.load_command_line_configuration()
     self._out_file = out_file
     self.run(args)
     pass
开发者ID:exbluesbreaker,项目名称:csu-code-analysis,代码行数:10,代码来源:builder.py

示例9: PylintUCRBuilder

class PylintUCRBuilder(ConfigurationMixIn,IdGeneratorMixIn):
    
    options = OPTIONS
    _out_file = None
    
    def __init__(self, args,out_file='test.xml'):
        ConfigurationMixIn.__init__(self, usage=__doc__)
        IdGeneratorMixIn.__init__(self)
        insert_default_options()
        self.manager = AstroidManager()
        self.register_options_provider(self.manager)
        args = self.load_command_line_configuration()
        self._out_file = out_file
        self.run(args)
        pass
    
    def run(self, args):
        project = self.manager.project_from_files(args)
        linker = Linker(project, tag=True)
        handler = DiadefsHandler(self.config)
        diadefs = handler.get_diadefs(project, linker)
        root = etree.Element("Classes")
        classes = None
        for diagram in diadefs:
            if diagram.TYPE == 'class':
                classes = diagram
        class_map = {}
        class_nodes = []
        for c in classes.objects:
            ''' First pass - id generation '''
            c_id = str(self.generate_id())
            node = etree.Element("Class",name=c.title,id=c_id,label=c.node.root().name)
            if class_map.has_key(c.title):
                print "Duplicate class name - ",c.title
            else:
                class_map[c.title] = c_id
            root.append(node)
            class_nodes.append((c,node))
        attr_num = 0
        typed_attrs = 0
        for c, node in class_nodes:
            ''' Second pass - linking '''
            attr_num += len(c.attrs)
            for a in c.attrs:
                a_data =  [w.strip() for w in a.split(':')]
                found_attr = False
                attr_node = etree.Element('Attr',name=a_data[0])
                if (len(a_data) > 1):
                    types = [w.strip() for w in a_data[1].split(',')]
                    for t in types:
                        if class_map.has_key(t):
                            print "InnerType!"
                            found_attr = True
                            type_node = etree.Element('CommonType', id=class_map[a_data[1]],name=a_data[1])
                            attr_node.append(type_node)
                if found_attr:
                    typed_attrs += 1
                node.append(attr_node)
            #mapper[obj] = node
        print "Numbers of all attributes in project: ", attr_num
        print "Numbers of typed attributes in project: ", typed_attrs
        print "Percentage: ", typed_attrs*1.0/attr_num
        print "Writing ", self._out_file
        f = open(self._out_file,'w')
        f.write(etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=True))
        f.close()
开发者ID:exbluesbreaker,项目名称:csu-code-analysis,代码行数:66,代码来源:builder.py

示例10: setUp

 def setUp(self):
     self.manager = AstroidManager()
     self.manager.astroid_cache.clear()
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:3,代码来源:unittest_manager.py

示例11: AstroidManagerTC

class AstroidManagerTC(TestCase):
    def setUp(self):
        self.manager = AstroidManager()
        self.manager.astroid_cache.clear()

    def test_ast_from_module(self):
        import unittest

        astroid = self.manager.ast_from_module(unittest)
        self.assertEqual(astroid.pure_python, True)
        import time

        astroid = self.manager.ast_from_module(time)
        self.assertEqual(astroid.pure_python, False)

    def test_ast_from_class(self):
        astroid = self.manager.ast_from_class(int)
        self.assertEqual(astroid.name, "int")
        self.assertEqual(astroid.parent.frame().name, BUILTINS)

        astroid = self.manager.ast_from_class(object)
        self.assertEqual(astroid.name, "object")
        self.assertEqual(astroid.parent.frame().name, BUILTINS)
        self.assertIn("__setattr__", astroid)

    def _test_ast_from_zip(self, archive):
        origpath = sys.path[:]
        sys.modules.pop("mypypa", None)
        archive_path = join(DATA, archive)
        sys.path.insert(0, archive_path)
        try:
            module = self.manager.ast_from_module_name("mypypa")
            self.assertEqual(module.name, "mypypa")
            self.assertTrue(module.file.endswith("%s/mypypa" % archive), module.file)
        finally:
            # remove the module, else after importing egg, we don't get the zip
            if "mypypa" in self.manager.astroid_cache:
                del self.manager.astroid_cache["mypypa"]
                del self.manager._mod_file_cache[("mypypa", None)]
            if archive_path in sys.path_importer_cache:
                del sys.path_importer_cache[archive_path]
            sys.path = origpath

    def test_ast_from_module_name_egg(self):
        self._test_ast_from_zip("MyPyPa-0.1.0-py2.5.egg")

    def test_ast_from_module_name_zip(self):
        self._test_ast_from_zip("MyPyPa-0.1.0-py2.5.zip")

    def test_from_directory(self):
        obj = self.manager.project_from_files([DATA], _silent_no_wrap, "data")
        self.assertEqual(obj.name, "data")
        self.assertEqual(obj.path, join(DATA, "__init__.py"))

    def test_project_node(self):
        obj = self.manager.project_from_files([DATA], _silent_no_wrap, "data")
        expected = set(
            ["SSL1", "__init__", "all", "appl", "format", "module", "module2", "noendingnewline", "nonregr", "notall"]
        )
        expected = [
            "data",
            "data.SSL1",
            "data.SSL1.Connection1",
            "data.absimport",
            "data.all",
            "data.appl",
            "data.appl.myConnection",
            "data.email",
            "data.format",
            "data.module",
            "data.module2",
            "data.noendingnewline",
            "data.nonregr",
            "data.notall",
        ]
        self.assertListEqual(sorted(k for k in list(obj.keys())), expected)

    def test_do_not_expose_main(self):
        obj = self.manager.ast_from_module_name("__main__")
        self.assertEqual(obj.name, "__main__")
        self.assertEqual(list(obj.items()), [])
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:81,代码来源:unittest_manager.py

示例12: AstroidManagerTC

class AstroidManagerTC(TestCase):
    def setUp(self):
        self.manager = AstroidManager()
        self.manager.astroid_cache.clear()

    def test_ast_from_module(self):
        import unittest
        astroid = self.manager.ast_from_module(unittest)
        self.assertEqual(astroid.pure_python, True)
        import time
        astroid = self.manager.ast_from_module(time)
        self.assertEqual(astroid.pure_python, False)

    def test_ast_from_class(self):
        astroid = self.manager.ast_from_class(int)
        self.assertEqual(astroid.name, 'int')
        self.assertEqual(astroid.parent.frame().name, BUILTINS)

        astroid = self.manager.ast_from_class(object)
        self.assertEqual(astroid.name, 'object')
        self.assertEqual(astroid.parent.frame().name, BUILTINS)
        self.assertIn('__setattr__', astroid)

    def _test_ast_from_zip(self, archive):
        origpath = sys.path[:]
        sys.modules.pop('mypypa', None)
        archive_path = join(DATA, archive)
        sys.path.insert(0, archive_path)
        try:
            module = self.manager.ast_from_module_name('mypypa')
            self.assertEqual(module.name, 'mypypa')
            self.assertTrue(module.file.endswith('%s/mypypa' % archive),
                            module.file)
        finally:
            # remove the module, else after importing egg, we don't get the zip
            if 'mypypa' in self.manager.astroid_cache:
                del self.manager.astroid_cache['mypypa']
                del self.manager._mod_file_cache[('mypypa', None)]
            if archive_path in sys.path_importer_cache:
                del sys.path_importer_cache[archive_path]
            sys.path = origpath

    def test_ast_from_module_name_egg(self):
        self._test_ast_from_zip('MyPyPa-0.1.0-py2.5.egg')

    def test_ast_from_module_name_zip(self):
        self._test_ast_from_zip('MyPyPa-0.1.0-py2.5.zip')

    def test_from_directory(self):
        obj = self.manager.project_from_files([DATA], _silent_no_wrap, 'data')
        self.assertEqual(obj.name, 'data')
        self.assertEqual(obj.path, join(DATA, '__init__.py'))

    def test_project_node(self):
        obj = self.manager.project_from_files([DATA], _silent_no_wrap, 'data')
        expected = set(['SSL1', '__init__', 'all', 'appl', 'format', 'module',
                        'module2', 'noendingnewline', 'nonregr', 'notall'])
        expected = ['data', 'data.SSL1', 'data.SSL1.Connection1',
                    'data.absimport', 'data.all',
                    'data.appl', 'data.appl.myConnection', 'data.email', 'data.format',
                    'data.module', 'data.module2', 'data.noendingnewline',
                    'data.nonregr', 'data.notall']
        self.assertListEqual(sorted(k for k in obj.keys()), expected)

    def test_do_not_expose_main(self):
      obj = self.manager.ast_from_module_name('__main__')
      self.assertEqual(obj.name, '__main__')
      self.assertEqual(obj.items(), [])
开发者ID:Launcelot,项目名称:nupic-linux64,代码行数:68,代码来源:unittest_manager.py

示例13: setUp

 def setUp(self):
     self.manager = AstroidManager()
     self.manager.clear_cache() # take care of borg
     self.builder = AstroidBuilder(self.manager)
开发者ID:Titulacion-Sistemas,项目名称:PythonTitulacion-EV,代码行数:4,代码来源:unittest_python3.py

示例14: Python3TC

class Python3TC(unittest.TestCase):
    def setUp(self):
        self.manager = AstroidManager()
        self.manager.clear_cache() # take care of borg
        self.builder = AstroidBuilder(self.manager)

    @require_version('3.0')
    def test_starred_notation(self):
        astroid = self.builder.string_build("*a, b = [1, 2, 3]", 'test', 'test')

        # Get the star node
        node = next(next(next(astroid.get_children()).get_children()).get_children())

        self.assertTrue(isinstance(node.ass_type(), Assign))

    @require_version('3.3')
    def test_yield_from(self):
        body = dedent("""
        def func():
            yield from iter([1, 2])
        """)
        astroid = self.builder.string_build(body)
        func = astroid.body[0]
        self.assertIsInstance(func, Function)
        yieldfrom_stmt = func.body[0]

        self.assertIsInstance(yieldfrom_stmt, Discard)
        self.assertIsInstance(yieldfrom_stmt.value, YieldFrom)
        self.assertEqual(yieldfrom_stmt.as_string(),
                         'yield from iter([1, 2])')

    @require_version('3.3')
    def test_yield_from_is_generator(self):
        body = dedent("""
        def func():
            yield from iter([1, 2])
        """)
        astroid = self.builder.string_build(body)
        func = astroid.body[0]
        self.assertIsInstance(func, Function)
        self.assertTrue(func.is_generator())

    @require_version('3.3')
    def test_yield_from_as_string(self):
        body = dedent("""
        def func():
            yield from iter([1, 2])
            value = yield from other()
        """)
        astroid = self.builder.string_build(body)
        func = astroid.body[0]
        self.assertEqual(func.as_string().strip(), body.strip())

    # metaclass tests

    @require_version('3.0')
    def test_simple_metaclass(self):
        astroid = self.builder.string_build("class Test(metaclass=type): pass")
        klass = astroid.body[0]

        metaclass = klass.metaclass()
        self.assertIsInstance(metaclass, Class)
        self.assertEqual(metaclass.name, 'type')

    @require_version('3.0')
    def test_metaclass_error(self):
        astroid = self.builder.string_build("class Test(metaclass=typ): pass")
        klass = astroid.body[0]
        self.assertFalse(klass.metaclass())

    @require_version('3.0')
    def test_metaclass_imported(self):
        astroid = self.builder.string_build(dedent("""
        from abc import ABCMeta 
        class Test(metaclass=ABCMeta): pass"""))
        klass = astroid.body[1]

        metaclass = klass.metaclass()
        self.assertIsInstance(metaclass, Class)
        self.assertEqual(metaclass.name, 'ABCMeta')

    @require_version('3.0')
    def test_as_string(self):
        body = dedent("""
        from abc import ABCMeta 
        class Test(metaclass=ABCMeta): pass""")
        astroid = self.builder.string_build(body)
        klass = astroid.body[1]

        self.assertEqual(klass.as_string(),
                         '\n\nclass Test(metaclass=ABCMeta):\n    pass\n')

    @require_version('3.0')
    def test_old_syntax_works(self):
        astroid = self.builder.string_build(dedent("""
        class Test:
            __metaclass__ = type
        class SubTest(Test): pass
        """))
        klass = astroid['SubTest']
#.........这里部分代码省略.........
开发者ID:Titulacion-Sistemas,项目名称:PythonTitulacion-EV,代码行数:101,代码来源:unittest_python3.py

示例15: AstroidManagerTC

class AstroidManagerTC(TestCase):
    def setUp(self):
        self.manager = AstroidManager()
        self.manager.clear_cache() # take care of borg

    def test_ast_from_file(self):
        """check if the method return a good astroid object"""
        import unittest
        filepath = unittest.__file__
        astroid = self.manager.ast_from_file(filepath)
        self.assertEqual(astroid.name, 'unittest')
        self.assertIn('unittest', self.manager.astroid_cache)

    def test_ast_from_file_cache(self):
        """check if the cache works"""
        import unittest
        filepath = unittest.__file__
        self.manager.ast_from_file(filepath)
        astroid = self.manager.ast_from_file('unhandledName', 'unittest')
        self.assertEqual(astroid.name, 'unittest')
        self.assertIn('unittest', self.manager.astroid_cache)

    def test_ast_from_file_astro_builder(self):
        """check if the source is at True, AstroidBuilder build a good astroid"""
        import unittest
        filepath = unittest.__file__
        astroid = self.manager.ast_from_file(filepath, None, True, True)
        self.assertEqual(astroid.name, 'unittest')
        self.assertIn('unittest', self.manager.astroid_cache)

    def test_ast_from_file_name_astro_builder_exception(self):
        """check if an exception is thrown if we give a wrong filepath"""
        self.assertRaises(AstroidBuildingException, self.manager.ast_from_file, 'unhandledName')

    def test_do_not_expose_main(self):
        obj = self.manager.ast_from_module_name('__main__')
        self.assertEqual(obj.name, '__main__')
        self.assertEqual(list(obj.items()), [])

    def test_ast_from_module_name(self):
        """check if the ast_from_module_name method return a good astroid"""
        astroid = self.manager.ast_from_module_name('unittest')
        self.assertEqual(astroid.name, 'unittest')
        self.assertIn('unittest', self.manager.astroid_cache)

    def test_ast_from_module_name_not_python_source(self):
        """check if the ast_from_module_name method return a good astroid with a no python source module"""
        astroid = self.manager.ast_from_module_name('time')
        self.assertEqual(astroid.name, 'time')
        self.assertIn('time', self.manager.astroid_cache)
        self.assertEqual(astroid.pure_python, False)

    def test_ast_from_module_name_astro_builder_exception(self):
        """check if the method raise an exception if we give a wrong module"""
        self.assertRaises(AstroidBuildingException, self.manager.ast_from_module_name, 'unhandledModule')

    def _test_ast_from_zip(self, archive):
        origpath = sys.path[:]
        sys.modules.pop('mypypa', None)
        archive_path = join(DATA, archive)
        sys.path.insert(0, archive_path)
        try:
            module = self.manager.ast_from_module_name('mypypa')
            self.assertEqual(module.name, 'mypypa')
            end = join(archive, 'mypypa')
            self.assertTrue(module.file.endswith(end),
                            "%s doesn't endswith %s" % (module.file, end))
        finally:
            # remove the module, else after importing egg, we don't get the zip
            if 'mypypa' in self.manager.astroid_cache:
                del self.manager.astroid_cache['mypypa']
                del self.manager._mod_file_cache[('mypypa', None)]
            if archive_path in sys.path_importer_cache:
                del sys.path_importer_cache[archive_path]
            sys.path = origpath

    def test_ast_from_module_name_egg(self):
        self._test_ast_from_zip('MyPyPa-0.1.0-py2.5.egg')

    def test_ast_from_module_name_zip(self):
        self._test_ast_from_zip('MyPyPa-0.1.0-py2.5.zip')

    def test_zip_import_data(self):
        """check if zip_import_data works"""
        filepath = self.datapath('MyPyPa-0.1.0-py2.5.zip/mypypa')
        astroid = self.manager.zip_import_data(filepath)
        self.assertEqual(astroid.name, 'mypypa')

    def test_zip_import_data_without_zipimport(self):
        """check if zip_import_data return None without zipimport"""
        self.assertEqual(self.manager.zip_import_data('path'), None)

    def test_file_from_module(self):
        """check if the unittest filepath is equals to the result of the method"""
        import unittest
        if PY3K:
            unittest_file = unittest.__file__
        else:
            unittest_file = unittest.__file__[:-1]
        self.assertEqual(unittest_file,
#.........这里部分代码省略.........
开发者ID:Stronhold,项目名称:Mario,代码行数:101,代码来源:unittest_manager.py


注:本文中的astroid.manager.AstroidManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。