Commit 16d32ac8 authored by Marius Wachtler's avatar Marius Wachtler

add reload() and a integration test for simplejson

parent 34288cf4
......@@ -1352,6 +1352,13 @@ static PyObject* builtin_print(PyObject* self, PyObject* args, PyObject* kwds) n
Py_RETURN_NONE;
}
static PyObject* builtin_reload(PyObject* self, PyObject* v) noexcept {
if (PyErr_WarnPy3k("In 3.x, reload() is renamed to imp.reload()", 1) < 0)
return NULL;
return PyImport_ReloadModule(v);
}
Box* getreversed(Box* o) {
static BoxedString* reversed_str = internStringImmortal("__reversed__");
......@@ -2159,6 +2166,7 @@ void setupBuiltins() {
static PyMethodDef builtin_methods[] = {
{ "print", (PyCFunction)builtin_print, METH_VARARGS | METH_KEYWORDS, print_doc },
{ "reload", builtin_reload, METH_O, reload_doc },
};
for (auto& md : builtin_methods) {
builtins_module->giveAttr(md.ml_name, new BoxedCApiFunction(&md, builtins_module, boxString("__builtin__")));
......
import os, sys, subprocess, shutil
sys.path.append(os.path.dirname(__file__) + "/../lib")
from test_helper import create_virtenv, run_test
ENV_NAME = "simplejson_test_env_" + os.path.basename(sys.executable)
SRC_DIR = os.path.abspath(os.path.join(ENV_NAME, "src"))
PYTHON_EXE = os.path.abspath(os.path.join(ENV_NAME, "bin", "python"))
def install_and_test_simplejson():
shutil.rmtree(SRC_DIR, ignore_errors=True)
os.makedirs(SRC_DIR)
url = "https://pypi.python.org/packages/source/s/simplejson/simplejson-2.6.2.tar.gz"
subprocess.check_call(["wget", url], cwd=SRC_DIR)
subprocess.check_call(["tar", "-zxf", "simplejson-2.6.2.tar.gz"], cwd=SRC_DIR)
SIMPLEJSON_DIR = os.path.abspath(os.path.join(SRC_DIR, "simplejson-2.6.2"))
subprocess.check_call([PYTHON_EXE, "setup.py", "build"], cwd=SIMPLEJSON_DIR)
subprocess.check_call([PYTHON_EXE, "setup.py", "install"], cwd=SIMPLEJSON_DIR)
expected = [{'ran': 170}]
run_test([PYTHON_EXE, "setup.py", "test"], cwd=SIMPLEJSON_DIR, expected=expected)
create_virtenv(ENV_NAME, None, force_create = True)
install_and_test_simplejson()
import os, sys
def delete_file(name):
try:
import os
os.remove(name)
except:
pass
def generate_file(ret):
with open("reload_test_target.py", "w") as f:
f.write("# skip-if: True\n")
f.write("# warning this file is generated by %s\n" % (__file__))
f.write("def foo(): return %s\n" % (ret))
# delete the pyc because cpython uses a timestamp for detecting if the pyc needs an update and we modify the file too fast
delete_file("reload_test_target.pyc")
os.chdir(os.path.dirname(os.path.realpath(__file__)))
generate_file(1)
import reload_test_target
print reload_test_target.foo()
generate_file(42)
reload(reload_test_target)
print reload_test_target.foo()
delete_file("reload_test_target.py")
delete_file("reload_test_target.pyc")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment