Commit 0d5c9ae9 authored by Stefan Behnel's avatar Stefan Behnel

collection of regression tests (based on Greg's test suite)

parent be4e6108
VERSION = 0.9.6.3
PYTHON?=python
version:
@echo "Setting version to $(VERSION)"
......@@ -10,3 +11,9 @@ clean:
@rm -f *~ */*~ */*/*~
@rm -f core */core
@(cd Demos; $(MAKE) clean)
testclean:
rm -fr BUILD
test: testclean
${PYTHON} runtests.py
#!/usr/bin/python
import os, sys, unittest, doctest
from Cython.Distutils.build_ext import build_ext
from Cython.Distutils.extension import Extension
from distutils.dist import Distribution
distutils_distro = Distribution()
TEST_DIRS = ['compile', 'run']
TEST_RUN_DIRS = ['run']
INCLUDE_DIRS = os.getenv('INCLUDE', '').split(os.pathsep)
CFLAGS = os.getenv('CFLAGS', '').split()
class TestBuilder(object):
def __init__(self, rootdir, workdir):
self.rootdir = rootdir
self.workdir = workdir
def build_suite(self):
suite = unittest.TestSuite()
for filename in os.listdir(self.rootdir):
path = os.path.join(self.rootdir, filename)
if os.path.isdir(path) and filename in TEST_DIRS:
suite.addTest(
self.handle_directory(path, filename in TEST_RUN_DIRS))
return suite
def handle_directory(self, path, run_module):
suite = unittest.TestSuite()
for filename in os.listdir(path):
if not filename.endswith(".pyx"):
continue
module = filename[:-4]
suite.addTest(
CythonCompileTestCase(path, self.workdir, module))
if run_module:
suite.addTest(
CythonRunTestCase(self.workdir, module))
return suite
class CythonCompileTestCase(unittest.TestCase):
def __init__(self, directory, workdir, module):
self.directory = directory
self.workdir = workdir
self.module = module
unittest.TestCase.__init__(self)
def shortDescription(self):
return "compiling " + self.module
def runTest(self):
self.compile(self.directory, self.module, self.workdir)
def compile(self, directory, module, workdir):
build_extension = build_ext(distutils_distro)
build_extension.include_dirs = INCLUDE_DIRS[:]
build_extension.include_dirs.append(directory)
build_extension.finalize_options()
extension = Extension(
module,
sources = [os.path.join(directory, module + '.pyx')],
extra_compile_args = CFLAGS,
pyrex_c_in_temp = 1
)
build_extension.extensions = [extension]
build_extension.build_temp = workdir
build_extension.build_lib = workdir
build_extension.pyrex_c_in_temp = 1
build_extension.run()
class CythonRunTestCase(unittest.TestCase):
def __init__(self, rootdir, module):
self.rootdir, self.module = rootdir, module
unittest.TestCase.__init__(self)
def shortDescription(self):
return "running " + self.module
def runTest(self):
self.run(self)
def run(self, result=None):
sys.path.insert(0, self.rootdir)
if result is None: result = self.defaultTestResult()
try:
try:
doctest.DocTestSuite(self.module).run(result)
except ImportError:
result.startTest(self)
result.addFailure(self, sys.exc_info())
result.stopTest(self)
except Exception:
result.startTest(self)
result.addError(self, sys.exc_info())
result.stopTest(self)
if __name__ == '__main__':
# RUN ALL TESTS!
ROOTDIR = os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), 'tests')
WORKDIR = os.path.join(os.getcwd(), 'BUILD')
if not os.path.exists(WORKDIR):
os.makedirs(WORKDIR)
tests = TestBuilder(ROOTDIR, WORKDIR)
unittest.TextTestRunner(verbosity=2).run( tests.build_suite() )
cdef enum:
spam = 42
grail = 17
cdef int i
i = spam
cdef void f1(char *argv[]):
f2(argv)
cdef void f2(char *argv[]):
pass
cdef int i
cdef x
def f(a):
global i, x
i = 42
x = a
cdef void spam():
cdef long long L
cdef unsigned long long U
cdef object x
L = x
x = L
U = x
x = U
cdef int f() except -1:
cdef object x, y, z, w
cdef int i
x = abs(y)
delattr(x, 'spam')
x = dir(y)
x = divmod(y, z)
x = getattr(y, 'spam')
i = hasattr(y, 'spam')
i = hash(y)
x = intern(y)
i = isinstance(y, z)
i = issubclass(y, z)
x = iter(y)
i = len(x)
x = open(y, z)
x = pow(y, z, w)
x = reload(y)
x = repr(y)
setattr(x, y, z)
#i = typecheck(x, y)
#i = issubtype(x, y)
x = abs
cdef void foo():
cdef int bool, int1, int2, int3, int4
cdef object obj1, obj2, obj3, obj4
obj1 = 1
obj2 = 2
obj3 = 3
obj4 = 4
bool = int1 < int2 < int3
bool = obj1 < obj2 < obj3
bool = int1 < int2 < obj3
bool = obj1 < 2 < 3
bool = obj1 < 2 < 3 < 4
bool = int1 < (int2 == int3) < int4
cdef void foo():
cdef int i1, i2
cdef char c1, c2
cdef char *p1, *p2
i1 = i2
i1 = c1
p1 = p2
obj1 = i1
i1 = obj1
p1 = obj1
p1 = "spanish inquisition"
\ No newline at end of file
cdef extern class external.Spam:
pass
cdef void foo(object x):
pass
cdef void blarg(void *y, object z):
foo(<Spam>y)
foo(<Spam>z)
cdef extern int a "c_a", b "c_b"
cdef struct foo "c_foo":
int i "c_i"
ctypedef enum blarg "c_blarg":
x "c_x"
y "c_y" = 42
cdef double spam "c_spam" (int i, float f):
cdef double d "c_d"
cdef foo *p
global b
d = spam(a, f)
b = p.i
p.i = x
p.i = y
def f():
cdef int int1, int2, int3
cdef char char1
cdef long long1, long2
cdef float float1, float2
cdef double double1
int1 = int2 * int3
int1 = int2 / int3
long1 = long2 * char1
float1 = int1 * float2
double1 = float1 * int2
DEF NO = 0
DEF YES = 1
cdef void f():
cdef int i
IF YES:
i = 1
ELIF NO:
i = 2
ELSE:
i = 3
cdef void g():
cdef int i
IF NO:
i = 1
ELIF YES:
i = 2
ELSE:
i = 3
cdef void h():
cdef int i
IF NO:
i = 1
ELIF NO:
i = 2
ELSE:
i = 3
cdef void f():
cdef unsigned long x
cdef object y
x = y
y = x
def f(a, b):
global g
del g
del a[b]
del a[b][42]
del a.spam
del a.spam.eggs
cdef void spam():
cdef object x
del x[17:42]
cdef char *s
s = r'\"HT\"'
cdef void foo():
cdef int bool, int1, int2
cdef float float1, float2
cdef char *ptr1, *ptr2
cdef int *ptr3
bool = int1 == int2
bool = int1 <> int2
bool = int1 != int2
bool = float1 == float2
bool = ptr1 == ptr2
bool = int1 == float2
bool = ptr1 is ptr2
bool = ptr1 is not ptr2
\ No newline at end of file
cdef int blarg(int i):
pass
cdef void foo():
cdef float f
cdef int i
if blarg(<int> f):
pass
cdef char *f():
raise Exception
cdef extern int spam() except -1
cdef extern void grail() except *
cdef extern char *tomato() except? NULL
cdef void eggs():
cdef int i
cdef char *p
i = spam()
grail()
p = tomato()
cdef int spam() except -1:
eggs = 42
cdef class Spam:
cdef int tons
cdef void add_tons(self, int x):
self.tons = self.tons + x
cdef void eat(self):
self.tons = 0
cdef class SuperSpam(Spam):
cdef void add_tons(self, int x):
self.tons = self.tons + 2 * x
cdef class Grail:
def __add__(int x, float y):
pass
def __getslice__(self, i, j):
pass
def __setslice__(self, Py_ssize_t i, float j, x):
pass
cdef class Swallow:
pass
def f(Grail g):
cdef int i
cdef Swallow s
g = x
x = g
g = i
i = g
g = s
s = g
cdef class Foo:
def __delete__(self, i):
pass
cdef class Foo:
def __get__(self, i, c):
pass
cdef class Foo:
def __set__(self, i, v):
pass
cdef extern class external.Spam [object SpamObject]:
pass
ctypedef extern class external.Grail [object Grail]:
pass
cdef extern from "food.h":
class external.Tomato [object Tomato]:
pass
class external.Bicycle [object Bicycle]:
pass
cdef class Spam:
def __getitem__(self, x):
pass
cdef class Spam:
property eggs:
"Ova"
def __get__(self):
pass
def __set__(self, x):
pass
def __del__(self):
pass
cdef class Spam:
property eggs:
def __get__(self):
pass
cdef void tomato():
cdef Spam spam
cdef object lettuce
lettuce = spam.eggs
cdef class Spam:
cdef public char c
cdef public int i
cdef public long l
cdef public unsigned char uc
cdef public unsigned int ui
cdef public unsigned long ul
cdef public float f
cdef public double d
cdef public char *s
cdef public char a[42]
cdef public object o
cdef readonly int r
cdef readonly Spam e
cdef void spam():
cdef int i, j, k
for i from 0 <= i < 10:
j = k
else:
k = j
def f(x, y):
x = y
def z(a, b, c):
f(x = 42, y = "spam")
f(*a)
f(**b)
f(x = 42, **b)
f(a, *b)
f(a, x = 42, *b, **c)
\ No newline at end of file
cdef int f(a, b, c) except -1:
d = getattr3(a, b, c)
def f():
global a,b,c,d
a = b
c = d
ctypedef enum someenum_t:
ENUMVALUE_1
ENUMVALUE_2
cdef somefunction(someenum_t val):
if val == ENUMVALUE_1:
pass
def f(obj1, obj2, obj3):
cdef int int1, int2, int3
cdef float flt1, *ptr1
cdef int array1[42]
int1 = array1[int2]
flt1 = ptr1[int2]
array1[int1] = int2
ptr1[int1] = int2
obj1 = obj2[obj3]
int1 = array1[obj3]
obj1 = obj2[int3]
obj1[obj2] = obj3
array1[obj2] = int3
obj1[int2] = obj3
obj1[obj2] = 42
\ No newline at end of file
cdef class Parrot:
cdef void describe(self):
pass
cdef class Norwegian(Parrot):
cdef void describe(self):
Parrot.describe(self)
def f():
cdef int i
global mylist
del mylist[i]
return
cdef extern from "string.h":
void memcpy(void* des, void* src, int size)
cdef void f():
cdef float f1[3]
cdef float* f2
f2 = f1 + 1
memcpy(f1, f2, 1)
ctypedef enum foo:
FOO
cdef void func():
cdef foo x
map = [FOO]
x = map[0]
DEF STUFF = "Spam"
cdef void f():
IF STUFF == "Spam":
print "It works!"
ELSE:
print "Doesn't work"
cdef void foo():
cdef int bool, int1, int2
bool = int1 < int2
bool = int1 > int2
bool = int1 <= int2
bool = int1 >= int2
cdef loops():
cdef int k
for i from 0 <= i < 5:
for j from 0 <= j < 2:
k = i + j
cdef void spam():
eggs = None
cdef class Spam:
pass
cdef f(Spam s):
pass
cdef g():
f(None)
cdef extern class external.Spam [object Spam]: pass
cdef extern class external.Eggs [object Eggs]: pass
def ham(Spam s, Eggs e not None):
pass
if x: y = 42; z = 88
def f(): return 17
cdef class Spam:
pass
cdef void foo(object blarg):
pass
cdef void xyzzy():
cdef Spam spam
foo(spam)
def f(obj1, obj2, obj3):
cdef float flt1, flt2, flt3
flt1 = flt2 ** flt3
obj1 = obj2 ** obj3
cdef extern from "math.h":
double M_PI
#cdef unsigned long int n1
#n1 = 4293858116
cdef double pi
pi = 3.14159265358979323846
def main():
#print n1
print "%.18f" % M_PI
print "%.18f" % (<float> M_PI)
print "%.18f" % pi
def f(a, b, c):
#raise
raise a
raise "spam"
raise a, b
raise "spam", 42
raise a, b, c
raise "spam", 42, c()
def f(a):
a = f
a = g
def f(a, b, c, d, e, f, g, h, i):
a = b[c:d, e:f:g, ..., h, :i:]
cdef int i, j, k
i = 17; j = 42; k = i * j
if j > k: i = 88
else: i = 99; j = k
def spam():
raise Exception
cdef int grail() except -1:
raise Exception
def tomato():
spam()
grail()
def f():
cdef int i
try:
i = 1
raise x
i = 2
else:
i = 3
raise y
i = 4
def g():
cdef int i
try:
i = 1
raise x
i = 2
except a:
i = 3
else:
i = 4
raise y
i = 5
def test():
cdef int a,b
foo=(55,66)
a,b=foo
cdef int x
x = 0xFFFFFFFF
cdef public struct Foo:
int a, b
ctypedef struct Blarg:
int c, d
ctypedef public Foo Zax
cdef public class C[type C_Type, object C_Obj]:
pass
cdef public Zax *blarg
cdef api float f(Foo *x):
pass
cdef public void g(Blarg *x):
pass
cdef public api void h(Zax *x):
pass
typedef int blarg;
cdef extern from "altet1.h":
ctypedef int blarg
cdef blarg globvar
def flub(blarg bobble):
print bobble
globvar = 0
cdef swallow
def spam(w, int x = 42, y = "grail", z = swallow):
pass
cdef enum E:
z
cdef void f():
cdef int *p
cdef void *v
cdef int a[5]
cdef int i
cdef E e
p = a
v = a
p = a + i
p = a + e
p = i + a
p = e + a
p = a - i
p = a - e
cdef enum E:
spam, eggs
cdef E f() except spam:
pass
cdef extern from "stdint.h":
ctypedef int intptr_t
cdef int _is_aligned(void *ptr):
return ((<intptr_t>ptr) & ((sizeof(int))-1)) == 0
void c_func(unsigned char pixel);
cdef extern from "belchenko2.h":
void c_func(unsigned char pixel)
def f(unsigned char pixel):
c_func(pixel)
def g(signed char pixel):
c_func(pixel)
def h(char pixel):
c_func(pixel)
def f():
x = open("foo")
cdef void f():
cdef void (*p)()
p = <void(*)()>0
(<int (*)()>p)()
cdef extern int f()
cdef extern int __stdcall g()
cdef extern int __cdecl h()
cdef extern int (__stdcall *p)()
def f(obj, int i, float f, char *s1, char s2[]):
pass
\ No newline at end of file
cdef extern from *:
int spam
cdef enum Spam:
a
b, c,
d, e, f
g = 42
cdef void eggs():
cdef Spam s1, s2
cdef int i
s1 = s2
s1 = c
i = s1
\ No newline at end of file
cdef int i, j, k
cdef object a, b, x
for i from 0 <= i < 10:
pass
for i from 0 < i <= 10:
pass
for i from 10 >= i > 0:
pass
for i from 10 > i >= 0:
pass
for x from 0 <= x <= 10:
pass
for i from a <= i <= b:
pass
for i from k <= i <= j:
pass
for i from k * 42 <= i <= j / 18:
pass
while j:
for i from 0 <= i <= 10:
continue
break
else:
continue
break
class Swallow:
def spam(w, int x = 42, y = "grail", z = swallow):
pass
cdef extern void spam(char *s)
cdef struct Grail:
char silly[42]
cdef void eggs():
cdef char silly[42]
cdef Grail grail
spam(silly)
spam(grail.silly)
cdef void f():
cdef void *p
cdef char *q
p = q
cdef extern (int *[42]) spam, grail, swallow
cdef (int (*)()) brian():
pass
cdef enum Grail:
k = 42
cdef enum Spam:
a = -1
b = 2 + 3
c = 42 > 17
d = k
cdef class Tst:
cdef foo,
ctypedef struct Foo:
int blarg
cdef Foo f():
blarg = 1 + 2
DEF CHAR = c'x'
DEF INT = 42
DEF LONG = 666L
DEF FLOAT = 17.88
DEF STR = "spam"
DEF TUPLE = (1, 2, "buckle my shoe")
DEF TWO = TUPLE[1]
DEF FIVE = TWO + 3
cdef void f():
cdef char c
cdef int i
cdef long l
cdef float f
cdef char *s
cdef int two
cdef int five
c = CHAR
i = INT
l = LONG
f = FLOAT
s = STR
two = TWO
five = FIVE
\ No newline at end of file
ctypedef int *IntPtr
ctypedef unsigned long ULong
cdef extern IntPtr spam
cdef extern ULong grail
ctypedef class spam:
pass
cdef spam s
s = None
ctypedef enum parrot_state:
alive = 1
dead = 2
cdef parrot_state polly
polly = dead
ctypedef struct order:
int spam
int eggs
cdef order order1
order1.spam = 7
order1.eggs = 2
ctypedef union pet:
int cat
float dog
cdef pet sam
sam.cat = 1
sam.dog = 2.7
cdef extern short int s
cdef extern long int l
cdef extern long long ll
cdef extern long double ld
cdef struct Sandwich:
int i
char *s
cdef class Tomato:
cdef float danger
cdef class Tomato:
def eject(self):
pass
cdef extern Sandwich butty
cdef Tomato supertom
supertom = None
cdef extern char *cp
cdef extern char *cpa[5]
cdef extern int (*ifnpa[5])()
cdef extern char *(*cpfnpa[5])()
cdef extern int (*ifnp)()
cdef extern int (*iap)[5]
cdef extern int ifn()
cdef extern char *cpfn()
cdef extern int (*iapfn())[5]
cdef extern char *(*cpapfn())[5]
cdef extern int fnargfn(int ())
cdef void f():
cdef void *p
global ifnp, cpa
ifnp = <int (*)()>p
cdef char *g():
pass
cdef class Spam:
pass
cdef Spam foo():
return blarg()
#cdef Spam grail
#grail = blarg()
#return grail
cdef object blarg():
pass
cdef void f():
try:
pass
finally:
pass
cdef enum E:
a
cdef enum G:
b
cdef void f():
cdef E e
cdef G g
cdef int i, j
cdef float f, h
i = j | e
i = e | j
i = j ^ e
i = j & e
i = j << e
i = j >> e
i = j + e
i = j - e
i = j * e
i = j / e
i = j % e
# f = j ** e # Cython prohibits this
i = e + g
f = h
cdef class C:
cdef f(self):
pass
cdef void f():
"This is a pseudo doc string."
# Spurious gcc3.3 warnings about incompatible pointer
# types passed to C method
# Ordering of declarations in C code is important
cdef class C
cdef class D(C)
cdef class E
cdef class C:
cdef void a(self):
pass
cdef class D(C):
cdef void m(self, E e):
pass
cdef class E:
pass
cdef void f(D d, E e):
d.m(e)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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