當前位置: 首頁>>代碼示例>>Python>>正文


Python ASTNGManager.astng_from_class方法代碼示例

本文整理匯總了Python中logilab.astng.manager.ASTNGManager.astng_from_class方法的典型用法代碼示例。如果您正苦於以下問題:Python ASTNGManager.astng_from_class方法的具體用法?Python ASTNGManager.astng_from_class怎麽用?Python ASTNGManager.astng_from_class使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在logilab.astng.manager.ASTNGManager的用法示例。


在下文中一共展示了ASTNGManager.astng_from_class方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ASTNGManagerTC

# 需要導入模塊: from logilab.astng.manager import ASTNGManager [as 別名]
# 或者: from logilab.astng.manager.ASTNGManager import astng_from_class [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

示例2: ASTNGManagerTC

# 需要導入模塊: from logilab.astng.manager import ASTNGManager [as 別名]
# 或者: from logilab.astng.manager.ASTNGManager import astng_from_class [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_class [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_class方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。