Commit 5aad3631 authored by Boxiang Sun's avatar Boxiang Sun

add some tests

parent 09a5a8e0
......@@ -179,7 +179,7 @@ test_pydoc [unknown]
test_random long("invalid number")
test_repr complex.__hash__; some unknown issues
test_resource [unknown]
test_richcmp PyObject_Not
test_richcmp sefaults
test_rlcompleter [unknown]
test_runpy [unknown]
test_sax [unknown]
......
This diff is collapsed.
# script expects to find the numpy directory at the same level as the Pyston directory
import os
import sys
import subprocess
import shutil
"""
Using this test file.
We apply some patches on NumPy for some issues that we can't fix at the moment. The
patches are applied directly to the NumPy subrepository (test/lib/numpy). If you need,
you can make modifications in that folder directly for testing purposes. Just make sure
that everytime you do, run this script again, so that the contents of numpy_test_env_*
are updated (this is where the code and binaries that get tested are located).
Note that sometimes it can be a pain to run this script everytime you make a change,
as it does take a while. You can cd to the numpy_test_env_* directory and run the
binaries inside of that folder, which will be able to "see" the NumPy module. For example:
~/pyston/numpy_test_env_pyston_dbg$ gdb --args ./bin/python -c "import numpy as np; np.test()"
The /bin/python is the pyston executable so if you recompile pyston, you need to run this
script again to update it.
Currently this script is not running the NumPy tests since there are still crashes
happening. If you want to run the test, go to the bottom of the file and uncomment
the subprocess call to the test suite.
Some test cases in test/lib/numpy are commented out by the patch since they caused
a crash where the cause was not immediately obvious and I wanted to make progress. Those
will need to be uncommented at some point.
"""
def print_progress_header(text):
print "\n>>>"
print ">>> " + text + "..."
print ">>>"
ENV_NAME = "numpy_test_env_" + os.path.basename(sys.executable)
DEPENDENCIES = ["nose==1.3.7"]
if not os.path.exists(ENV_NAME) or os.stat(sys.executable).st_mtime > os.stat(ENV_NAME + "/bin/python").st_mtime:
print "Creating virtualenv to install testing dependencies..."
......@@ -14,6 +46,8 @@ if not os.path.exists(ENV_NAME) or os.stat(sys.executable).st_mtime > os.stat(EN
args = [sys.executable, VIRTUALENV_SCRIPT, "-p", sys.executable, ENV_NAME]
print "Running", args
subprocess.check_call(args)
subprocess.check_call([ENV_NAME + "/bin/pip", "install"] + DEPENDENCIES)
except:
print "Error occurred; trying to remove partially-created directory"
ei = sys.exc_info()
......@@ -28,10 +62,8 @@ PYTHON_EXE = os.path.abspath(ENV_NAME + "/bin/python")
CYTHON_DIR = os.path.abspath(os.path.join(SRC_DIR, "Cython-0.22"))
NUMPY_DIR = os.path.dirname(__file__) + "/../lib/numpy"
print "\n>>>"
print ">>> Setting up Cython..."
print_progress_header("Setting up Cython...")
if not os.path.exists(CYTHON_DIR):
print ">>>"
url = "http://cython.org/release/Cython-0.22.tar.gz"
subprocess.check_call(["wget", url], cwd=SRC_DIR)
......@@ -39,7 +71,7 @@ if not os.path.exists(CYTHON_DIR):
PATCH_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), "Cython_0001-Pyston-change-we-don-t-support-custom-traceback-entr.patch"))
subprocess.check_call(["patch", "-p1", "--input=" + PATCH_FILE], cwd=CYTHON_DIR)
print "Applied Cython patch"
print ">>> Applied Cython patch"
try:
......@@ -49,11 +81,8 @@ if not os.path.exists(CYTHON_DIR):
subprocess.check_call(["rm", "-rf", CYTHON_DIR])
else:
print ">>> Cython already installed."
print ">>>"
print "\n>>>"
print ">>> Patching NumPy..."
print ">>>"
print_progress_header("Patching NumPy...")
NUMPY_PATCH_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), "numpy_patch.patch"))
try:
cmd = ["patch", "-p1", "--forward", "-i", NUMPY_PATCH_FILE, "-d", NUMPY_DIR]
......@@ -63,14 +92,10 @@ except subprocess.CalledProcessError as e:
if "Reversed (or previously applied) patch detected! Skipping patch" not in e.output:
raise e
print "\n>>>"
print ">>> Setting up NumPy..."
print ">>>"
print_progress_header("Setting up NumPy...")
subprocess.check_call([PYTHON_EXE, "setup.py", "build"], cwd=NUMPY_DIR)
print "\n>>>"
print ">>> Installing NumPy..."
print ">>>"
print_progress_header("Installing NumPy...")
subprocess.check_call([PYTHON_EXE, "setup.py", "install"], cwd=NUMPY_DIR)
# From Wikipedia
......@@ -110,19 +135,20 @@ m = mandelbrot(complex(400),complex(400))
print m
"""
print "\n>>>"
print ">>> Running NumPy linear algebra test..."
print ">>>"
numpy_test = "import numpy as np; np.test(verbose=2)"
print_progress_header("Running NumPy linear algebra test...")
subprocess.check_call([PYTHON_EXE, "-c", script], cwd=CYTHON_DIR)
print "\n>>>"
print ">>> Running NumPy mandelbrot test..."
print ">>>"
print_progress_header("Running NumPy mandelbrot test...")
subprocess.check_call([PYTHON_EXE, "-c", mandelbrot], cwd=CYTHON_DIR)
print "\n>>>"
print ">>> Unpatching NumPy..."
print ">>>"
print_progress_header("Running NumPy test suite...")
# Currently we crash running the test suite. Uncomment for testing or
# when all the crashes are fixed.
# subprocess.check_call([PYTHON_EXE, "-c", numpy_test], cwd=CYTHON_DIR)
print_progress_header("Unpatching NumPy...")
cmd = ["patch", "-p1", "--forward", "-i", NUMPY_PATCH_FILE, "-R", "-d", NUMPY_DIR]
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
......
......@@ -19,3 +19,6 @@ test(3.0, 2)
test(3.0, 2.0)
test(3.0, -2.0)
test(-3.0, -2.0)
test(1.0 + 1.0j, 2)
test(1.0 + 1.0j, 2.0)
test(1.0 + 1.0j, 2.0j)
......@@ -112,6 +112,31 @@ def test_just_funcs(s, w):
t5 = s.rjust(w)
t6 = s.center(w)
try:
print s.ljust("a string")
except TypeError as e:
print e
try:
print s.rjust("a string")
except TypeError:
print e
try:
print s.center("a string")
except TypeError:
print e
try:
print s.ljust(10, 12345)
except TypeError:
print e
try:
print s.rjust(10, 12345)
except TypeError:
print e
try:
print s.center(10, 12345)
except TypeError:
print e
print t1, t1 == s, t1 is s, type(t1)
print t2, t2 == s, t2 is s, type(t2)
print t3, t3 == s, t3 is s, type(t3)
......
......@@ -95,6 +95,11 @@ print (1, 2, 3) + ()
print () + (1, 2, 3)
print (1, 2) + (2, 3)
try:
(1, 2) + "a"
except TypeError as e:
print e
## __new__
print tuple()
print tuple((1,3,7,42))
......
  • I add the tp_new in bool, complex, float, int, long. These part almost identical to this PR, so I just fetch it and apply my implementation. The other part is same as that PR.

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