本文整理汇总了Python中logilab.astng.manager.ASTNGManager.from_directory方法的典型用法代码示例。如果您正苦于以下问题:Python ASTNGManager.from_directory方法的具体用法?Python ASTNGManager.from_directory怎么用?Python ASTNGManager.from_directory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logilab.astng.manager.ASTNGManager
的用法示例。
在下文中一共展示了ASTNGManager.from_directory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ASTNGManagerTC
# 需要导入模块: from logilab.astng.manager import ASTNGManager [as 别名]
# 或者: from logilab.astng.manager.ASTNGManager import from_directory [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')