本文整理汇总了Python中c7n.mu.PythonPackageArchive.get_reader方法的典型用法代码示例。如果您正苦于以下问题:Python PythonPackageArchive.get_reader方法的具体用法?Python PythonPackageArchive.get_reader怎么用?Python PythonPackageArchive.get_reader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c7n.mu.PythonPackageArchive
的用法示例。
在下文中一共展示了PythonPackageArchive.get_reader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_class_constructor_only_accepts_py_modules_not_pyc
# 需要导入模块: from c7n.mu import PythonPackageArchive [as 别名]
# 或者: from c7n.mu.PythonPackageArchive import get_reader [as 别名]
def test_class_constructor_only_accepts_py_modules_not_pyc(self):
# Create a module with both *.py and *.pyc.
self.py_with_pyc('foo.py')
# Create another with a *.pyc but no *.py behind it.
os.unlink(self.py_with_pyc('bar.py'))
# Now: *.py takes precedence over *.pyc ...
get = lambda name: os.path.basename(imp.find_module(name)[1])
self.assertTrue(get('foo'), 'foo.py')
try:
# ... and while *.pyc is importable ...
self.assertTrue(get('bar'), 'bar.pyc')
except ImportError:
# (except on PyPy)
# http://doc.pypy.org/en/latest/config/objspace.lonepycfiles.html
self.assertEqual(platform.python_implementation(), 'PyPy')
else:
# ... we refuse it.
with self.assertRaises(ValueError) as raised:
PythonPackageArchive('bar')
msg = raised.exception.args[0]
self.assertTrue(msg.startswith('We need a *.py source file instead'))
self.assertTrue(msg.endswith('bar.pyc'))
# We readily ignore a *.pyc if a *.py exists.
archive = PythonPackageArchive('foo')
archive.close()
self.assertEqual(archive.get_filenames(), ['foo.py'])
with archive.get_reader() as reader:
self.assertEqual('42', reader.read('foo.py'))
示例2: test_class_constructor_only_accepts_py_modules_not_pyc
# 需要导入模块: from c7n.mu import PythonPackageArchive [as 别名]
# 或者: from c7n.mu.PythonPackageArchive import get_reader [as 别名]
def test_class_constructor_only_accepts_py_modules_not_pyc(self):
# Create a module with both *.py and *.pyc.
self.py_with_pyc("foo.py")
# Create another with a *.pyc but no *.py behind it.
os.unlink(self.py_with_pyc("bar.py"))
# Now: *.py takes precedence over *.pyc ...
def get(name):
return os.path.basename(importlib.import_module(name).__file__)
self.assertTrue(get("foo"), "foo.py")
try:
# ... and while *.pyc is importable ...
self.assertTrue(get("bar"), "bar.pyc")
except ImportError:
try:
# (except on PyPy)
# http://doc.pypy.org/en/latest/config/objspace.lonepycfiles.html
self.assertEqual(platform.python_implementation(), "PyPy")
except AssertionError:
# (... aaaaaand Python 3)
self.assertEqual(platform.python_version_tuple()[0], "3")
else:
# ... we refuse it.
with self.assertRaises(ValueError) as raised:
PythonPackageArchive("bar")
msg = raised.exception.args[0]
self.assertTrue(msg.startswith("Could not find a *.py source file"))
self.assertTrue(msg.endswith("bar.pyc"))
# We readily ignore a *.pyc if a *.py exists.
archive = PythonPackageArchive("foo")
archive.close()
self.assertEqual(archive.get_filenames(), ["foo.py"])
with archive.get_reader() as reader:
self.assertEqual(b"42", reader.read("foo.py"))