work-around for ticket #691: look up unknown global names in builtins at runtime
[cython.git] / pyximport / test / test_reload.py
1 # reload seems to work for Python 2.3 but not 2.2. 
2 import time, os, sys
3 import test_pyximport
4
5 # debugging the 2.2 problem
6 if 1:
7     from distutils import sysconfig
8     try:
9         sysconfig.set_python_build()
10     except AttributeError:
11         pass
12     import pyxbuild
13     print pyxbuild.distutils.sysconfig == sysconfig
14
15 def test():
16     tempdir = test_pyximport.make_tempdir()
17     sys.path.append(tempdir)
18     hello_file = os.path.join(tempdir, "hello.pyx")
19     open(hello_file, "w").write("x = 1; print x; before = 'before'\n")
20     import hello
21         assert hello.x == 1
22
23     time.sleep(1) # sleep to make sure that new "hello.pyx" has later
24               # timestamp than object file.
25
26     open(hello_file, "w").write("x = 2; print x; after = 'after'\n")
27     reload(hello)
28     assert hello.x == 2, "Reload should work on Python 2.3 but not 2.2"
29     test_pyximport.remove_tempdir(tempdir)
30
31 if __name__=="__main__":
32     test()
33