summaryrefslogtreecommitdiff
path: root/numpy/f2py/tests/test_parameter.py
diff options
context:
space:
mode:
authorNick Papior <nickpapior@gmail.com>2016-11-23 09:11:52 +0100
committerNick Papior <nickpapior@gmail.com>2016-11-27 21:10:04 +0100
commit8a7e7a44c194e3c748ccee0862f4ae01e371a208 (patch)
tree45eaa09569e3fd84f1d9899cd8de476344b561ba /numpy/f2py/tests/test_parameter.py
parentce6d3ffc991c63c1a91fd806b4eb3d0008caace2 (diff)
downloadnumpy-8a7e7a44c194e3c748ccee0862f4ae01e371a208.tar.gz
BUG: fixed kind specifications for parameters
Fortran sources with parameters having kind-specifiers where not correctly intercepted in the crackfortran.py source. The reason was a restrictive check for only integer specifiers which did not split real's into the correct number. Furthermore, several tests has been added which tests the different kind specifiers and their use in codes, also all of them together. Signed-off-by: Nick Papior <nickpapior@gmail.com>
Diffstat (limited to 'numpy/f2py/tests/test_parameter.py')
-rw-r--r--numpy/f2py/tests/test_parameter.py102
1 files changed, 102 insertions, 0 deletions
diff --git a/numpy/f2py/tests/test_parameter.py b/numpy/f2py/tests/test_parameter.py
new file mode 100644
index 000000000..f0168b2d5
--- /dev/null
+++ b/numpy/f2py/tests/test_parameter.py
@@ -0,0 +1,102 @@
+from __future__ import division, absolute_import, print_function
+
+import os
+import math
+
+import numpy as np
+from numpy.testing import run_module_suite, dec, assert_raises, assert_equal
+
+import util
+
+
+def _path(*a):
+ return os.path.join(*((os.path.dirname(__file__),) + a))
+
+
+class TestParameters(util.F2PyTest):
+ # Check that intent(in out) translates as intent(inout)
+ sources = [_path('src', 'parameter', 'constant_real.f90'),
+ _path('src', 'parameter', 'constant_integer.f90'),
+ _path('src', 'parameter', 'constant_both.f90'),
+ ]
+
+ @dec.slow
+ def test_constant_real_single(self):
+ # non-contiguous should raise error
+ x = np.arange(6, dtype=np.float32)[::2]
+ assert_raises(ValueError, self.module.foo_single, x)
+
+ # check values with contiguous array
+ x = np.arange(3, dtype=np.float32)
+ self.module.foo_single(x)
+ assert_equal(x, [0 + 1 + 2*3, 1, 2])
+
+ @dec.slow
+ def test_constant_real_double(self):
+ # non-contiguous should raise error
+ x = np.arange(6, dtype=np.float64)[::2]
+ assert_raises(ValueError, self.module.foo_double, x)
+
+ # check values with contiguous array
+ x = np.arange(3, dtype=np.float64)
+ self.module.foo_double(x)
+ assert_equal(x, [0 + 1 + 2*3, 1, 2])
+
+ @dec.slow
+ def test_constant_integer_int(self):
+ # non-contiguous should raise error
+ x = np.arange(6, dtype=np.int32)[::2]
+ assert_raises(ValueError, self.module.foo_int, x)
+
+ # check values with contiguous array
+ x = np.arange(3, dtype=np.int32)
+ self.module.foo_int(x)
+ assert_equal(x, [0 + 1 + 2*3, 1, 2])
+
+ @dec.slow
+ def test_constant_integer_long(self):
+ # non-contiguous should raise error
+ x = np.arange(6, dtype=np.int64)[::2]
+ assert_raises(ValueError, self.module.foo_long, x)
+
+ # check values with contiguous array
+ x = np.arange(3, dtype=np.int64)
+ self.module.foo_long(x)
+ assert_equal(x, [0 + 1 + 2*3, 1, 2])
+
+ @dec.slow
+ def test_constant_both(self):
+ # non-contiguous should raise error
+ x = np.arange(6, dtype=np.float64)[::2]
+ assert_raises(ValueError, self.module.foo, x)
+
+ # check values with contiguous array
+ x = np.arange(3, dtype=np.float64)
+ self.module.foo(x)
+ assert_equal(x, [0 + 1*3*3 + 2*3*3, 1*3, 2*3])
+
+ @dec.slow
+ def test_constant_no(self):
+ # non-contiguous should raise error
+ x = np.arange(6, dtype=np.float64)[::2]
+ assert_raises(ValueError, self.module.foo_no, x)
+
+ # check values with contiguous array
+ x = np.arange(3, dtype=np.float64)
+ self.module.foo_no(x)
+ assert_equal(x, [0 + 1*3*3 + 2*3*3, 1*3, 2*3])
+
+ @dec.slow
+ def test_constant_sum(self):
+ # non-contiguous should raise error
+ x = np.arange(6, dtype=np.float64)[::2]
+ assert_raises(ValueError, self.module.foo_sum, x)
+
+ # check values with contiguous array
+ x = np.arange(3, dtype=np.float64)
+ self.module.foo_sum(x)
+ assert_equal(x, [0 + 1*3*3 + 2*3*3, 1*3, 2*3])
+
+
+if __name__ == "__main__":
+ run_module_suite()