summaryrefslogtreecommitdiff
path: root/numpy/f2py/lib/tests/test_derived_scalar.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/f2py/lib/tests/test_derived_scalar.py')
-rw-r--r--numpy/f2py/lib/tests/test_derived_scalar.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/numpy/f2py/lib/tests/test_derived_scalar.py b/numpy/f2py/lib/tests/test_derived_scalar.py
new file mode 100644
index 000000000..c57778020
--- /dev/null
+++ b/numpy/f2py/lib/tests/test_derived_scalar.py
@@ -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@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()