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


Python ASTNGManager.astng_from_module_name方法代码示例

本文整理汇总了Python中logilab.astng.manager.ASTNGManager.astng_from_module_name方法的典型用法代码示例。如果您正苦于以下问题:Python ASTNGManager.astng_from_module_name方法的具体用法?Python ASTNGManager.astng_from_module_name怎么用?Python ASTNGManager.astng_from_module_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在logilab.astng.manager.ASTNGManager的用法示例。


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

示例1: test_borg

# 需要导入模块: from logilab.astng.manager import ASTNGManager [as 别名]
# 或者: from logilab.astng.manager.ASTNGManager import astng_from_module_name [as 别名]
    def test_borg(self):
        """test that the ASTNGManager is really a borg, i.e. that two different
        instances has same cache"""
        first_manager = ASTNGManager()
        built = first_manager.astng_from_module_name(BUILTINS_NAME)

        second_manager = ASTNGManager()
        second_built = first_manager.astng_from_module_name(BUILTINS_NAME)
        self.assertTrue(built is second_built)
开发者ID:OFFIS-Automation,项目名称:Framework,代码行数:11,代码来源:unittest_manager.py

示例2: ASTNGManagerTC

# 需要导入模块: from logilab.astng.manager import ASTNGManager [as 别名]
# 或者: from logilab.astng.manager.ASTNGManager import astng_from_module_name [as 别名]
class ASTNGManagerTC(unittest.TestCase):
    def setUp(self):
        self.manager = ASTNGManager(borg=False)
        
    def test_astng_from_module(self):
        astng = self.manager.astng_from_module(unittest)
        self.assertEquals(astng.pure_python, True)
        import time
        astng = self.manager.astng_from_module(time)
        self.assertEquals(astng.pure_python, False)
        
    def test_astng_from_class(self):
        astng = self.manager.astng_from_class(file)
        self.assertEquals(astng.name, 'file')
        self.assertEquals(astng.parent.frame().name, '__builtin__')

        astng = self.manager.astng_from_class(object)
        self.assertEquals(astng.name, 'object')
        self.assertEquals(astng.parent.frame().name, '__builtin__')
        self.failUnless('__setattr__' in astng)
        
    def _test_astng_from_zip(self, archive):
        origpath = sys.path[:]
        sys.modules.pop('mypypa', None)
        sys.path.insert(0, join(dirname(__file__), 'data', archive))
        try:
            module = self.manager.astng_from_module_name('mypypa')
            self.assertEquals(module.name, 'mypypa')
            self.failUnless(module.file.endswith('%s/mypypa' % archive),
                            module.file)
        finally:
            sys.path = origpath

    def test_astng_from_module_name_egg(self):
        self._test_astng_from_zip('MyPyPa-0.1.0-py2.5.egg')

    def test_astng_from_module_name_zip(self):
        self._test_astng_from_zip('MyPyPa-0.1.0-py2.5.zip')            
        
    def test_from_directory(self):
        obj = self.manager.from_directory('data')
        self.assertEquals(obj.name, 'data')
        self.assertEquals(obj.path, join(os.getcwd(), 'data'))
        
    def test_package_node(self):
        obj = self.manager.from_directory('data')
        expected_short = ['SSL1', '__init__', 'all', 'appl', 'format', 'module', 'module2',
                          'noendingnewline', 'nonregr', 'notall']
        expected_long = ['SSL1', 'data', 'data.all', 'appl', 'data.format', 'data.module',
                         'data.module2', 'data.noendingnewline', 'data.nonregr',
                         'data.notall']
        self.assertEquals(obj.keys(), expected_short)
        self.assertEquals([m.name for m in obj.values()], expected_long)
        self.assertEquals([m for m in list(obj)], expected_short)
        self.assertEquals([(name, m.name) for name, m in obj.items()],
                          zip(expected_short, expected_long))
        self.assertEquals([(name, m.name) for name, m in obj.items()],
                          zip(expected_short, expected_long))
        
        self.assertEquals('module' in obj, True)
        self.assertEquals(obj.has_key('module'), True)
        self.assertEquals(obj.get('module').name, 'data.module')
        self.assertEquals(obj['module'].name, 'data.module')
        self.assertEquals(obj.get('whatever'), None)
        self.assertEquals(obj.fullname(), 'data')
开发者ID:AndryulE,项目名称:kitsune,代码行数:67,代码来源:unittest_manager.py

示例3: ASTNGManagerTC

# 需要导入模块: from logilab.astng.manager import ASTNGManager [as 别名]
# 或者: from logilab.astng.manager.ASTNGManager import astng_from_module_name [as 别名]
class ASTNGManagerTC(TestCase):
    def setUp(self):
        self.manager = ASTNGManager()
        self.manager.astng_cache.clear()

    def test_astng_from_module(self):
        import unittest
        astng = self.manager.astng_from_module(unittest)
        self.assertEqual(astng.pure_python, True)
        import time
        astng = self.manager.astng_from_module(time)
        self.assertEqual(astng.pure_python, False)

    def test_astng_from_class(self):
        astng = self.manager.astng_from_class(int)
        self.assertEqual(astng.name, 'int')
        self.assertEqual(astng.parent.frame().name, BUILTINS_NAME)

        astng = self.manager.astng_from_class(object)
        self.assertEqual(astng.name, 'object')
        self.assertEqual(astng.parent.frame().name, BUILTINS_NAME)
        self.failUnless('__setattr__' in astng)

    def _test_astng_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.astng_from_module_name('mypypa')
            self.assertEqual(module.name, 'mypypa')
            self.failUnless(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.astng_cache:
                del self.manager.astng_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_astng_from_module_name_egg(self):
        self._test_astng_from_zip('MyPyPa-0.1.0-py2.5.egg')

    def test_astng_from_module_name_zip(self):
        self._test_astng_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.all',
                    'data.appl', 'data.appl.myConnection', '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.astng_from_module_name('__main__')
      self.assertEqual(obj.name, '__main__')
      self.assertEqual(list(obj.items()), [])
开发者ID:OFFIS-Automation,项目名称:Framework,代码行数:69,代码来源:unittest_manager.py

示例4: ASTNGManagerTC

# 需要导入模块: from logilab.astng.manager import ASTNGManager [as 别名]
# 或者: from logilab.astng.manager.ASTNGManager import astng_from_module_name [as 别名]
class ASTNGManagerTC(TestCase):
    def setUp(self):
        self.manager = ASTNGManager()
        self.manager.astng_cache.clear()

    def test_astng_from_module(self):
        import unittest

        astng = self.manager.astng_from_module(unittest)
        self.assertEqual(astng.pure_python, True)
        import time

        astng = self.manager.astng_from_module(time)
        self.assertEqual(astng.pure_python, False)

    def test_astng_from_class(self):
        astng = self.manager.astng_from_class(int)
        self.assertEqual(astng.name, "int")
        self.assertEqual(astng.parent.frame().name, BUILTINS_NAME)

        astng = self.manager.astng_from_class(object)
        self.assertEqual(astng.name, "object")
        self.assertEqual(astng.parent.frame().name, BUILTINS_NAME)
        self.failUnless("__setattr__" in astng)

    def _test_astng_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.astng_from_module_name("mypypa")
            self.assertEqual(module.name, "mypypa")
            self.failUnless(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.astng_cache:
                del self.manager.astng_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_astng_from_module_name_egg(self):
        self._test_astng_from_zip("MyPyPa-0.1.0-py2.5.egg")

    def test_astng_from_module_name_zip(self):
        self._test_astng_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.all",
            "data.appl",
            "data.appl.myConnection",
            "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.astng_from_module_name("__main__")
        self.assertEqual(obj.name, "__main__")
        self.assertEqual(obj.items(), [])
开发者ID:tomfitzhenry,项目名称:modern-python-example,代码行数:81,代码来源:unittest_manager.py


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