test_runpy.py 文件源码

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

项目:zippy 作者: securesystemslab 项目源码 文件源码
def _check_module(self, depth):
        pkg_dir, mod_fname, mod_name = (
               self._make_pkg("x=1\n", depth))
        forget(mod_name)
        try:
            if verbose: print("Running from source:", mod_name)
            d1 = run_module(mod_name) # Read from source
            self.assertIn("x", d1)
            self.assertEqual(d1["x"], 1)
            del d1 # Ensure __loader__ entry doesn't keep file open
            __import__(mod_name)
            os.remove(mod_fname)
            make_legacy_pyc(mod_fname)
            unload(mod_name)  # In case loader caches paths
            if verbose: print("Running from compiled:", mod_name)
            d2 = run_module(mod_name) # Read from bytecode
            self.assertIn("x", d2)
            self.assertEqual(d2["x"], 1)
            del d2 # Ensure __loader__ entry doesn't keep file open
        finally:
            self._del_pkg(pkg_dir, depth, mod_name)
        if verbose: print("Module executed successfully")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号