diff options
Diffstat (limited to 'numpy/distutils/tests')
23 files changed, 301 insertions, 0 deletions
diff --git a/numpy/distutils/tests/f2py_ext/__init__.py b/numpy/distutils/tests/f2py_ext/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/numpy/distutils/tests/f2py_ext/__init__.py diff --git a/numpy/distutils/tests/f2py_ext/setup.py b/numpy/distutils/tests/f2py_ext/setup.py new file mode 100644 index 000000000..6b786a97e --- /dev/null +++ b/numpy/distutils/tests/f2py_ext/setup.py @@ -0,0 +1,12 @@ + +import os +from scipy.distutils.core import setup, Extension + +ext = Extension('f2py_ext.fib2',['src/fib2.pyf','src/fib1.f']) + +setup( + name = 'f2py_ext', + ext_modules = [ext], + packages = ['f2py_ext.tests','f2py_ext'], + package_dir = {'f2py_ext':'.'}) + diff --git a/numpy/distutils/tests/f2py_ext/src/fib1.f b/numpy/distutils/tests/f2py_ext/src/fib1.f new file mode 100644 index 000000000..cfbb1eea0 --- /dev/null +++ b/numpy/distutils/tests/f2py_ext/src/fib1.f @@ -0,0 +1,18 @@ +C FILE: FIB1.F + SUBROUTINE FIB(A,N) +C +C CALCULATE FIRST N FIBONACCI NUMBERS +C + INTEGER N + REAL*8 A(N) + DO I=1,N + IF (I.EQ.1) THEN + A(I) = 0.0D0 + ELSEIF (I.EQ.2) THEN + A(I) = 1.0D0 + ELSE + A(I) = A(I-1) + A(I-2) + ENDIF + ENDDO + END +C END FILE FIB1.F diff --git a/numpy/distutils/tests/f2py_ext/src/fib2.pyf b/numpy/distutils/tests/f2py_ext/src/fib2.pyf new file mode 100644 index 000000000..90a8cf00c --- /dev/null +++ b/numpy/distutils/tests/f2py_ext/src/fib2.pyf @@ -0,0 +1,9 @@ +! -*- f90 -*- +python module fib2 + interface + subroutine fib(a,n) + real*8 dimension(n),intent(out),depend(n) :: a + integer intent(in) :: n + end subroutine fib + end interface +end python module fib2 diff --git a/numpy/distutils/tests/f2py_ext/tests/test_fib2.py b/numpy/distutils/tests/f2py_ext/tests/test_fib2.py new file mode 100644 index 000000000..633e2ba20 --- /dev/null +++ b/numpy/distutils/tests/f2py_ext/tests/test_fib2.py @@ -0,0 +1,13 @@ +import sys +from scipy.base.testing import * +set_package_path() +from f2py_ext import fib2 +del sys.path[0] + +class test_fib2(ScipyTestCase): + + def check_fib(self): + assert_array_equal(fib2.fib(6),[0,1,1,2,3,5]) + +if __name__ == "__main__": + ScipyTest(fib2).run() diff --git a/numpy/distutils/tests/f2py_f90_ext/__init__.py b/numpy/distutils/tests/f2py_f90_ext/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/numpy/distutils/tests/f2py_f90_ext/__init__.py diff --git a/numpy/distutils/tests/f2py_f90_ext/include/body.f90 b/numpy/distutils/tests/f2py_f90_ext/include/body.f90 new file mode 100644 index 000000000..90b44e29d --- /dev/null +++ b/numpy/distutils/tests/f2py_f90_ext/include/body.f90 @@ -0,0 +1,5 @@ + subroutine bar13(a) + !f2py intent(out) a + integer a + a = 13 + end subroutine bar13 diff --git a/numpy/distutils/tests/f2py_f90_ext/setup.py b/numpy/distutils/tests/f2py_f90_ext/setup.py new file mode 100644 index 000000000..f3ab45045 --- /dev/null +++ b/numpy/distutils/tests/f2py_f90_ext/setup.py @@ -0,0 +1,16 @@ + +import os +from scipy_distutils.core import setup, Extension + +package = 'f2py_f90_ext' + +ext = Extension(package+'.foo',['src/foo_free.f90'], + include_dirs=['include'], + f2py_options=['--include_paths','include']) + +setup( + name = package, + ext_modules = [ext], + packages = [package+'.tests',package], + package_dir = {package:'.'}) + diff --git a/numpy/distutils/tests/f2py_f90_ext/src/foo_free.f90 b/numpy/distutils/tests/f2py_f90_ext/src/foo_free.f90 new file mode 100644 index 000000000..c7713be59 --- /dev/null +++ b/numpy/distutils/tests/f2py_f90_ext/src/foo_free.f90 @@ -0,0 +1,6 @@ +module foo_free +contains + +include "body.f90" + +end module foo_free diff --git a/numpy/distutils/tests/f2py_f90_ext/tests/test_foo.py b/numpy/distutils/tests/f2py_f90_ext/tests/test_foo.py new file mode 100644 index 000000000..544f94ab4 --- /dev/null +++ b/numpy/distutils/tests/f2py_f90_ext/tests/test_foo.py @@ -0,0 +1,13 @@ +import sys +from scipy.base.testing import * +set_package_path() +from f2py_f90_ext import foo +del sys.path[0] + +class test_foo(ScipyTestCase): + + def check_foo_free(self): + assert_equal(foo.foo_free.bar13(),13) + +if __name__ == "__main__": + ScipyTest().run() diff --git a/numpy/distutils/tests/gen_ext/__init__.py b/numpy/distutils/tests/gen_ext/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/numpy/distutils/tests/gen_ext/__init__.py diff --git a/numpy/distutils/tests/gen_ext/setup.py b/numpy/distutils/tests/gen_ext/setup.py new file mode 100644 index 000000000..7b12c1f55 --- /dev/null +++ b/numpy/distutils/tests/gen_ext/setup.py @@ -0,0 +1,47 @@ + +import os +from scipy.distutils.core import setup, Extension +from distutils.dep_util import newer + +fib3_f = ''' +C FILE: FIB3.F + SUBROUTINE FIB(A,N) +C +C CALCULATE FIRST N FIBONACCI NUMBERS +C + INTEGER N + REAL*8 A(N) +Cf2py intent(in) n +Cf2py intent(out) a +Cf2py depend(n) a + DO I=1,N + IF (I.EQ.1) THEN + A(I) = 0.0D0 + ELSEIF (I.EQ.2) THEN + A(I) = 1.0D0 + ELSE + A(I) = A(I-1) + A(I-2) + ENDIF + ENDDO + END +C END FILE FIB3.F +''' + +package = 'gen_ext' + +def source_func(ext, src_dir): + source = os.path.join(src_dir,'fib3.f') + if newer(__file__, source): + f = open(source,'w') + f.write(fib3_f) + f.close() + return [source] + +ext = Extension(package+'.fib3',[source_func]) + +setup( + name = package, + ext_modules = [ext], + packages = [package+'.tests',package], + package_dir = {package:'.'}) + diff --git a/numpy/distutils/tests/gen_ext/tests/test_fib3.py b/numpy/distutils/tests/gen_ext/tests/test_fib3.py new file mode 100644 index 000000000..c8ee2441c --- /dev/null +++ b/numpy/distutils/tests/gen_ext/tests/test_fib3.py @@ -0,0 +1,13 @@ +import sys +from scipy.base.testing import * +set_package_path() +from gen_ext import fib3 +del sys.path[0] + +class test_fib3(ScipyTestCase): + + def check_fib(self): + assert_array_equal(fib3.fib(6),[0,1,1,2,3,5]) + +if __name__ == "__main__": + ScipyTest().run() diff --git a/numpy/distutils/tests/swig_ext/__init__.py b/numpy/distutils/tests/swig_ext/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/numpy/distutils/tests/swig_ext/__init__.py diff --git a/numpy/distutils/tests/swig_ext/setup.py b/numpy/distutils/tests/swig_ext/setup.py new file mode 100644 index 000000000..b6fe8eed4 --- /dev/null +++ b/numpy/distutils/tests/swig_ext/setup.py @@ -0,0 +1,14 @@ + +import os +from scipy_distutils.core import setup, Extension + +ext_c = Extension('swig_ext._example',['src/example.i','src/example.c']) +ext_cpp = Extension('swig_ext._example2',['src/zoo.i','src/zoo.cc'], + depends=['src/zoo.h'],include_dirs=['src']) + +setup( + name = 'swig_ext', + ext_modules = [ext_c,ext_cpp], + packages = ['swig_ext.tests','swig_ext'], + package_dir = {'swig_ext':'.'}) + diff --git a/numpy/distutils/tests/swig_ext/src/example.c b/numpy/distutils/tests/swig_ext/src/example.c new file mode 100644 index 000000000..7bbb661dd --- /dev/null +++ b/numpy/distutils/tests/swig_ext/src/example.c @@ -0,0 +1,14 @@ +/* File : example.c */ + +double My_variable = 3.0; + +/* Compute factorial of n */ +int fact(int n) { + if (n <= 1) return 1; + else return n*fact(n-1); +} + +/* Compute n mod m */ +int my_mod(int n, int m) { + return(n % m); +} diff --git a/numpy/distutils/tests/swig_ext/src/example.i b/numpy/distutils/tests/swig_ext/src/example.i new file mode 100644 index 000000000..6d61062b3 --- /dev/null +++ b/numpy/distutils/tests/swig_ext/src/example.i @@ -0,0 +1,11 @@ +/* -*- c -*- */ + +/* File : example.i */ +%module example +%{ +/* Put headers and other declarations here */ +%} + +extern double My_variable; +extern int fact(int); +extern int my_mod(int n, int m); diff --git a/numpy/distutils/tests/swig_ext/src/zoo.cc b/numpy/distutils/tests/swig_ext/src/zoo.cc new file mode 100644 index 000000000..0a643d1e5 --- /dev/null +++ b/numpy/distutils/tests/swig_ext/src/zoo.cc @@ -0,0 +1,23 @@ +#include "zoo.h" +#include <cstdio> +#include <cstring> + +Zoo::Zoo() +{ + n = 0; +} + +void Zoo::shut_up(char *animal) +{ + if (n < 10) { + strcpy(animals[n], animal); + n++; + } +} + +void Zoo::display() +{ + int i; + for(i = 0; i < n; i++) + printf("%s\n", animals[i]); +} diff --git a/numpy/distutils/tests/swig_ext/src/zoo.h b/numpy/distutils/tests/swig_ext/src/zoo.h new file mode 100644 index 000000000..cb26e6cef --- /dev/null +++ b/numpy/distutils/tests/swig_ext/src/zoo.h @@ -0,0 +1,9 @@ + +class Zoo{ + int n; + char animals[10][50]; +public: + Zoo(); + void shut_up(char *animal); + void display(); +}; diff --git a/numpy/distutils/tests/swig_ext/src/zoo.i b/numpy/distutils/tests/swig_ext/src/zoo.i new file mode 100644 index 000000000..a029c03e8 --- /dev/null +++ b/numpy/distutils/tests/swig_ext/src/zoo.i @@ -0,0 +1,10 @@ +// -*- c++ -*- +// Example copied from http://linuxgazette.net/issue49/pramode.html + +%module example2 + +%{ +#include "zoo.h" +%} + +%include "zoo.h" diff --git a/numpy/distutils/tests/swig_ext/tests/test_example.py b/numpy/distutils/tests/swig_ext/tests/test_example.py new file mode 100644 index 000000000..baedec642 --- /dev/null +++ b/numpy/distutils/tests/swig_ext/tests/test_example.py @@ -0,0 +1,18 @@ +import sys +from scipy.base.testing import * +set_package_path() +from swig_ext import example +del sys.path[0] + +class test_example(ScipyTestCase): + + def check_fact(self): + assert_equal(example.fact(10),3628800) + + def check_cvar(self): + assert_equal(example.cvar.My_variable,3.0) + example.cvar.My_variable = 5 + assert_equal(example.cvar.My_variable,5.0) + +if __name__ == "__main__": + ScipyTest().run() diff --git a/numpy/distutils/tests/swig_ext/tests/test_example2.py b/numpy/distutils/tests/swig_ext/tests/test_example2.py new file mode 100644 index 000000000..af066be68 --- /dev/null +++ b/numpy/distutils/tests/swig_ext/tests/test_example2.py @@ -0,0 +1,17 @@ +import sys +from scipy.base.testing import * +set_package_path() +from swig_ext import example2 +del sys.path[0] + +class test_example2(ScipyTestCase): + + def check_zoo(self): + z = example2.Zoo() + z.shut_up('Tiger') + z.shut_up('Lion') + z.display() + + +if __name__ == "__main__": + ScipyTest().run() diff --git a/numpy/distutils/tests/test_misc_util.py b/numpy/distutils/tests/test_misc_util.py new file mode 100644 index 000000000..4ca21ea13 --- /dev/null +++ b/numpy/distutils/tests/test_misc_util.py @@ -0,0 +1,33 @@ +import sys +from scipy.testing import * +from scipy.distutils.misc_util import appendpath +from os.path import join, sep + +ajoin = lambda *paths: join(*((sep,)+paths)) + +class test_appendpath(ScipyTestCase): + + def check_1(self): + assert_equal(appendpath('prefix','name'),join('prefix','name')) + assert_equal(appendpath('/prefix','name'),ajoin('prefix','name')) + assert_equal(appendpath('/prefix','/name'),ajoin('prefix','name')) + assert_equal(appendpath('prefix','/name'),join('prefix','name')) + + def check_2(self): + assert_equal(appendpath('prefix/sub','name'), + join('prefix','sub','name')) + assert_equal(appendpath('prefix/sub','sup/name'), + join('prefix','sub','sup','name')) + assert_equal(appendpath('/prefix/sub','/prefix/name'), + ajoin('prefix','sub','name')) + + def check_3(self): + assert_equal(appendpath('/prefix/sub','/prefix/sup/name'), + ajoin('prefix','sub','sup','name')) + assert_equal(appendpath('/prefix/sub/sub2','/prefix/sup/sup2/name'), + ajoin('prefix','sub','sub2','sup','sup2','name')) + assert_equal(appendpath('/prefix/sub/sub2','/prefix/sub/sup/name'), + ajoin('prefix','sub','sub2','sup','name')) + +if __name__ == "__main__": + ScipyTest().run() |