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


Python PythonPackageArchive.get_filenames方法代码示例

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


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

示例1: test_class_constructor_only_accepts_py_modules_not_pyc

# 需要导入模块: from c7n.mu import PythonPackageArchive [as 别名]
# 或者: from c7n.mu.PythonPackageArchive import get_filenames [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'))
开发者ID:JJediny,项目名称:cloud-custodian,代码行数:34,代码来源:test_mu.py

示例2: test_class_constructor_only_accepts_py_modules_not_pyc

# 需要导入模块: from c7n.mu import PythonPackageArchive [as 别名]
# 或者: from c7n.mu.PythonPackageArchive import get_filenames [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"))
开发者ID:jpoley,项目名称:cloud-custodian,代码行数:40,代码来源:test_mu.py

示例3: test_reverts_to_py_if_available

# 需要导入模块: from c7n.mu import PythonPackageArchive [as 别名]
# 或者: from c7n.mu.PythonPackageArchive import get_filenames [as 别名]
 def test_reverts_to_py_if_available(self):
     archive = PythonPackageArchive()
     py = self.py_with_pyc('foo.py')
     archive.add_py_file(py+'c')
     archive.close()
     self.assertEqual(archive.get_filenames(), ['foo.py'])
开发者ID:JJediny,项目名称:cloud-custodian,代码行数:8,代码来源:test_mu.py

示例4: test_can_add_py_file

# 需要导入模块: from c7n.mu import PythonPackageArchive [as 别名]
# 或者: from c7n.mu.PythonPackageArchive import get_filenames [as 别名]
 def test_can_add_py_file(self):
     archive = PythonPackageArchive()
     archive.add_py_file(self.py_with_pyc('foo.py'))
     archive.close()
     self.assertEqual(archive.get_filenames(), ['foo.py'])
开发者ID:JJediny,项目名称:cloud-custodian,代码行数:7,代码来源:test_mu.py


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