Example #1
0
    def test_python_module_reload(self):
        search_path = abspath(join(FILES_DIR, 'imports'))
        pypath = abspath(join(search_path, 'A', 'a.py'))
        assert exists(pypath)

        pycpath = abspath(join(search_path, 'A', 'a.pyc'))
        pyopath = abspath(join(search_path, 'A', 'a.pyo'))
        if not exists(pycpath) or not exists(pyopath):
            compile_python_source(pypath)
            compile_python_source(pypath, optimization=True)
        assert exists(pycpath) and exists(pyopath)

        m = read_module_code(pypath, search_path=[search_path])
        old_imports = m.context['imports'][:]
        old_classdefs = m.context['classdefs'][:]

        for f in [pypath, pycpath, pyopath]:
            # ugly ...
            del m.context['imports'][:]
            del m.context['classdefs'][:]
            m.filename = f

            co = m.reload()
            self.assertNotNone(co)
            self.assertEqual(pypath, co.co_filename)
            self.assertEqual(old_imports, m.context['imports'])
            self.assertEqual(old_classdefs, m.context['classdefs'])
Example #2
0
    def setUp(self):
        self.notpypath = join(FILES_DIR, '000', '001')
        self.pypath  = join(FILES_DIR, 'python', 'a.py')
        self.pycpath = join(FILES_DIR, 'python', 'a.pyc')
        self.pyopath = join(FILES_DIR, 'python', 'a.pyo')

        assert exists(self.pypath)
        if not exists(self.pycpath) or not exists(self.pyopath):
            utils.compile_python_source(self.pypath)
            utils.compile_python_source(self.pypath, optimization=True)
        assert exists(self.pycpath)
        assert exists(self.pyopath)