test_zipfile.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:zippy 作者: securesystemslab 项目源码 文件源码
def test_write_python_directory(self):
        os.mkdir(TESTFN2)
        try:
            with open(os.path.join(TESTFN2, "mod1.py"), "w") as fp:
                fp.write("print(42)\n")

            with open(os.path.join(TESTFN2, "mod2.py"), "w") as fp:
                fp.write("print(42 * 42)\n")

            with open(os.path.join(TESTFN2, "mod2.txt"), "w") as fp:
                fp.write("bla bla bla\n")

            with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
                zipfp.writepy(TESTFN2)

                names = zipfp.namelist()
                self.assertTrue('mod1.pyc' in names or 'mod1.pyo' in names)
                self.assertTrue('mod2.pyc' in names or 'mod2.pyo' in names)
                self.assertNotIn('mod2.txt', names)

        finally:
            shutil.rmtree(TESTFN2)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号