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


Python PyZipFile.getinfo方法代码示例

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


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

示例1: ArchiveTestCase

# 需要导入模块: from zipfile import PyZipFile [as 别名]
# 或者: from zipfile.PyZipFile import getinfo [as 别名]
class ArchiveTestCase(TestCase):

    def setUp(self):
        tmp = tempfile.mkstemp(prefix=__name__)
        self.zipfile_path = tmp[1]
        self.zipfile = PyZipFile(self.zipfile_path, 'w')
        self.pj_root = os.path.abspath(
            os.path.dirname(os.path.dirname(os.path.dirname(__file__))))

    def tearDown(self):
        os.remove(self.zipfile_path)

    def test_create_zipfile(self):
        archive = Archive('test.zip')
        ok_(hasattr(archive.create_zipfile(), 'read'))
        with PyZipFile(archive._zippath, 'r', compression=ZIP_DEFLATED) as zipfile:
            ok_('lambda_function.pyc' in zipfile.namelist())
            ok_('.lamvery_secret.json' in zipfile.namelist())

    def test_create_zipfile_with_single_file(self):
        archive = Archive('test.zip', function_filename='lambda_function.py', single_file=True)
        archive.create_zipfile()
        with PyZipFile(archive._zippath, 'r', compression=ZIP_DEFLATED) as zipfile:
            ok_('lambda_function.py' in zipfile.namelist())
            ok_(not ('.lamvery_secret.json' in zipfile.namelist()))

    def test_archive_dir(self):
        archive = Archive('test.zip')
        archive._archive_dir(self.zipfile, self.pj_root)
        ok_(isinstance(self.zipfile.getinfo('setup.pyc'), zipfile.ZipInfo))

    def test_archive_file(self):
        archive = Archive('test.zip')
        archive._archive_file(
            self.zipfile, os.path.join(self.pj_root, 'setup.py'))
        ok_(isinstance(self.zipfile.getinfo('setup.pyc'), zipfile.ZipInfo))
        archive._archive_file(
            self.zipfile, os.path.join(self.pj_root, 'README.md'))
        ok_(isinstance(self.zipfile.getinfo('README.md'), zipfile.ZipInfo))

    @raises(KeyError)
    def test_archive_single_file_key_error(self):
        self._single_file = True
        archive = Archive('test.zip', single_file=True)
        archive._archive_file(
            self.zipfile, os.path.join(self.pj_root, 'setup.py'))
        ok_(isinstance(self.zipfile.getinfo('setup.pyc'), zipfile.ZipInfo))

    def test_archive_single_file(self):
        self._single_file = True
        archive = Archive('test.zip', single_file=True)
        archive._archive_file(
            self.zipfile, os.path.join(self.pj_root, 'setup.py'))
        ok_(isinstance(self.zipfile.getinfo('setup.py'), zipfile.ZipInfo))

    def test_is_exclude(self):
        archive = Archive('test.zip', exclude=['^\.lamvery\.yml$'])
        eq_(archive.is_exclude('foo.txt'), False)
        eq_(archive.is_exclude('.lamvery.yml'), True)

    def test_is_exclude_file(self):
        archive = Archive('test.zip')
        eq_(archive.is_exclude_file('test.zip'), True)
        eq_(archive.is_exclude_file('foo.txt'), False)
        archive.is_exclude = Mock(return_value=True)
        eq_(archive.is_exclude_file('foo.txt'), True)

    def test_is_exclude_dir(self):
        archive = Archive('test.zip')
        eq_(archive.is_exclude_dir('.git'), True)
        eq_(archive.is_exclude_dir('foo'), False)
        archive.is_exclude = Mock(return_value=True)
        eq_(archive.is_exclude_file('foo'), True)

    def test_is_source_file(self):
        archive = Archive('test.zip')
        eq_(archive.is_source_file('foo.py'), True)
        eq_(archive.is_source_file('foo.pyc'), True)
        eq_(archive.is_source_file('foo.php'), False)

    def test_get_paths(self):
        archive = Archive('test.zip')
        paths = archive._get_paths()
        ok_(os.path.join(self.pj_root, 'lamvery') in paths)

        archive = Archive('test.zip', no_libs=True)
        paths = archive._get_paths()
        ok_(os.path.join(self.pj_root, 'lamvery') in paths)
        ok_(os.path.join(self.pj_root, 'lambda_function.py') in paths)
        ok_(os.path.join(self.pj_root, 'lambda_function.pyc') in paths)
        ok_(os.path.join(self.pj_root, '.lamvery.yml') in paths)

        archive = Archive('test.zip', function_filename='test.py', single_file=True)
        paths = archive._get_paths()
        ok_(os.path.join(self.pj_root, 'test.py') in paths)
        ok_(not os.path.join(self.pj_root, 'lambda_function.pyc') in paths)
        ok_(not os.path.join(self.pj_root, '.lamvery.yml') in paths)

        del os.environ['VIRTUAL_ENV']
        archive = Archive('test.zip')
#.........这里部分代码省略.........
开发者ID:ijin,项目名称:lamvery,代码行数:103,代码来源:archive_test.py

示例2: BuilderTestCase

# 需要导入模块: from zipfile import PyZipFile [as 别名]
# 或者: from zipfile.PyZipFile import getinfo [as 别名]
class BuilderTestCase(TestCase):

    def setUp(self):
        tmp = tempfile.mkstemp(prefix=__name__)
        self.zipfile_path = tmp[1]
        self.zipfile = PyZipFile(self.zipfile_path, 'w')
        self.pj_root = os.path.abspath(
            os.path.dirname(os.path.dirname(os.path.dirname(__file__))))

    def tearDown(self):
        os.remove(self.zipfile_path)
        try:
            os.remove('test.json')
        except:
            pass

    def test_build(self):
        builder = Builder('test.zip')
        builder._runtime = RUNTIME_NODE_JS
        ok_(hasattr(builder.build(), 'read'))
        with PyZipFile(builder._zippath, 'r', compression=ZIP_DEFLATED) as zipfile:
            ok_('lambda_function.pyc' in zipfile.namelist())
            ok_('.lamvery_secret.json' in zipfile.namelist())

    def test_build_with_single_file(self):
        builder = Builder('test.zip', function_filename='lambda_function.py', single_file=True)
        builder.build()
        with PyZipFile(builder._zippath, 'r', compression=ZIP_DEFLATED) as zipfile:
            ok_('lambda_function.py' in zipfile.namelist())
            ok_(not ('.lamvery_secret.json' in zipfile.namelist()))

    def test_generate_json(self):
        builder = Builder('test.zip')
        builder._generate_json(
            JSON_FILE_NAME, {'foo': 2, 'bar': 3})
        data = json.load(open(JSON_FILE_NAME, 'r'))
        eq_(data.get('foo'), 2)

    def test_archive_dir(self):
        builder = Builder('test.zip')
        builder._archive_dir(self.zipfile, self.pj_root)
        ok_(isinstance(self.zipfile.getinfo('setup.pyc'), zipfile.ZipInfo))

    def test_archive_file(self):
        builder = Builder('test.zip')
        builder._archive_file(
            self.zipfile, os.path.join(self.pj_root, 'setup.py'))
        ok_(isinstance(self.zipfile.getinfo('setup.pyc'), zipfile.ZipInfo))
        builder._archive_file(
            self.zipfile, os.path.join(self.pj_root, 'README.md'))
        ok_(isinstance(self.zipfile.getinfo('README.md'), zipfile.ZipInfo))

    def test_archive_dist(self):
        builder = Builder('test.zip')
        builder._archive_dist(self.zipfile, 'lamvery.js')
        ok_(isinstance(self.zipfile.getinfo('lamvery.js'), zipfile.ZipInfo))

    @raises(KeyError)
    def test_archive_single_file_key_error(self):
        self._single_file = True
        builder = Builder('test.zip', single_file=True)
        builder._archive_file(
            self.zipfile, os.path.join(self.pj_root, 'setup.py'))
        ok_(isinstance(self.zipfile.getinfo('setup.pyc'), zipfile.ZipInfo))

    def test_archive_single_file(self):
        self._single_file = True
        builder = Builder('test.zip', single_file=True)
        builder._archive_file(
            self.zipfile, os.path.join(self.pj_root, 'setup.py'))
        ok_(isinstance(self.zipfile.getinfo('setup.py'), zipfile.ZipInfo))

    def test_is_exclude(self):
        builder = Builder('test.zip', exclude=['^\.lamvery\.yml$'])
        eq_(builder.is_exclude('foo.txt'), False)
        eq_(builder.is_exclude('.lamvery.yml'), True)

    def test_is_exclude_file(self):
        builder = Builder('test.zip')
        eq_(builder.is_exclude_file('test.zip'), True)
        eq_(builder.is_exclude_file('foo.txt'), False)
        builder.is_exclude = Mock(return_value=True)
        eq_(builder.is_exclude_file('foo.txt'), True)

    def test_is_exclude_dir(self):
        builder = Builder('test.zip')
        eq_(builder.is_exclude_dir('.git'), True)
        eq_(builder.is_exclude_dir('foo'), False)
        builder.is_exclude = Mock(return_value=True)
        eq_(builder.is_exclude_file('foo'), True)

    def test_is_source_file(self):
        builder = Builder('test.zip')
        eq_(builder.is_source_file('foo.py'), True)
        eq_(builder.is_source_file('foo.pyc'), True)
        eq_(builder.is_source_file('foo.php'), False)

    def test_get_paths(self):
        builder = Builder('test.zip')
        paths = builder._get_paths()
#.........这里部分代码省略.........
开发者ID:koppeft,项目名称:lamvery,代码行数:103,代码来源:build_test.py


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