Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
16d32ac8
Commit
16d32ac8
authored
Feb 21, 2016
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add reload() and a integration test for simplejson
parent
34288cf4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
0 deletions
+63
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+8
-0
test/extra/simplejson_test.py
test/extra/simplejson_test.py
+26
-0
test/tests/reload_test.py
test/tests/reload_test.py
+29
-0
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
16d32ac8
...
...
@@ -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__"
)));
...
...
test/extra/simplejson_test.py
0 → 100644
View file @
16d32ac8
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
()
test/tests/reload_test.py
0 → 100644
View file @
16d32ac8
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"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment