Utils_Test.py 文件源码

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

项目:newsreap 作者: caronc 项目源码 文件源码
def test_load_pylib(self):
        """
        tests the dynamic loading of a python package

        """

        # A working dir
        work_dir = join(self.tmp_dir, 'Utils_Test.load_pylib')

        # Add a few modules
        assert(self.touch(join(work_dir, 'test01.py')))

        # A module we can attempt to load
        work_module = load_pylib('test01', join(work_dir, 'test01.py'))
        assert(work_module is not None)
        assert(work_module.__class__.__name__ == 'module')

        work_module = load_pylib(join(work_dir, 'test01.py'))
        assert(work_module is not None)
        assert(work_module.__class__.__name__ == 'module')

        # Now we'll protect our original directory
        chmod(work_dir, 0000)

        # We should fail to load our module
        work_module = load_pylib('test01', join(work_dir, 'test01.py'))
        assert(work_module is None)

        # Restore our permissions
        chmod(work_dir, 0700)

        # Protect our module
        chmod(join(work_dir, 'test01.py'), 0000)
        work_module = load_pylib('test01', join(work_dir, 'test01.py'))
        assert(work_module is None)

        # Restore our permissions
        chmod(join(work_dir, 'test01.py'), 0600)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号