本文整理汇总了Python中astroid.manager.AstroidManager.zip_import_data方法的典型用法代码示例。如果您正苦于以下问题:Python AstroidManager.zip_import_data方法的具体用法?Python AstroidManager.zip_import_data怎么用?Python AstroidManager.zip_import_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astroid.manager.AstroidManager
的用法示例。
在下文中一共展示了AstroidManager.zip_import_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AstroidManagerTC
# 需要导入模块: from astroid.manager import AstroidManager [as 别名]
# 或者: from astroid.manager.AstroidManager import zip_import_data [as 别名]
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,
#.........这里部分代码省略.........
示例2: AstroidManagerTest
# 需要导入模块: from astroid.manager import AstroidManager [as 别名]
# 或者: from astroid.manager.AstroidManager import zip_import_data [as 别名]
class AstroidManagerTest(resources.SysPathSetup,
resources.AstroidCacheSetupMixin,
unittest.TestCase):
@property
def project(self):
return self.manager.project_from_files(
[resources.find('data')],
_silent_no_wrap, 'data',
black_list=['joined_strings.py'])
def setUp(self):
super(AstroidManagerTest, self).setUp()
self.manager = AstroidManager()
self.manager.clear_cache(self._builtins) # 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(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 = resources.find(archive)
sys.path.insert(0, archive_path)
try:
module = self.manager.ast_from_module_name('mypypa')
self.assertEqual(module.name, 'mypypa')
end = os.path.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(
os.path.sep.join(['data', os.path.normcase('MyPyPa-0.1.0-py2.5.egg')])
)
def test_ast_from_module_name_zip(self):
self._test_ast_from_zip(
os.path.sep.join(['data', os.path.normcase('MyPyPa-0.1.0-py2.5.zip')])
)
def test_zip_import_data(self):
"""check if zip_import_data works"""
filepath = resources.find('data/MyPyPa-0.1.0-py2.5.zip/mypypa')
#.........这里部分代码省略.........