[Numpy-svn] r3777 - in trunk/numpy/f2py/lib: . tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Fri May 18 12:45:18 EDT 2007
Author: pearu
Date: 2007-05-18 11:44:43 -0500 (Fri, 18 May 2007)
New Revision: 3777
Added:
trunk/numpy/f2py/lib/nary.py
trunk/numpy/f2py/lib/tests/
trunk/numpy/f2py/lib/tests/test_derived_scalar.py
trunk/numpy/f2py/lib/tests/test_module_module.py
trunk/numpy/f2py/lib/tests/test_module_scalar.py
trunk/numpy/f2py/lib/tests/test_scalar_function_in.py
trunk/numpy/f2py/lib/tests/test_scalar_in_out.py
Removed:
trunk/numpy/f2py/lib/test_derived_scalar.py
trunk/numpy/f2py/lib/test_module_module.py
trunk/numpy/f2py/lib/test_module_scalar.py
trunk/numpy/f2py/lib/test_scalar_function_in.py
trunk/numpy/f2py/lib/test_scalar_in_out.py
Modified:
trunk/numpy/f2py/lib/main.py
Log:
g3 f2py: impl. compiling Fortran codes online (function numpy.f2py.lib.compile), clean up testing.
Modified: trunk/numpy/f2py/lib/main.py
===================================================================
--- trunk/numpy/f2py/lib/main.py 2007-05-18 16:41:44 UTC (rev 3776)
+++ trunk/numpy/f2py/lib/main.py 2007-05-18 16:44:43 UTC (rev 3777)
@@ -21,7 +21,7 @@
except ImportError:
numpy_version = 'N/A'
-__all__ = ['main']
+__all__ = ['main', 'compile']
__usage__ = """
F2PY G3 --- The third generation of Fortran to Python Interface Generator
@@ -100,7 +100,8 @@
import re
import shutil
import parser.api
-from parser.api import parse, PythonModule, EndStatement, Module, Subroutine, Function
+from parser.api import parse, PythonModule, EndStatement, Module, Subroutine, Function,\
+ get_reader
def get_values(sys_argv, prefix='', suffix='', strip_prefix=False, strip_suffix=False):
"""
@@ -200,9 +201,11 @@
if os.path.isfile(signature_output):
overwrite = get_option(sys_argv, '--overwrite-signature', False)
if not overwrite:
- print >> sys.stderr, 'Signature file %r exists. Use --overwrite-signature to overwrite.' % (signature_output)
+ print >> sys.stderr, 'Signature file %r exists. '\
+ 'Use --overwrite-signature to overwrite.' % (signature_output)
sys.exit()
- modulename = get_option_value(sys_argv,'-m',os.path.basename(name),os.path.basename(name))
+ modulename = get_option_value(sys_argv,'-m',os.path.basename(name),
+ os.path.basename(name))
output_stream = open(signature_output,'w')
flag = 'file'
@@ -217,7 +220,8 @@
elif word==':': flag = 'file'
elif word.startswith('--'): options.append(word)
else:
- {'file': file_names,'only': only_names, 'skip': skip_names}[flag].append(word)
+ {'file': file_names,'only': only_names,
+ 'skip': skip_names}[flag].append(word)
if options:
sys.stderr.write('Unused options: %s\n' % (', '.join(options)))
@@ -286,7 +290,7 @@
f = open(f_fn,'w')
f.write(f_code)
f.close()
- f_lib = '%s_f_wrappers_f2py' % (block.name)
+ #f_lib = '%s_f_wrappers_f2py' % (block.name)
module_info = {'name':block.name, 'c_sources':[c_fn],
'f_sources':[f_fn], 'language':'f90'}
module_infos.append(module_info)
@@ -371,7 +375,7 @@
if sources_only:
return
- def configuration(parent_package='', top_path=None):
+ def configuration(parent_package='', top_path=None or ''):
from numpy.distutils.misc_util import Configuration
config = Configuration('',parent_package,top_path)
flibname = modulename + '_fortran_f2py'
@@ -403,10 +407,18 @@
return config
old_sys_argv = sys.argv[:]
- new_sys_argv = [sys.argv[0]] + ['build',
- '--build-temp',build_dir,
- '--build-base',build_dir,
- '--build-platlib','.']
+ build_dir_ext_temp = os.path.join(build_dir,'ext_temp')
+ build_dir_clib_temp = os.path.join(build_dir,'clib_temp')
+ build_dir_clib_clib = os.path.join(build_dir,'clib_clib')
+ new_sys_argv = [sys.argv[0]] + ['build_ext',
+ '--build-temp',build_dir_ext_temp,
+ '--build-lib',build_dir,
+ 'build_clib',
+ '--build-temp',build_dir_clib_temp,
+ '--build-clib',build_dir_clib_clib,
+ ]
+ temp_dirs = [build_dir_ext_temp, build_dir_clib_temp, build_dir_clib_clib]
+
if fc_flags:
new_sys_argv += ['config_fc'] + fc_flags
sys.argv[:] = new_sys_argv
@@ -418,9 +430,11 @@
sys.argv[:] = old_sys_argv
- if clean_build_dir and os.path.exists(build_dir):
- sys.stderr.write('Removing build directory %s\n'%(build_dir))
- shutil.rmtree(build_dir)
+ if 1 or clean_build_dir:
+ for d in temp_dirs:
+ if os.path.exists(d):
+ sys.stderr.write('Removing build directory %s\n'%(d))
+ shutil.rmtree(d)
return
def main(sys_argv = None):
@@ -449,3 +463,73 @@
build_extension(sys_argv, sources_only = True)
return
+
+def compile(source,
+ jobname = 'untitled',
+ extra_args = [],
+ source_ext = None,
+ modulenames = None
+ ):
+ """
+ Build extension module from processing source with f2py.
+
+ jobname - the name of compile job. For non-module source
+ this will be also the name of extension module.
+ modulenames - the list of extension module names that
+ the given compilation job should create.
+ extra_args - a list of extra arguments for numpy style
+ setup.py command line.
+ source_ext - extension of the Fortran source file: .f90 or .f
+
+ Extension modules are saved to current working directory.
+ Returns a list of module objects according to modulenames
+ input.
+ """
+ from nary import encode
+ tempdir = tempfile.gettempdir()
+ s = 'f2pyjob_%s_%s' % (jobname, encode(source))
+ tmpdir = os.path.join(tempdir, s)
+ if source_ext is None:
+ reader = get_reader(source)
+ source_ext = {'free90':'.f90','fix90':'.f90','fix77':'.f','pyf':'.pyf'}[reader.mode]
+
+ if modulenames is None:
+ modulenames = jobname,
+ if os.path.isdir(tmpdir):
+ try:
+ sys.path.insert(0, tmpdir)
+ modules = []
+ for modulename in modulenames:
+ exec('import %s as m' % (modulename))
+ modules.append(m)
+ sys.path.pop(0)
+ return modules
+ except ImportError:
+ pass
+ finally:
+ sys.path.pop(0)
+ else:
+ os.mkdir(tmpdir)
+
+ fname = os.path.join(tmpdir,'%s_src%s' % (jobname, source_ext))
+
+ f = open(fname,'w')
+ f.write(source)
+ f.close()
+
+ sys_argv = []
+ sys_argv.extend(['--build-dir',tmpdir])
+ #sys_argv.extend(['-DF2PY_DEBUG_PYOBJ_TOFROM'])
+ sys_argv.extend(['-m',jobname, fname])
+
+ build_extension(sys_argv + extra_args)
+
+ sys.path.insert(0, tmpdir)
+ modules = []
+ for modulename in modulenames:
+ exec('import %s as m' % (modulename))
+ modules.append(m)
+ sys.path.pop(0)
+ return modules
+
+#EOF
Added: trunk/numpy/f2py/lib/nary.py
===================================================================
--- trunk/numpy/f2py/lib/nary.py 2007-05-18 16:41:44 UTC (rev 3776)
+++ trunk/numpy/f2py/lib/nary.py 2007-05-18 16:44:43 UTC (rev 3777)
@@ -0,0 +1,32 @@
+"""
+nary - convert integer to a number with an arbitrary base.
+"""
+
+__all__ = ['nary']
+
+_alphabet='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+def _getalpha(r):
+ if r>=len(_alphabet):
+ return '_'+nary(r-len(_alphabet),len(_alphabet))
+ return _alphabet[r]
+
+def nary(number, base=64):
+ """
+ Return string representation of a number with a given base.
+ """
+ if isinstance(number, str):
+ number = eval(number)
+ n = number
+ s = ''
+ while n:
+ n1 = n // base
+ r = n - n1*base
+ n = n1
+ s = _getalpha(r) + s
+ return s
+
+def encode(string):
+ import md5
+ return nary('0x'+md5.new(string).hexdigest())
+
+#print nary(12345124254252525522512324,64)
Deleted: trunk/numpy/f2py/lib/test_derived_scalar.py
===================================================================
--- trunk/numpy/f2py/lib/test_derived_scalar.py 2007-05-18 16:41:44 UTC (rev 3776)
+++ trunk/numpy/f2py/lib/test_derived_scalar.py 2007-05-18 16:44:43 UTC (rev 3777)
@@ -1,99 +0,0 @@
-#!/usr/bin/env python
-"""
-Tests for intent(in,out) derived type arguments in Fortran subroutine's.
-
------
-Permission to use, modify, and distribute this software is given under the
-terms of the NumPy License. See http://scipy.org.
-
-NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
-Author: Pearu Peterson <pearu at cens.ioc.ee>
-Created: Oct 2006
------
-"""
-
-import os
-import sys
-from numpy.testing import *
-
-def build(fortran_code, rebuild=True):
- modulename = os.path.splitext(os.path.basename(__file__))[0]+'_ext'
- try:
- exec ('import %s as m' % (modulename))
- if rebuild and os.stat(m.__file__)[8] < os.stat(__file__)[8]:
- del sys.modules[m.__name__] # soft unload extension module
- os.remove(m.__file__)
- raise ImportError,'%s is newer than %s' % (__file__, m.__file__)
- except ImportError,msg:
- assert str(msg).startswith('No module named'),str(msg)
- print msg, ', recompiling %s.' % (modulename)
- import tempfile
- fname = tempfile.mktemp() + '.f90'
- f = open(fname,'w')
- f.write(fortran_code)
- f.close()
- sys_argv = []
- sys_argv.extend(['--build-dir','tmp'])
- #sys_argv.extend(['-DF2PY_DEBUG_PYOBJ_TOFROM'])
- from main import build_extension
- sys_argv.extend(['-m',modulename, fname])
- build_extension(sys_argv)
- os.remove(fname)
- status = os.system(' '.join([sys.executable] + sys.argv))
- sys.exit(status)
- return m
-
-fortran_code = '''
-subroutine foo(a)
- type myt
- integer flag
- end type myt
- type(myt) a
-!f2py intent(in,out) a
- a % flag = a % flag + 1
-end
-function foo2(a)
- type myt
- integer flag
- end type myt
- type(myt) a
- type(myt) foo2
- foo2 % flag = a % flag + 2
-end
-'''
-
-# tester note: set rebuild=True when changing fortan_code and for SVN
-m = build(fortran_code, rebuild=True)
-
-from numpy import *
-
-class test_m(NumpyTestCase):
-
- def check_foo_simple(self, level=1):
- a = m.myt(2)
- assert_equal(a.flag,2)
- assert isinstance(a,m.myt),`a`
- r = m.foo(a)
- assert isinstance(r,m.myt),`r`
- assert r is a
- assert_equal(r.flag,3)
- assert_equal(a.flag,3)
-
- a.flag = 5
- assert_equal(r.flag,5)
-
- #s = m.foo((5,))
-
- def check_foo2_simple(self, level=1):
- a = m.myt(2)
- assert_equal(a.flag,2)
- assert isinstance(a,m.myt),`a`
- r = m.foo2(a)
- assert isinstance(r,m.myt),`r`
- assert r is not a
- assert_equal(a.flag,2)
- assert_equal(r.flag,4)
-
-
-if __name__ == "__main__":
- NumpyTest().run()
Deleted: trunk/numpy/f2py/lib/test_module_module.py
===================================================================
--- trunk/numpy/f2py/lib/test_module_module.py 2007-05-18 16:41:44 UTC (rev 3776)
+++ trunk/numpy/f2py/lib/test_module_module.py 2007-05-18 16:44:43 UTC (rev 3777)
@@ -1,83 +0,0 @@
-#!/usr/bin/env python
-"""
-Tests for module with scalar derived types and subprograms.
-
------
-Permission to use, modify, and distribute this software is given under the
-terms of the NumPy License. See http://scipy.org.
-
-NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
-Author: Pearu Peterson <pearu at cens.ioc.ee>
-Created: Oct 2006
------
-"""
-
-import os
-import sys
-from numpy.testing import *
-
-def build(fortran_code, rebuild=True, build_dir = 'tmp'):
- modulename = os.path.splitext(os.path.basename(__file__))[0] + '_ext'
- try:
- exec ('import %s as m' % (modulename))
- if rebuild and os.stat(m.__file__)[8] < os.stat(__file__)[8]:
- del sys.modules[m.__name__] # soft unload extension module
- os.remove(m.__file__)
- raise ImportError,'%s is newer than %s' % (__file__, m.__file__)
- except ImportError,msg:
- assert str(msg)==('No module named %s' % (modulename)) \
- or str(msg).startswith('%s is newer than' % (__file__)),str(msg)
- print msg, ', recompiling %s.' % (modulename)
- if not os.path.isdir(build_dir): os.makedirs(build_dir)
- fname = os.path.join(build_dir, modulename + '_source.f90')
- f = open(fname,'w')
- f.write(fortran_code)
- f.close()
- sys_argv = []
- sys_argv.extend(['--build-dir',build_dir])
- #sys_argv.extend(['-DF2PY_DEBUG_PYOBJ_TOFROM'])
- from main import build_extension
- sys_argv.extend(['-m',modulename, fname])
- build_extension(sys_argv)
- status = os.system(' '.join([sys.executable] + sys.argv))
- sys.exit(status)
- return m
-
-fortran_code = '''
-module test_module_module_ext2
- type rat
- integer n,d
- end type rat
- contains
- subroutine foo2()
- print*,"In foo2"
- end subroutine foo2
-end module
-module test_module_module_ext
- contains
- subroutine foo
- use test_module_module_ext2
- print*,"In foo"
- call foo2
- end subroutine foo
- subroutine bar(a)
- use test_module_module_ext2
- type(rat) a
- print*,"In bar,a=",a
- end subroutine bar
-end module test_module_module_ext
-'''
-
-# tester note: set rebuild=True when changing fortan_code and for SVN
-m = build(fortran_code, rebuild=True)
-
-from numpy import *
-
-class test_m(NumpyTestCase):
-
- def check_foo_simple(self, level=1):
- foo = m.foo
- foo()
-
-if __name__ == "__main__":
- NumpyTest().run()
Deleted: trunk/numpy/f2py/lib/test_module_scalar.py
===================================================================
--- trunk/numpy/f2py/lib/test_module_scalar.py 2007-05-18 16:41:44 UTC (rev 3776)
+++ trunk/numpy/f2py/lib/test_module_scalar.py 2007-05-18 16:44:43 UTC (rev 3777)
@@ -1,83 +0,0 @@
-#!/usr/bin/env python
-"""
-Tests for module with scalar derived types and subprograms.
-
------
-Permission to use, modify, and distribute this software is given under the
-terms of the NumPy License. See http://scipy.org.
-
-NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
-Author: Pearu Peterson <pearu at cens.ioc.ee>
-Created: Oct 2006
------
-"""
-
-import os
-import sys
-from numpy.testing import *
-
-def build(fortran_code, rebuild=True):
- modulename = os.path.splitext(os.path.basename(__file__))[0] + '_ext'
- try:
- exec ('import %s as m' % (modulename))
- if rebuild and os.stat(m.__file__)[8] < os.stat(__file__)[8]:
- del sys.modules[m.__name__] # soft unload extension module
- os.remove(m.__file__)
- raise ImportError,'%s is newer than %s' % (__file__, m.__file__)
- except ImportError,msg:
- assert str(msg)==('No module named %s' % (modulename)),str(msg)
- print msg, ', recompiling %s.' % (modulename)
- import tempfile
- fname = tempfile.mktemp() + '.f90'
- f = open(fname,'w')
- f.write(fortran_code)
- f.close()
- sys_argv = []
- sys_argv.extend(['--build-dir','tmp'])
- #sys_argv.extend(['-DF2PY_DEBUG_PYOBJ_TOFROM'])
- from main import build_extension
- sys_argv.extend(['-m',modulename, fname])
- build_extension(sys_argv)
- os.remove(fname)
- status = os.system(' '.join([sys.executable] + sys.argv))
- sys.exit(status)
- return m
-
-fortran_code = '''
-module test_module_scalar_ext
-
- contains
- subroutine foo(a)
- integer a
-!f2py intent(in,out) a
- a = a + 1
- end subroutine foo
- function foo2(a)
- integer a
- integer foo2
- foo2 = a + 2
- end function foo2
-end module test_module_scalar_ext
-'''
-
-# tester note: set rebuild=True when changing fortan_code and for SVN
-m = build(fortran_code, rebuild=True)
-
-from numpy import *
-
-class test_m(NumpyTestCase):
-
- def check_foo_simple(self, level=1):
- foo = m.foo
- r = foo(2)
- assert isinstance(r,int32),`type(r)`
- assert_equal(r,3)
-
- def check_foo2_simple(self, level=1):
- foo2 = m.foo2
- r = foo2(2)
- assert isinstance(r,int32),`type(r)`
- assert_equal(r,4)
-
-if __name__ == "__main__":
- NumpyTest().run()
Deleted: trunk/numpy/f2py/lib/test_scalar_function_in.py
===================================================================
--- trunk/numpy/f2py/lib/test_scalar_function_in.py 2007-05-18 16:41:44 UTC (rev 3776)
+++ trunk/numpy/f2py/lib/test_scalar_function_in.py 2007-05-18 16:44:43 UTC (rev 3777)
@@ -1,554 +0,0 @@
-#!/usr/bin/env python
-"""
-Tests for intent(in) arguments in subroutine-wrapped Fortran functions.
-
------
-Permission to use, modify, and distribute this software is given under the
-terms of the NumPy License. See http://scipy.org.
-
-NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
-Author: Pearu Peterson <pearu at cens.ioc.ee>
-Created: Oct 2006
------
-"""
-
-import os
-import sys
-from numpy.testing import *
-
-def build(fortran_code, rebuild=True):
- modulename = os.path.splitext(os.path.basename(__file__))[0]+'_ext'
- try:
- exec ('import %s as m' % (modulename))
- if rebuild and os.stat(m.__file__)[8] < os.stat(__file__)[8]:
- del sys.modules[m.__name__] # soft unload extension module
- os.remove(m.__file__)
- raise ImportError,'%s is newer than %s' % (__file__, m.__file__)
- except ImportError,msg:
- assert str(msg).startswith('No module named'),str(msg)
- print msg, ', recompiling %s.' % (modulename)
- import tempfile
- fname = tempfile.mktemp() + '.f'
- f = open(fname,'w')
- f.write(fortran_code)
- f.close()
- sys_argv = ['--build-dir','tmp']
- #sys_argv.extend(['-DF2PY_DEBUG_PYOBJ_TOFROM'])
- from main import build_extension
- sys_argv.extend(['-m',modulename, fname])
- build_extension(sys_argv)
- os.remove(fname)
- os.system(' '.join([sys.executable] + sys.argv))
- sys.exit(0)
- return m
-
-fortran_code = '''
- function fooint1(a)
- integer*1 a
- integer*1 fooint1
- fooint1 = a + 1
- end
- function fooint2(a)
- integer*2 a
- integer*2 fooint2
- fooint2 = a + 1
- end
- function fooint4(a)
- integer*4 a
- integer*4 fooint4
- fooint4 = a + 1
- end
- function fooint8(a)
- integer*8 a
- integer*8 fooint8
- fooint8 = a + 1
- end
- function foofloat4(a)
- real*4 a
- real*4 foofloat4
- foofloat4 = a + 1.0e0
- end
- function foofloat8(a)
- real*8 a
- real*8 foofloat8
- foofloat8 = a + 1.0d0
- end
- function foocomplex8(a)
- complex*8 a
- complex*8 foocomplex8
- foocomplex8 = a + 1.0e0
- end
- function foocomplex16(a)
- complex*16 a
- complex*16 foocomplex16
- foocomplex16 = a + 1.0d0
- end
- function foobool1(a)
- logical*1 a
- logical*1 foobool1
- foobool1 = .not. a
- end
- function foobool2(a)
- logical*2 a
- logical*2 foobool2
- foobool2 = .not. a
- end
- function foobool4(a)
- logical*4 a
- logical*4 foobool4
- foobool4 = .not. a
- end
- function foobool8(a)
- logical*8 a
- logical*8 foobool8
- foobool8 = .not. a
- end
- function foostring1(a)
- character*1 a
- character*1 foostring1
- foostring1 = "1"
- end
- function foostring5(a)
- character*5 a
- character*5 foostring5
- foostring5 = a
- foostring5(1:2) = "12"
- end
-! function foostringstar(a)
-! character*(*) a
-! character*(*) foostringstar
-! if (len(a).gt.0) then
-! foostringstar = a
-! foostringstar(1:1) = "1"
-! endif
-! end
-'''
-
-# tester note: set rebuild=True when changing fortan_code and for SVN
-m = build(fortran_code, rebuild=True)
-
-from numpy import *
-
-class test_m(NumpyTestCase):
-
- def check_foo_integer1(self, level=1):
- i = int8(2)
- e = int8(3)
- func = m.fooint1
- assert isinstance(i,int8),`type(i)`
- r = func(i)
- assert isinstance(r,int8),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,int8),`type(r)`
- assert_equal(r,e)
-
- for intx in [int64,int16,int32]:
- r = func(intx(2))
- assert isinstance(r,int8),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,int8),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,int8),`type(r)`
- assert_equal(r,e)
-
- r = func([2])
- assert isinstance(r,int8),`type(r)`
- assert_equal(r,e)
-
- self.assertRaises(TypeError,lambda :func(2.2j))
- self.assertRaises(TypeError,lambda :func([2,1]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_integer2(self, level=1):
- i = int16(2)
- e = int16(3)
- func = m.fooint2
- assert isinstance(i,int16),`type(i)`
- r = func(i)
- assert isinstance(r,int16),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,int16),`type(r)`
- assert_equal(r,e)
-
- for intx in [int8,int64,int32]:
- r = func(intx(2))
- assert isinstance(r,int16),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,int16),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,int16),`type(r)`
- assert_equal(r,e)
-
- r = func([2])
- assert isinstance(r,int16),`type(r)`
- assert_equal(r,e)
-
- self.assertRaises(TypeError,lambda :func(2.2j))
- self.assertRaises(TypeError,lambda :func([2,1]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_integer4(self, level=1):
- i = int32(2)
- e = int32(3)
- func = m.fooint4
- assert isinstance(i,int32),`type(i)`
- r = func(i)
- assert isinstance(r,int32),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,int32),`type(r)`
- assert_equal(r,e)
-
- for intx in [int8,int16,int64]:
- r = func(intx(2))
- assert isinstance(r,int32),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,int32),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,int32),`type(r)`
- assert_equal(r,e)
-
- r = func([2])
- assert isinstance(r,int32),`type(r)`
- assert_equal(r,e)
-
- self.assertRaises(TypeError,lambda :func(2.2j))
- self.assertRaises(TypeError,lambda :func([2,1]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_integer8(self, level=1):
- i = int64(2)
- e = int64(3)
- func = m.fooint8
- assert isinstance(i,int64),`type(i)`
- r = func(i)
- assert isinstance(r,int64),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,int64),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,int64),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,int64),`type(r)`
- assert_equal(r,e)
-
- for intx in [int8,int16,int32]:
- r = func(intx(2))
- assert isinstance(r,int64),`type(r)`
- assert_equal(r,e)
-
- r = func([2])
- assert isinstance(r,int64),`type(r)`
- assert_equal(r,e)
-
- self.assertRaises(TypeError,lambda :func(2.2j))
- self.assertRaises(TypeError,lambda :func([2,1]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_real4(self, level=1):
- i = float32(2)
- e = float32(3)
- func = m.foofloat4
- assert isinstance(i,float32),`type(i)`
- r = func(i)
- assert isinstance(r,float32),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,float32),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,float32),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,float32),`type(r)`
- assert_equal(r,e+float32(0.2))
-
- r = func(float64(2.0))
- assert isinstance(r,float32),`type(r)`
- assert_equal(r,e)
-
- r = func([2])
- assert isinstance(r,float32),`type(r)`
- assert_equal(r,e)
-
- self.assertRaises(TypeError,lambda :func(2.2j))
- self.assertRaises(TypeError,lambda :func([2,1]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_real8(self, level=1):
- i = float64(2)
- e = float64(3)
- func = m.foofloat8
- assert isinstance(i,float64),`type(i)`
- r = func(i)
- assert isinstance(r,float64),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,float64),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,float64),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,float64),`type(r)`
- assert_equal(r,e+float64(0.2))
-
- r = func(float32(2.0))
- assert isinstance(r,float64),`type(r)`
- assert_equal(r,e)
-
- r = func([2])
- assert isinstance(r,float64),`type(r)`
- assert_equal(r,e)
-
- self.assertRaises(TypeError,lambda :func(2.2j))
- self.assertRaises(TypeError,lambda :func([2,1]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_complex8(self, level=1):
- i = complex64(2)
- e = complex64(3)
- func = m.foocomplex8
- assert isinstance(i,complex64),`type(i)`
- r = func(i)
- assert isinstance(r,complex64),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,complex64),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,complex64),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,complex64),`type(r)`
- assert_equal(r,e+complex64(0.2))
-
- r = func(2+1j)
- assert isinstance(r,complex64),`type(r)`
- assert_equal(r,e+complex64(1j))
-
- r = func(complex128(2.0))
- assert isinstance(r,complex64),`type(r)`
- assert_equal(r,e)
-
- r = func([2])
- assert isinstance(r,complex64),`type(r)`
- assert_equal(r,e)
-
- r = func([2,3])
- assert isinstance(r,complex64),`type(r)`
- assert_equal(r,e+complex64(3j))
-
- self.assertRaises(TypeError,lambda :func([2,1,3]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_complex16(self, level=1):
- i = complex128(2)
- e = complex128(3)
- func = m.foocomplex16
- assert isinstance(i,complex128),`type(i)`
- r = func(i)
- assert isinstance(r,complex128),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,complex128),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,complex128),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,complex128),`type(r)`
- assert_equal(r,e+complex128(0.2))
-
- r = func(2+1j)
- assert isinstance(r,complex128),`type(r)`
- assert_equal(r,e+complex128(1j))
-
- r = func([2])
- assert isinstance(r,complex128),`type(r)`
- assert_equal(r,e)
-
- r = func([2,3])
- assert isinstance(r,complex128),`type(r)`
- assert_equal(r,e+complex128(3j))
-
- r = func(complex64(2.0))
- assert isinstance(r,complex128),`type(r)`
- assert_equal(r,e)
-
- self.assertRaises(TypeError,lambda :func([2,1,3]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_bool1(self, level=1):
- i = bool8(True)
- e = bool8(False)
- func = m.foobool1
- assert isinstance(i,bool8),`type(i)`
- r = func(i)
- assert isinstance(r,bool8),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- for tv in [1,2,2.1,-1j,[0],True]:
- r = func(tv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,e)
-
- for fv in [0,0.0,0j,False,(),{},[]]:
- r = func(fv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,not e)
-
- def check_foo_bool2(self, level=1):
- i = bool8(True)
- e = bool8(False)
- func = m.foobool2
- assert isinstance(i,bool8),`type(i)`
- r = func(i)
- assert isinstance(r,bool8),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- for tv in [1,2,2.1,-1j,[0],True]:
- r = func(tv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,e)
-
- for fv in [0,0.0,0j,False,(),{},[]]:
- r = func(fv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,not e)
-
- def check_foo_bool4(self, level=1):
- i = bool8(True)
- e = bool8(False)
- func = m.foobool4
- assert isinstance(i,bool8),`type(i)`
- r = func(i)
- assert isinstance(r,bool8),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- for tv in [1,2,2.1,-1j,[0],True]:
- r = func(tv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,e)
-
- for fv in [0,0.0,0j,False,(),{},[]]:
- r = func(fv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,not e)
-
- def check_foo_bool8(self, level=1):
- i = bool8(True)
- e = bool8(False)
- func = m.foobool8
- assert isinstance(i,bool8),`type(i)`
- r = func(i)
- assert isinstance(r,bool8),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- for tv in [1,2,2.1,-1j,[0],True]:
- r = func(tv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,e)
-
- for fv in [0,0.0,0j,False,(),{},[]]:
- r = func(fv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,not e)
-
- def check_foo_string1(self, level=1):
- i = string0('a')
- e = string0('1')
- func = m.foostring1
- assert isinstance(i,string0),`type(i)`
- r = func(i)
- assert isinstance(r,string0),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func('ab')
- assert isinstance(r,string0),`type(r)`
- assert_equal(r,e)
-
- r = func('')
- assert isinstance(r,string0),`type(r)`
- assert_equal(r,e)
-
- def check_foo_string5(self, level=1):
- i = string0('abcde')
- e = string0('12cde')
- func = m.foostring5
- assert isinstance(i,string0),`type(i)`
- r = func(i)
- assert isinstance(r,string0),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func('abc')
- assert isinstance(r,string0),`type(r)`
- assert_equal(r,'12c ')
-
- r = func('abcdefghi')
- assert isinstance(r,string0),`type(r)`
- assert_equal(r,'12cde')
-
- r = func([1])
- assert isinstance(r,string0),`type(r)`
- assert_equal(r,'12] ')
-
- def _check_foo_string0(self, level=1):
- i = string0('abcde')
- e = string0('12cde')
- func = m.foostringstar
- r = func('abcde')
- assert_equal(r,'1bcde')
- r = func('')
- assert_equal(r,'')
-
-if __name__ == "__main__":
- NumpyTest().run()
Deleted: trunk/numpy/f2py/lib/test_scalar_in_out.py
===================================================================
--- trunk/numpy/f2py/lib/test_scalar_in_out.py 2007-05-18 16:41:44 UTC (rev 3776)
+++ trunk/numpy/f2py/lib/test_scalar_in_out.py 2007-05-18 16:44:43 UTC (rev 3777)
@@ -1,552 +0,0 @@
-#!/usr/bin/env python
-"""
-Tests for intent(in,out) arguments in Fortran subroutine's.
-
------
-Permission to use, modify, and distribute this software is given under the
-terms of the NumPy License. See http://scipy.org.
-
-NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
-Author: Pearu Peterson <pearu at cens.ioc.ee>
-Created: Oct 2006
------
-"""
-
-import os
-import sys
-from numpy.testing import *
-
-def build(fortran_code, rebuild=True, build_dir='tmp'):
- modulename = os.path.splitext(os.path.basename(__file__))[0]+'_ext'
- try:
- exec ('import %s as m' % (modulename))
- if rebuild and os.stat(m.__file__)[8] < os.stat(__file__)[8]:
- del sys.modules[m.__name__] # soft unload extension module
- os.remove(m.__file__)
- raise ImportError,'%s is newer than %s' % (__file__, m.__file__)
- except ImportError,msg:
- assert str(msg)==('No module named %s' % (modulename)) \
- or str(msg).startswith('%s is newer than' % (__file__)),str(msg)
- print msg, ', recompiling %s.' % (modulename)
- if not os.path.isdir(build_dir): os.makedirs(build_dir)
- fname = os.path.join(build_dir,'%s_source.f' % (modulename))
- f = open(fname,'w')
- f.write(fortran_code)
- f.close()
- sys_argv = ['--build-dir',build_dir]
- #sys_argv.extend(['-DF2PY_DEBUG_PYOBJ_TOFROM'])
- from main import build_extension
- sys_argv.extend(['-m',modulename, fname])
- build_extension(sys_argv)
- status = os.system(' '.join([sys.executable] + sys.argv))
- sys.exit(status)
- return m
-
-fortran_code = '''
- subroutine fooint1(a)
- integer*1 a
-!f2py intent(in,out) a
- a = a + 1
- end
- subroutine fooint2(a)
- integer*2 a
-!f2py intent(in,out) a
- a = a + 1
- end
- subroutine fooint4(a)
- integer*4 a
-!f2py intent(in,out) a
- a = a + 1
- end
- subroutine fooint8(a)
- integer*8 a
-!f2py intent(in,out) a
- a = a + 1
- end
- subroutine foofloat4(a)
- real*4 a
-!f2py intent(in,out) a
- a = a + 1.0e0
- end
- subroutine foofloat8(a)
- real*8 a
-!f2py intent(in,out) a
- a = a + 1.0d0
- end
- subroutine foocomplex8(a)
- complex*8 a
-!f2py intent(in,out) a
- a = a + 1.0e0
- end
- subroutine foocomplex16(a)
- complex*16 a
-!f2py intent(in,out) a
- a = a + 1.0d0
- end
- subroutine foobool1(a)
- logical*1 a
-!f2py intent(in,out) a
- a = .not. a
- end
- subroutine foobool2(a)
- logical*2 a
-!f2py intent(in,out) a
- a = .not. a
- end
- subroutine foobool4(a)
- logical*4 a
-!f2py intent(in,out) a
- a = .not. a
- end
- subroutine foobool8(a)
- logical*8 a
-!f2py intent(in,out) a
- a = .not. a
- end
- subroutine foostring1(a)
- character*1 a
-!f2py intent(in,out) a
- a = "1"
- end
- subroutine foostring5(a)
- character*5 a
-!f2py intent(in,out) a
- a(1:2) = "12"
- end
- subroutine foostringstar(a)
- character*(*) a
-!f2py intent(in,out) a
- if (len(a).gt.0) then
- a(1:1) = "1"
- endif
- end
-'''
-
-# tester note: set rebuild=True when changing fortan_code and for SVN
-m = build(fortran_code, rebuild=True)
-
-from numpy import *
-
-class test_m(NumpyTestCase):
-
- def check_foo_integer1(self, level=1):
- i = int8(2)
- e = int8(3)
- func = m.fooint1
- assert isinstance(i,int8),`type(i)`
- r = func(i)
- assert isinstance(r,int8),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,int8),`type(r)`
- assert_equal(r,e)
-
- for intx in [int64,int16,int32]:
- r = func(intx(2))
- assert isinstance(r,int8),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,int8),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,int8),`type(r)`
- assert_equal(r,e)
-
- r = func([2])
- assert isinstance(r,int8),`type(r)`
- assert_equal(r,e)
-
- self.assertRaises(TypeError,lambda :func(2.2j))
- self.assertRaises(TypeError,lambda :func([2,1]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_integer2(self, level=1):
- i = int16(2)
- e = int16(3)
- func = m.fooint2
- assert isinstance(i,int16),`type(i)`
- r = func(i)
- assert isinstance(r,int16),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,int16),`type(r)`
- assert_equal(r,e)
-
- for intx in [int8,int64,int32]:
- r = func(intx(2))
- assert isinstance(r,int16),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,int16),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,int16),`type(r)`
- assert_equal(r,e)
-
- r = func([2])
- assert isinstance(r,int16),`type(r)`
- assert_equal(r,e)
-
- self.assertRaises(TypeError,lambda :func(2.2j))
- self.assertRaises(TypeError,lambda :func([2,1]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_integer4(self, level=1):
- i = int32(2)
- e = int32(3)
- func = m.fooint4
- assert isinstance(i,int32),`type(i)`
- r = func(i)
- assert isinstance(r,int32),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,int32),`type(r)`
- assert_equal(r,e)
-
- for intx in [int8,int16,int64]:
- r = func(intx(2))
- assert isinstance(r,int32),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,int32),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,int32),`type(r)`
- assert_equal(r,e)
-
- r = func([2])
- assert isinstance(r,int32),`type(r)`
- assert_equal(r,e)
-
- self.assertRaises(TypeError,lambda :func(2.2j))
- self.assertRaises(TypeError,lambda :func([2,1]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_integer8(self, level=1):
- i = int64(2)
- e = int64(3)
- func = m.fooint8
- assert isinstance(i,int64),`type(i)`
- r = func(i)
- assert isinstance(r,int64),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,int64),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,int64),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,int64),`type(r)`
- assert_equal(r,e)
-
- for intx in [int8,int16,int32]:
- r = func(intx(2))
- assert isinstance(r,int64),`type(r)`
- assert_equal(r,e)
-
- r = func([2])
- assert isinstance(r,int64),`type(r)`
- assert_equal(r,e)
-
- self.assertRaises(TypeError,lambda :func(2.2j))
- self.assertRaises(TypeError,lambda :func([2,1]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_real4(self, level=1):
- i = float32(2)
- e = float32(3)
- func = m.foofloat4
- assert isinstance(i,float32),`type(i)`
- r = func(i)
- assert isinstance(r,float32),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,float32),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,float32),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,float32),`type(r)`
- assert_equal(r,e+float32(0.2))
-
- r = func(float64(2.0))
- assert isinstance(r,float32),`type(r)`
- assert_equal(r,e)
-
- r = func([2])
- assert isinstance(r,float32),`type(r)`
- assert_equal(r,e)
-
- self.assertRaises(TypeError,lambda :func(2.2j))
- self.assertRaises(TypeError,lambda :func([2,1]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_real8(self, level=1):
- i = float64(2)
- e = float64(3)
- func = m.foofloat8
- assert isinstance(i,float64),`type(i)`
- r = func(i)
- assert isinstance(r,float64),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,float64),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,float64),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,float64),`type(r)`
- assert_equal(r,e+float64(0.2))
-
- r = func(float32(2.0))
- assert isinstance(r,float64),`type(r)`
- assert_equal(r,e)
-
- r = func([2])
- assert isinstance(r,float64),`type(r)`
- assert_equal(r,e)
-
- self.assertRaises(TypeError,lambda :func(2.2j))
- self.assertRaises(TypeError,lambda :func([2,1]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_complex8(self, level=1):
- i = complex64(2)
- e = complex64(3)
- func = m.foocomplex8
- assert isinstance(i,complex64),`type(i)`
- r = func(i)
- assert isinstance(r,complex64),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,complex64),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,complex64),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,complex64),`type(r)`
- assert_equal(r,e+complex64(0.2))
-
- r = func(2+1j)
- assert isinstance(r,complex64),`type(r)`
- assert_equal(r,e+complex64(1j))
-
- r = func(complex128(2.0))
- assert isinstance(r,complex64),`type(r)`
- assert_equal(r,e)
-
- r = func([2])
- assert isinstance(r,complex64),`type(r)`
- assert_equal(r,e)
-
- r = func([2,3])
- assert isinstance(r,complex64),`type(r)`
- assert_equal(r,e+complex64(3j))
-
- self.assertRaises(TypeError,lambda :func([2,1,3]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_complex16(self, level=1):
- i = complex128(2)
- e = complex128(3)
- func = m.foocomplex16
- assert isinstance(i,complex128),`type(i)`
- r = func(i)
- assert isinstance(r,complex128),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func(2)
- assert isinstance(r,complex128),`type(r)`
- assert_equal(r,e)
-
- r = func(2.0)
- assert isinstance(r,complex128),`type(r)`
- assert_equal(r,e)
-
- r = func(2.2)
- assert isinstance(r,complex128),`type(r)`
- assert_equal(r,e+complex128(0.2))
-
- r = func(2+1j)
- assert isinstance(r,complex128),`type(r)`
- assert_equal(r,e+complex128(1j))
-
- r = func([2])
- assert isinstance(r,complex128),`type(r)`
- assert_equal(r,e)
-
- r = func([2,3])
- assert isinstance(r,complex128),`type(r)`
- assert_equal(r,e+complex128(3j))
-
- r = func(complex64(2.0))
- assert isinstance(r,complex128),`type(r)`
- assert_equal(r,e)
-
- self.assertRaises(TypeError,lambda :func([2,1,3]))
- self.assertRaises(TypeError,lambda :func({}))
-
- def check_foo_bool1(self, level=1):
- i = bool8(True)
- e = bool8(False)
- func = m.foobool1
- assert isinstance(i,bool8),`type(i)`
- r = func(i)
- assert isinstance(r,bool8),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- for tv in [1,2,2.1,-1j,[0],True]:
- r = func(tv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,e)
-
- for fv in [0,0.0,0j,False,(),{},[]]:
- r = func(fv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,not e)
-
- def check_foo_bool2(self, level=1):
- i = bool8(True)
- e = bool8(False)
- func = m.foobool2
- assert isinstance(i,bool8),`type(i)`
- r = func(i)
- assert isinstance(r,bool8),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- for tv in [1,2,2.1,-1j,[0],True]:
- r = func(tv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,e)
-
- for fv in [0,0.0,0j,False,(),{},[]]:
- r = func(fv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,not e)
-
- def check_foo_bool4(self, level=1):
- i = bool8(True)
- e = bool8(False)
- func = m.foobool4
- assert isinstance(i,bool8),`type(i)`
- r = func(i)
- assert isinstance(r,bool8),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- for tv in [1,2,2.1,-1j,[0],True]:
- r = func(tv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,e)
-
- for fv in [0,0.0,0j,False,(),{},[]]:
- r = func(fv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,not e)
-
- def check_foo_bool8(self, level=1):
- i = bool8(True)
- e = bool8(False)
- func = m.foobool8
- assert isinstance(i,bool8),`type(i)`
- r = func(i)
- assert isinstance(r,bool8),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- for tv in [1,2,2.1,-1j,[0],True]:
- r = func(tv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,e)
-
- for fv in [0,0.0,0j,False,(),{},[]]:
- r = func(fv)
- assert isinstance(r,bool8),`type(r)`
- assert_equal(r,not e)
-
- def check_foo_string1(self, level=1):
- i = string0('a')
- e = string0('1')
- func = m.foostring1
- assert isinstance(i,string0),`type(i)`
- r = func(i)
- assert isinstance(r,string0),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func('ab')
- assert isinstance(r,string0),`type(r)`
- assert_equal(r,e)
-
- r = func('')
- assert isinstance(r,string0),`type(r)`
- assert_equal(r,e)
-
- def check_foo_string5(self, level=1):
- i = string0('abcde')
- e = string0('12cde')
- func = m.foostring5
- assert isinstance(i,string0),`type(i)`
- r = func(i)
- assert isinstance(r,string0),`type(r)`
- assert i is not r,`id(i),id(r)`
- assert_equal(r,e)
-
- r = func('abc')
- assert isinstance(r,string0),`type(r)`
- assert_equal(r,'12c ')
-
- r = func('abcdefghi')
- assert isinstance(r,string0),`type(r)`
- assert_equal(r,'12cde')
-
- r = func([1])
- assert isinstance(r,string0),`type(r)`
- assert_equal(r,'12] ')
-
- def check_foo_string0(self, level=1):
- i = string0('abcde')
- e = string0('12cde')
- func = m.foostringstar
- r = func('abcde')
- assert_equal(r,'1bcde')
- r = func('')
- assert_equal(r,'')
-
-if __name__ == "__main__":
- NumpyTest().run()
Added: trunk/numpy/f2py/lib/tests/test_derived_scalar.py
===================================================================
--- trunk/numpy/f2py/lib/tests/test_derived_scalar.py 2007-05-18 16:41:44 UTC (rev 3776)
+++ trunk/numpy/f2py/lib/tests/test_derived_scalar.py 2007-05-18 16:44:43 UTC (rev 3777)
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+"""
+Tests for intent(in,out) derived type arguments in Fortran subroutine's.
+
+-----
+Permission to use, modify, and distribute this software is given under the
+terms of the NumPy License. See http://scipy.org.
+
+NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
+Author: Pearu Peterson <pearu at cens.ioc.ee>
+Created: Oct 2006
+-----
+"""
+
+import os
+import sys
+from numpy.testing import *
+set_package_path()
+from lib.main import build_extension, compile
+restore_path()
+
+fortran_code = '''
+subroutine foo(a)
+ type myt
+ integer flag
+ end type myt
+ type(myt) a
+!f2py intent(in,out) a
+ a % flag = a % flag + 1
+end
+function foo2(a)
+ type myt
+ integer flag
+ end type myt
+ type(myt) a
+ type(myt) foo2
+ foo2 % flag = a % flag + 2
+end
+'''
+
+m, = compile(fortran_code, 'test_derived_scalar_ext')
+
+from numpy import *
+
+class test_m(NumpyTestCase):
+
+ def check_foo_simple(self, level=1):
+ a = m.myt(2)
+ assert_equal(a.flag,2)
+ assert isinstance(a,m.myt),`a`
+ r = m.foo(a)
+ assert isinstance(r,m.myt),`r`
+ assert r is a
+ assert_equal(r.flag,3)
+ assert_equal(a.flag,3)
+
+ a.flag = 5
+ assert_equal(r.flag,5)
+
+ #s = m.foo((5,))
+
+ def check_foo2_simple(self, level=1):
+ a = m.myt(2)
+ assert_equal(a.flag,2)
+ assert isinstance(a,m.myt),`a`
+ r = m.foo2(a)
+ assert isinstance(r,m.myt),`r`
+ assert r is not a
+ assert_equal(a.flag,2)
+ assert_equal(r.flag,4)
+
+
+if __name__ == "__main__":
+ NumpyTest().run()
Copied: trunk/numpy/f2py/lib/tests/test_module_module.py (from rev 3764, trunk/numpy/f2py/lib/test_module_module.py)
===================================================================
--- trunk/numpy/f2py/lib/test_module_module.py 2007-05-15 00:35:49 UTC (rev 3764)
+++ trunk/numpy/f2py/lib/tests/test_module_module.py 2007-05-18 16:44:43 UTC (rev 3777)
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+"""
+Tests for module with scalar derived types and subprograms.
+
+-----
+Permission to use, modify, and distribute this software is given under the
+terms of the NumPy License. See http://scipy.org.
+
+NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
+Author: Pearu Peterson <pearu at cens.ioc.ee>
+Created: Oct 2006
+-----
+"""
+
+import os
+import sys
+from numpy.testing import *
+
+set_package_path()
+from lib.main import build_extension, compile
+restore_path()
+
+fortran_code = '''
+module test_module_module_ext2
+ type rat
+ integer n,d
+ end type rat
+ contains
+ subroutine foo2()
+ print*,"In foo2"
+ end subroutine foo2
+end module
+module test_module_module_ext
+ contains
+ subroutine foo
+ use test_module_module_ext2
+ print*,"In foo"
+ call foo2
+ end subroutine foo
+ subroutine bar(a)
+ use test_module_module_ext2
+ type(rat) a
+ print*,"In bar,a=",a
+ end subroutine bar
+end module test_module_module_ext
+'''
+
+m,m2 = compile(fortran_code, modulenames=['test_module_module_ext',
+ 'test_module_module_ext2',
+ ])
+
+from numpy import *
+
+class test_m(NumpyTestCase):
+
+ def check_foo_simple(self, level=1):
+ foo = m.foo
+ foo()
+
+if __name__ == "__main__":
+ NumpyTest().run()
Copied: trunk/numpy/f2py/lib/tests/test_module_scalar.py (from rev 3764, trunk/numpy/f2py/lib/test_module_scalar.py)
===================================================================
--- trunk/numpy/f2py/lib/test_module_scalar.py 2007-05-15 00:35:49 UTC (rev 3764)
+++ trunk/numpy/f2py/lib/tests/test_module_scalar.py 2007-05-18 16:44:43 UTC (rev 3777)
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+"""
+Tests for module with scalar derived types and subprograms.
+
+-----
+Permission to use, modify, and distribute this software is given under the
+terms of the NumPy License. See http://scipy.org.
+
+NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
+Author: Pearu Peterson <pearu at cens.ioc.ee>
+Created: Oct 2006
+-----
+"""
+
+import os
+import sys
+from numpy.testing import *
+set_package_path()
+from lib.main import build_extension, compile
+restore_path()
+
+fortran_code = '''
+module test_module_scalar_ext
+
+ contains
+ subroutine foo(a)
+ integer a
+!f2py intent(in,out) a
+ a = a + 1
+ end subroutine foo
+ function foo2(a)
+ integer a
+ integer foo2
+ foo2 = a + 2
+ end function foo2
+end module test_module_scalar_ext
+'''
+
+m, = compile(fortran_code, modulenames = ['test_module_scalar_ext'])
+
+from numpy import *
+
+class test_m(NumpyTestCase):
+
+ def check_foo_simple(self, level=1):
+ foo = m.foo
+ r = foo(2)
+ assert isinstance(r,int32),`type(r)`
+ assert_equal(r,3)
+
+ def check_foo2_simple(self, level=1):
+ foo2 = m.foo2
+ r = foo2(2)
+ assert isinstance(r,int32),`type(r)`
+ assert_equal(r,4)
+
+if __name__ == "__main__":
+ NumpyTest().run()
Copied: trunk/numpy/f2py/lib/tests/test_scalar_function_in.py (from rev 3764, trunk/numpy/f2py/lib/test_scalar_function_in.py)
===================================================================
--- trunk/numpy/f2py/lib/test_scalar_function_in.py 2007-05-15 00:35:49 UTC (rev 3764)
+++ trunk/numpy/f2py/lib/tests/test_scalar_function_in.py 2007-05-18 16:44:43 UTC (rev 3777)
@@ -0,0 +1,532 @@
+#!/usr/bin/env python
+"""
+Tests for intent(in) arguments in subroutine-wrapped Fortran functions.
+
+-----
+Permission to use, modify, and distribute this software is given under the
+terms of the NumPy License. See http://scipy.org.
+
+NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
+Author: Pearu Peterson <pearu at cens.ioc.ee>
+Created: Oct 2006
+-----
+"""
+
+import os
+import sys
+from numpy.testing import *
+
+set_package_path()
+from lib.main import build_extension, compile
+restore_path()
+
+fortran_code = '''\
+! -*- f77 -*-
+ function fooint1(a)
+ integer*1 a
+ integer*1 fooint1
+ fooint1 = a + 1
+ end
+ function fooint2(a)
+ integer*2 a
+ integer*2 fooint2
+ fooint2 = a + 1
+ end
+ function fooint4(a)
+ integer*4 a
+ integer*4 fooint4
+ fooint4 = a + 1
+ end
+ function fooint8(a)
+ integer*8 a
+ integer*8 fooint8
+ fooint8 = a + 1
+ end
+ function foofloat4(a)
+ real*4 a
+ real*4 foofloat4
+ foofloat4 = a + 1.0e0
+ end
+ function foofloat8(a)
+ real*8 a
+ real*8 foofloat8
+ foofloat8 = a + 1.0d0
+ end
+ function foocomplex8(a)
+ complex*8 a
+ complex*8 foocomplex8
+ foocomplex8 = a + 1.0e0
+ end
+ function foocomplex16(a)
+ complex*16 a
+ complex*16 foocomplex16
+ foocomplex16 = a + 1.0d0
+ end
+ function foobool1(a)
+ logical*1 a
+ logical*1 foobool1
+ foobool1 = .not. a
+ end
+ function foobool2(a)
+ logical*2 a
+ logical*2 foobool2
+ foobool2 = .not. a
+ end
+ function foobool4(a)
+ logical*4 a
+ logical*4 foobool4
+ foobool4 = .not. a
+ end
+ function foobool8(a)
+ logical*8 a
+ logical*8 foobool8
+ foobool8 = .not. a
+ end
+ function foostring1(a)
+ character*1 a
+ character*1 foostring1
+ foostring1 = "1"
+ end
+ function foostring5(a)
+ character*5 a
+ character*5 foostring5
+ foostring5 = a
+ foostring5(1:2) = "12"
+ end
+! function foostringstar(a)
+! character*(*) a
+! character*(*) foostringstar
+! if (len(a).gt.0) then
+! foostringstar = a
+! foostringstar(1:1) = "1"
+! endif
+! end
+'''
+
+m, = compile(fortran_code, 'test_scalar_function_in_ext')
+
+from numpy import *
+
+class test_m(NumpyTestCase):
+
+ def check_foo_integer1(self, level=1):
+ i = int8(2)
+ e = int8(3)
+ func = m.fooint1
+ assert isinstance(i,int8),`type(i)`
+ r = func(i)
+ assert isinstance(r,int8),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,int8),`type(r)`
+ assert_equal(r,e)
+
+ for intx in [int64,int16,int32]:
+ r = func(intx(2))
+ assert isinstance(r,int8),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,int8),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,int8),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2])
+ assert isinstance(r,int8),`type(r)`
+ assert_equal(r,e)
+
+ self.assertRaises(TypeError,lambda :func(2.2j))
+ self.assertRaises(TypeError,lambda :func([2,1]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_integer2(self, level=1):
+ i = int16(2)
+ e = int16(3)
+ func = m.fooint2
+ assert isinstance(i,int16),`type(i)`
+ r = func(i)
+ assert isinstance(r,int16),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,int16),`type(r)`
+ assert_equal(r,e)
+
+ for intx in [int8,int64,int32]:
+ r = func(intx(2))
+ assert isinstance(r,int16),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,int16),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,int16),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2])
+ assert isinstance(r,int16),`type(r)`
+ assert_equal(r,e)
+
+ self.assertRaises(TypeError,lambda :func(2.2j))
+ self.assertRaises(TypeError,lambda :func([2,1]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_integer4(self, level=1):
+ i = int32(2)
+ e = int32(3)
+ func = m.fooint4
+ assert isinstance(i,int32),`type(i)`
+ r = func(i)
+ assert isinstance(r,int32),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,int32),`type(r)`
+ assert_equal(r,e)
+
+ for intx in [int8,int16,int64]:
+ r = func(intx(2))
+ assert isinstance(r,int32),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,int32),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,int32),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2])
+ assert isinstance(r,int32),`type(r)`
+ assert_equal(r,e)
+
+ self.assertRaises(TypeError,lambda :func(2.2j))
+ self.assertRaises(TypeError,lambda :func([2,1]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_integer8(self, level=1):
+ i = int64(2)
+ e = int64(3)
+ func = m.fooint8
+ assert isinstance(i,int64),`type(i)`
+ r = func(i)
+ assert isinstance(r,int64),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,int64),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,int64),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,int64),`type(r)`
+ assert_equal(r,e)
+
+ for intx in [int8,int16,int32]:
+ r = func(intx(2))
+ assert isinstance(r,int64),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2])
+ assert isinstance(r,int64),`type(r)`
+ assert_equal(r,e)
+
+ self.assertRaises(TypeError,lambda :func(2.2j))
+ self.assertRaises(TypeError,lambda :func([2,1]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_real4(self, level=1):
+ i = float32(2)
+ e = float32(3)
+ func = m.foofloat4
+ assert isinstance(i,float32),`type(i)`
+ r = func(i)
+ assert isinstance(r,float32),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,float32),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,float32),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,float32),`type(r)`
+ assert_equal(r,e+float32(0.2))
+
+ r = func(float64(2.0))
+ assert isinstance(r,float32),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2])
+ assert isinstance(r,float32),`type(r)`
+ assert_equal(r,e)
+
+ self.assertRaises(TypeError,lambda :func(2.2j))
+ self.assertRaises(TypeError,lambda :func([2,1]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_real8(self, level=1):
+ i = float64(2)
+ e = float64(3)
+ func = m.foofloat8
+ assert isinstance(i,float64),`type(i)`
+ r = func(i)
+ assert isinstance(r,float64),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,float64),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,float64),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,float64),`type(r)`
+ assert_equal(r,e+float64(0.2))
+
+ r = func(float32(2.0))
+ assert isinstance(r,float64),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2])
+ assert isinstance(r,float64),`type(r)`
+ assert_equal(r,e)
+
+ self.assertRaises(TypeError,lambda :func(2.2j))
+ self.assertRaises(TypeError,lambda :func([2,1]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_complex8(self, level=1):
+ i = complex64(2)
+ e = complex64(3)
+ func = m.foocomplex8
+ assert isinstance(i,complex64),`type(i)`
+ r = func(i)
+ assert isinstance(r,complex64),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,complex64),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,complex64),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,complex64),`type(r)`
+ assert_equal(r,e+complex64(0.2))
+
+ r = func(2+1j)
+ assert isinstance(r,complex64),`type(r)`
+ assert_equal(r,e+complex64(1j))
+
+ r = func(complex128(2.0))
+ assert isinstance(r,complex64),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2])
+ assert isinstance(r,complex64),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2,3])
+ assert isinstance(r,complex64),`type(r)`
+ assert_equal(r,e+complex64(3j))
+
+ self.assertRaises(TypeError,lambda :func([2,1,3]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_complex16(self, level=1):
+ i = complex128(2)
+ e = complex128(3)
+ func = m.foocomplex16
+ assert isinstance(i,complex128),`type(i)`
+ r = func(i)
+ assert isinstance(r,complex128),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,complex128),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,complex128),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,complex128),`type(r)`
+ assert_equal(r,e+complex128(0.2))
+
+ r = func(2+1j)
+ assert isinstance(r,complex128),`type(r)`
+ assert_equal(r,e+complex128(1j))
+
+ r = func([2])
+ assert isinstance(r,complex128),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2,3])
+ assert isinstance(r,complex128),`type(r)`
+ assert_equal(r,e+complex128(3j))
+
+ r = func(complex64(2.0))
+ assert isinstance(r,complex128),`type(r)`
+ assert_equal(r,e)
+
+ self.assertRaises(TypeError,lambda :func([2,1,3]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_bool1(self, level=1):
+ i = bool8(True)
+ e = bool8(False)
+ func = m.foobool1
+ assert isinstance(i,bool8),`type(i)`
+ r = func(i)
+ assert isinstance(r,bool8),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ for tv in [1,2,2.1,-1j,[0],True]:
+ r = func(tv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,e)
+
+ for fv in [0,0.0,0j,False,(),{},[]]:
+ r = func(fv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,not e)
+
+ def check_foo_bool2(self, level=1):
+ i = bool8(True)
+ e = bool8(False)
+ func = m.foobool2
+ assert isinstance(i,bool8),`type(i)`
+ r = func(i)
+ assert isinstance(r,bool8),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ for tv in [1,2,2.1,-1j,[0],True]:
+ r = func(tv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,e)
+
+ for fv in [0,0.0,0j,False,(),{},[]]:
+ r = func(fv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,not e)
+
+ def check_foo_bool4(self, level=1):
+ i = bool8(True)
+ e = bool8(False)
+ func = m.foobool4
+ assert isinstance(i,bool8),`type(i)`
+ r = func(i)
+ assert isinstance(r,bool8),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ for tv in [1,2,2.1,-1j,[0],True]:
+ r = func(tv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,e)
+
+ for fv in [0,0.0,0j,False,(),{},[]]:
+ r = func(fv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,not e)
+
+ def check_foo_bool8(self, level=1):
+ i = bool8(True)
+ e = bool8(False)
+ func = m.foobool8
+ assert isinstance(i,bool8),`type(i)`
+ r = func(i)
+ assert isinstance(r,bool8),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ for tv in [1,2,2.1,-1j,[0],True]:
+ r = func(tv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,e)
+
+ for fv in [0,0.0,0j,False,(),{},[]]:
+ r = func(fv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,not e)
+
+ def check_foo_string1(self, level=1):
+ i = string0('a')
+ e = string0('1')
+ func = m.foostring1
+ assert isinstance(i,string0),`type(i)`
+ r = func(i)
+ assert isinstance(r,string0),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func('ab')
+ assert isinstance(r,string0),`type(r)`
+ assert_equal(r,e)
+
+ r = func('')
+ assert isinstance(r,string0),`type(r)`
+ assert_equal(r,e)
+
+ def check_foo_string5(self, level=1):
+ i = string0('abcde')
+ e = string0('12cde')
+ func = m.foostring5
+ assert isinstance(i,string0),`type(i)`
+ r = func(i)
+ assert isinstance(r,string0),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func('abc')
+ assert isinstance(r,string0),`type(r)`
+ assert_equal(r,'12c ')
+
+ r = func('abcdefghi')
+ assert isinstance(r,string0),`type(r)`
+ assert_equal(r,'12cde')
+
+ r = func([1])
+ assert isinstance(r,string0),`type(r)`
+ assert_equal(r,'12] ')
+
+ def _check_foo_string0(self, level=1):
+ i = string0('abcde')
+ e = string0('12cde')
+ func = m.foostringstar
+ r = func('abcde')
+ assert_equal(r,'1bcde')
+ r = func('')
+ assert_equal(r,'')
+
+if __name__ == "__main__":
+ NumpyTest().run()
Copied: trunk/numpy/f2py/lib/tests/test_scalar_in_out.py (from rev 3764, trunk/numpy/f2py/lib/test_scalar_in_out.py)
===================================================================
--- trunk/numpy/f2py/lib/test_scalar_in_out.py 2007-05-15 00:35:49 UTC (rev 3764)
+++ trunk/numpy/f2py/lib/tests/test_scalar_in_out.py 2007-05-18 16:44:43 UTC (rev 3777)
@@ -0,0 +1,529 @@
+#!/usr/bin/env python
+"""
+Tests for intent(in,out) arguments in Fortran subroutine's.
+
+-----
+Permission to use, modify, and distribute this software is given under the
+terms of the NumPy License. See http://scipy.org.
+
+NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
+Author: Pearu Peterson <pearu at cens.ioc.ee>
+Created: Oct 2006
+-----
+"""
+
+import os
+import sys
+from numpy.testing import *
+
+set_package_path()
+from lib.main import build_extension, compile
+restore_path()
+
+fortran_code = '''
+ subroutine fooint1(a)
+ integer*1 a
+!f2py intent(in,out) a
+ a = a + 1
+ end
+ subroutine fooint2(a)
+ integer*2 a
+!f2py intent(in,out) a
+ a = a + 1
+ end
+ subroutine fooint4(a)
+ integer*4 a
+!f2py intent(in,out) a
+ a = a + 1
+ end
+ subroutine fooint8(a)
+ integer*8 a
+!f2py intent(in,out) a
+ a = a + 1
+ end
+ subroutine foofloat4(a)
+ real*4 a
+!f2py intent(in,out) a
+ a = a + 1.0e0
+ end
+ subroutine foofloat8(a)
+ real*8 a
+!f2py intent(in,out) a
+ a = a + 1.0d0
+ end
+ subroutine foocomplex8(a)
+ complex*8 a
+!f2py intent(in,out) a
+ a = a + 1.0e0
+ end
+ subroutine foocomplex16(a)
+ complex*16 a
+!f2py intent(in,out) a
+ a = a + 1.0d0
+ end
+ subroutine foobool1(a)
+ logical*1 a
+!f2py intent(in,out) a
+ a = .not. a
+ end
+ subroutine foobool2(a)
+ logical*2 a
+!f2py intent(in,out) a
+ a = .not. a
+ end
+ subroutine foobool4(a)
+ logical*4 a
+!f2py intent(in,out) a
+ a = .not. a
+ end
+ subroutine foobool8(a)
+ logical*8 a
+!f2py intent(in,out) a
+ a = .not. a
+ end
+ subroutine foostring1(a)
+ character*1 a
+!f2py intent(in,out) a
+ a = "1"
+ end
+ subroutine foostring5(a)
+ character*5 a
+!f2py intent(in,out) a
+ a(1:2) = "12"
+ end
+ subroutine foostringstar(a)
+ character*(*) a
+!f2py intent(in,out) a
+ if (len(a).gt.0) then
+ a(1:1) = "1"
+ endif
+ end
+'''
+
+m, = compile(fortran_code, 'test_scalar_in_out_ext', source_ext = '.f')
+
+from numpy import *
+
+class test_m(NumpyTestCase):
+
+ def check_foo_integer1(self, level=1):
+ i = int8(2)
+ e = int8(3)
+ func = m.fooint1
+ assert isinstance(i,int8),`type(i)`
+ r = func(i)
+ assert isinstance(r,int8),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,int8),`type(r)`
+ assert_equal(r,e)
+
+ for intx in [int64,int16,int32]:
+ r = func(intx(2))
+ assert isinstance(r,int8),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,int8),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,int8),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2])
+ assert isinstance(r,int8),`type(r)`
+ assert_equal(r,e)
+
+ self.assertRaises(TypeError,lambda :func(2.2j))
+ self.assertRaises(TypeError,lambda :func([2,1]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_integer2(self, level=1):
+ i = int16(2)
+ e = int16(3)
+ func = m.fooint2
+ assert isinstance(i,int16),`type(i)`
+ r = func(i)
+ assert isinstance(r,int16),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,int16),`type(r)`
+ assert_equal(r,e)
+
+ for intx in [int8,int64,int32]:
+ r = func(intx(2))
+ assert isinstance(r,int16),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,int16),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,int16),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2])
+ assert isinstance(r,int16),`type(r)`
+ assert_equal(r,e)
+
+ self.assertRaises(TypeError,lambda :func(2.2j))
+ self.assertRaises(TypeError,lambda :func([2,1]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_integer4(self, level=1):
+ i = int32(2)
+ e = int32(3)
+ func = m.fooint4
+ assert isinstance(i,int32),`type(i)`
+ r = func(i)
+ assert isinstance(r,int32),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,int32),`type(r)`
+ assert_equal(r,e)
+
+ for intx in [int8,int16,int64]:
+ r = func(intx(2))
+ assert isinstance(r,int32),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,int32),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,int32),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2])
+ assert isinstance(r,int32),`type(r)`
+ assert_equal(r,e)
+
+ self.assertRaises(TypeError,lambda :func(2.2j))
+ self.assertRaises(TypeError,lambda :func([2,1]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_integer8(self, level=1):
+ i = int64(2)
+ e = int64(3)
+ func = m.fooint8
+ assert isinstance(i,int64),`type(i)`
+ r = func(i)
+ assert isinstance(r,int64),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,int64),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,int64),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,int64),`type(r)`
+ assert_equal(r,e)
+
+ for intx in [int8,int16,int32]:
+ r = func(intx(2))
+ assert isinstance(r,int64),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2])
+ assert isinstance(r,int64),`type(r)`
+ assert_equal(r,e)
+
+ self.assertRaises(TypeError,lambda :func(2.2j))
+ self.assertRaises(TypeError,lambda :func([2,1]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_real4(self, level=1):
+ i = float32(2)
+ e = float32(3)
+ func = m.foofloat4
+ assert isinstance(i,float32),`type(i)`
+ r = func(i)
+ assert isinstance(r,float32),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,float32),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,float32),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,float32),`type(r)`
+ assert_equal(r,e+float32(0.2))
+
+ r = func(float64(2.0))
+ assert isinstance(r,float32),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2])
+ assert isinstance(r,float32),`type(r)`
+ assert_equal(r,e)
+
+ self.assertRaises(TypeError,lambda :func(2.2j))
+ self.assertRaises(TypeError,lambda :func([2,1]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_real8(self, level=1):
+ i = float64(2)
+ e = float64(3)
+ func = m.foofloat8
+ assert isinstance(i,float64),`type(i)`
+ r = func(i)
+ assert isinstance(r,float64),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,float64),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,float64),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,float64),`type(r)`
+ assert_equal(r,e+float64(0.2))
+
+ r = func(float32(2.0))
+ assert isinstance(r,float64),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2])
+ assert isinstance(r,float64),`type(r)`
+ assert_equal(r,e)
+
+ self.assertRaises(TypeError,lambda :func(2.2j))
+ self.assertRaises(TypeError,lambda :func([2,1]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_complex8(self, level=1):
+ i = complex64(2)
+ e = complex64(3)
+ func = m.foocomplex8
+ assert isinstance(i,complex64),`type(i)`
+ r = func(i)
+ assert isinstance(r,complex64),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,complex64),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,complex64),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,complex64),`type(r)`
+ assert_equal(r,e+complex64(0.2))
+
+ r = func(2+1j)
+ assert isinstance(r,complex64),`type(r)`
+ assert_equal(r,e+complex64(1j))
+
+ r = func(complex128(2.0))
+ assert isinstance(r,complex64),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2])
+ assert isinstance(r,complex64),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2,3])
+ assert isinstance(r,complex64),`type(r)`
+ assert_equal(r,e+complex64(3j))
+
+ self.assertRaises(TypeError,lambda :func([2,1,3]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_complex16(self, level=1):
+ i = complex128(2)
+ e = complex128(3)
+ func = m.foocomplex16
+ assert isinstance(i,complex128),`type(i)`
+ r = func(i)
+ assert isinstance(r,complex128),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func(2)
+ assert isinstance(r,complex128),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.0)
+ assert isinstance(r,complex128),`type(r)`
+ assert_equal(r,e)
+
+ r = func(2.2)
+ assert isinstance(r,complex128),`type(r)`
+ assert_equal(r,e+complex128(0.2))
+
+ r = func(2+1j)
+ assert isinstance(r,complex128),`type(r)`
+ assert_equal(r,e+complex128(1j))
+
+ r = func([2])
+ assert isinstance(r,complex128),`type(r)`
+ assert_equal(r,e)
+
+ r = func([2,3])
+ assert isinstance(r,complex128),`type(r)`
+ assert_equal(r,e+complex128(3j))
+
+ r = func(complex64(2.0))
+ assert isinstance(r,complex128),`type(r)`
+ assert_equal(r,e)
+
+ self.assertRaises(TypeError,lambda :func([2,1,3]))
+ self.assertRaises(TypeError,lambda :func({}))
+
+ def check_foo_bool1(self, level=1):
+ i = bool8(True)
+ e = bool8(False)
+ func = m.foobool1
+ assert isinstance(i,bool8),`type(i)`
+ r = func(i)
+ assert isinstance(r,bool8),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ for tv in [1,2,2.1,-1j,[0],True]:
+ r = func(tv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,e)
+
+ for fv in [0,0.0,0j,False,(),{},[]]:
+ r = func(fv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,not e)
+
+ def check_foo_bool2(self, level=1):
+ i = bool8(True)
+ e = bool8(False)
+ func = m.foobool2
+ assert isinstance(i,bool8),`type(i)`
+ r = func(i)
+ assert isinstance(r,bool8),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ for tv in [1,2,2.1,-1j,[0],True]:
+ r = func(tv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,e)
+
+ for fv in [0,0.0,0j,False,(),{},[]]:
+ r = func(fv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,not e)
+
+ def check_foo_bool4(self, level=1):
+ i = bool8(True)
+ e = bool8(False)
+ func = m.foobool4
+ assert isinstance(i,bool8),`type(i)`
+ r = func(i)
+ assert isinstance(r,bool8),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ for tv in [1,2,2.1,-1j,[0],True]:
+ r = func(tv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,e)
+
+ for fv in [0,0.0,0j,False,(),{},[]]:
+ r = func(fv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,not e)
+
+ def check_foo_bool8(self, level=1):
+ i = bool8(True)
+ e = bool8(False)
+ func = m.foobool8
+ assert isinstance(i,bool8),`type(i)`
+ r = func(i)
+ assert isinstance(r,bool8),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ for tv in [1,2,2.1,-1j,[0],True]:
+ r = func(tv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,e)
+
+ for fv in [0,0.0,0j,False,(),{},[]]:
+ r = func(fv)
+ assert isinstance(r,bool8),`type(r)`
+ assert_equal(r,not e)
+
+ def check_foo_string1(self, level=1):
+ i = string0('a')
+ e = string0('1')
+ func = m.foostring1
+ assert isinstance(i,string0),`type(i)`
+ r = func(i)
+ assert isinstance(r,string0),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func('ab')
+ assert isinstance(r,string0),`type(r)`
+ assert_equal(r,e)
+
+ r = func('')
+ assert isinstance(r,string0),`type(r)`
+ assert_equal(r,e)
+
+ def check_foo_string5(self, level=1):
+ i = string0('abcde')
+ e = string0('12cde')
+ func = m.foostring5
+ assert isinstance(i,string0),`type(i)`
+ r = func(i)
+ assert isinstance(r,string0),`type(r)`
+ assert i is not r,`id(i),id(r)`
+ assert_equal(r,e)
+
+ r = func('abc')
+ assert isinstance(r,string0),`type(r)`
+ assert_equal(r,'12c ')
+
+ r = func('abcdefghi')
+ assert isinstance(r,string0),`type(r)`
+ assert_equal(r,'12cde')
+
+ r = func([1])
+ assert isinstance(r,string0),`type(r)`
+ assert_equal(r,'12] ')
+
+ def check_foo_string0(self, level=1):
+ i = string0('abcde')
+ e = string0('12cde')
+ func = m.foostringstar
+ r = func('abcde')
+ assert_equal(r,'1bcde')
+ r = func('')
+ assert_equal(r,'')
+
+if __name__ == "__main__":
+ NumpyTest().run()
More information about the Numpy-svn
mailing list