diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2015-07-25 15:57:35 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2015-07-25 15:57:35 -0600 |
commit | ac193fac0ae1efa6c5c1fc2705615ee60d868774 (patch) | |
tree | 6bd65b1f3c2e5701c06afc107238ae73a7e6efff /numpy/f2py/tests | |
parent | 5eeb3c45fe407137771105ff863a46d623e7af84 (diff) | |
download | numpy-ac193fac0ae1efa6c5c1fc2705615ee60d868774.tar.gz |
STY: PEP8 and pyflakes fixes for numpy/f2py/tests.
Diffstat (limited to 'numpy/f2py/tests')
-rw-r--r-- | numpy/f2py/tests/test_array_from_pyobj.py | 212 | ||||
-rw-r--r-- | numpy/f2py/tests/test_assumed_shape.py | 20 | ||||
-rw-r--r-- | numpy/f2py/tests/test_callback.py | 10 | ||||
-rw-r--r-- | numpy/f2py/tests/test_kind.py | 28 | ||||
-rw-r--r-- | numpy/f2py/tests/test_mixed.py | 13 | ||||
-rw-r--r-- | numpy/f2py/tests/test_return_character.py | 30 | ||||
-rw-r--r-- | numpy/f2py/tests/test_return_complex.py | 51 | ||||
-rw-r--r-- | numpy/f2py/tests/test_return_integer.py | 42 | ||||
-rw-r--r-- | numpy/f2py/tests/test_return_logical.py | 84 | ||||
-rw-r--r-- | numpy/f2py/tests/test_return_real.py | 53 | ||||
-rw-r--r-- | numpy/f2py/tests/test_size.py | 13 |
11 files changed, 298 insertions, 258 deletions
diff --git a/numpy/f2py/tests/test_array_from_pyobj.py b/numpy/f2py/tests/test_array_from_pyobj.py index c51fa3936..21ed7c1fb 100644 --- a/numpy/f2py/tests/test_array_from_pyobj.py +++ b/numpy/f2py/tests/test_array_from_pyobj.py @@ -4,18 +4,21 @@ import unittest import os import sys import copy -import platform import nose -from numpy.testing import * -from numpy import (array, alltrue, ndarray, asarray, can_cast, zeros, dtype, - intp, clongdouble) +from numpy import ( + array, alltrue, ndarray, zeros, dtype, intp, clongdouble +) +from numpy.testing import ( + run_module_suite, assert_, assert_equal +) from numpy.core.multiarray import typeinfo - import util wrap = None + + def setup(): """ Build the required testing extension module @@ -40,10 +43,12 @@ def setup(): wrap = util.build_module_distutils(src, config_code, 'test_array_from_pyobj_ext') + def flags_info(arr): flags = wrap.array_attrs(arr)[6] return flags2names(flags) + def flags2names(flags): info = [] for flagname in ['CONTIGUOUS', 'FORTRAN', 'OWNDATA', 'ENSURECOPY', @@ -55,31 +60,39 @@ def flags2names(flags): info.append(flagname) return info + class Intent(object): - def __init__(self,intent_list=[]): + + def __init__(self, intent_list=[]): self.intent_list = intent_list[:] flags = 0 for i in intent_list: - if i=='optional': + if i == 'optional': flags |= wrap.F2PY_OPTIONAL else: - flags |= getattr(wrap, 'F2PY_INTENT_'+i.upper()) + flags |= getattr(wrap, 'F2PY_INTENT_' + i.upper()) self.flags = flags + def __getattr__(self, name): name = name.lower() - if name=='in_': name='in' - return self.__class__(self.intent_list+[name]) + if name == 'in_': + name = 'in' + return self.__class__(self.intent_list + [name]) + def __str__(self): return 'intent(%s)' % (','.join(self.intent_list)) + def __repr__(self): return 'Intent(%r)' % (self.intent_list) - def is_intent(self,*names): + + def is_intent(self, *names): for name in names: if name not in self.intent_list: return False return True - def is_intent_exact(self,*names): - return len(self.intent_list)==len(names) and self.is_intent(*names) + + def is_intent_exact(self, *names): + return len(self.intent_list) == len(names) and self.is_intent(*names) intent = Intent() @@ -87,7 +100,7 @@ _type_names = ['BOOL', 'BYTE', 'UBYTE', 'SHORT', 'USHORT', 'INT', 'UINT', 'LONG', 'ULONG', 'LONGLONG', 'ULONGLONG', 'FLOAT', 'DOUBLE', 'CFLOAT'] -_cast_dict = {'BOOL':['BOOL']} +_cast_dict = {'BOOL': ['BOOL']} _cast_dict['BYTE'] = _cast_dict['BOOL'] + ['BYTE'] _cast_dict['UBYTE'] = _cast_dict['BOOL'] + ['UBYTE'] _cast_dict['BYTE'] = ['BYTE'] @@ -109,18 +122,19 @@ _cast_dict['DOUBLE'] = _cast_dict['INT'] + ['UINT', 'FLOAT', 'DOUBLE'] _cast_dict['CFLOAT'] = _cast_dict['FLOAT'] + ['CFLOAT'] # 32 bit system malloc typically does not provide the alignment required by -# 16 byte long double types this means the inout intent cannot be satisfied and -# several tests fail as the alignment flag can be randomly true or fals +# 16 byte long double types this means the inout intent cannot be satisfied +# and several tests fail as the alignment flag can be randomly true or fals # when numpy gains an aligned allocator the tests could be enabled again if ((intp().dtype.itemsize != 4 or clongdouble().dtype.alignment <= 8) and sys.platform != 'win32'): _type_names.extend(['LONGDOUBLE', 'CDOUBLE', 'CLONGDOUBLE']) _cast_dict['LONGDOUBLE'] = _cast_dict['LONG'] + \ - ['ULONG', 'FLOAT', 'DOUBLE', 'LONGDOUBLE'] + ['ULONG', 'FLOAT', 'DOUBLE', 'LONGDOUBLE'] _cast_dict['CLONGDOUBLE'] = _cast_dict['LONGDOUBLE'] + \ - ['CFLOAT', 'CDOUBLE', 'CLONGDOUBLE'] + ['CFLOAT', 'CDOUBLE', 'CLONGDOUBLE'] _cast_dict['CDOUBLE'] = _cast_dict['DOUBLE'] + ['CFLOAT', 'CDOUBLE'] + class Type(object): _type_cache = {} @@ -142,7 +156,7 @@ class Type(object): def _init(self, name): self.NAME = name.upper() - self.type_num = getattr(wrap, 'NPY_'+self.NAME) + self.type_num = getattr(wrap, 'NPY_' + self.NAME) assert_equal(self.type_num, typeinfo[self.NAME][1]) self.dtype = typeinfo[self.NAME][-1] self.elsize = typeinfo[self.NAME][2] / 8 @@ -158,7 +172,7 @@ class Type(object): bits = typeinfo[self.NAME][3] types = [] for name in _type_names: - if typeinfo[name][3]<bits: + if typeinfo[name][3] < bits: types.append(Type(name)) return types @@ -166,8 +180,9 @@ class Type(object): bits = typeinfo[self.NAME][3] types = [] for name in _type_names: - if name==self.NAME: continue - if typeinfo[name][3]==bits: + if name == self.NAME: + continue + if typeinfo[name][3] == bits: types.append(Type(name)) return types @@ -175,11 +190,13 @@ class Type(object): bits = typeinfo[self.NAME][3] types = [] for name in _type_names: - if typeinfo[name][3]>bits: + if typeinfo[name][3] > bits: types.append(Type(name)) return types + class Array(object): + def __init__(self, typ, dims, intent, obj): self.type = typ self.dims = dims @@ -194,10 +211,11 @@ class Array(object): self.arr_attr = wrap.array_attrs(self.arr) - if len(dims)>1: + if len(dims) > 1: if self.intent.is_intent('c'): assert_(intent.flags & wrap.F2PY_INTENT_C) - assert_(not self.arr.flags['FORTRAN'], repr((self.arr.flags, getattr(obj, 'flags', None)))) + assert_(not self.arr.flags['FORTRAN'], + repr((self.arr.flags, getattr(obj, 'flags', None)))) assert_(self.arr.flags['CONTIGUOUS']) assert_(not self.arr_attr[6] & wrap.FORTRAN) else: @@ -215,15 +233,14 @@ class Array(object): assert_(isinstance(obj, ndarray), repr(type(obj))) self.pyarr = array(obj).reshape(*dims).copy() else: - self.pyarr = array(array(obj, - dtype = typ.dtypechar).reshape(*dims), + self.pyarr = array(array(obj, dtype=typ.dtypechar).reshape(*dims), order=self.intent.is_intent('c') and 'C' or 'F') - assert_(self.pyarr.dtype == typ, \ - repr((self.pyarr.dtype, typ))) + assert_(self.pyarr.dtype == typ, + repr((self.pyarr.dtype, typ))) assert_(self.pyarr.flags['OWNDATA'], (obj, intent)) self.pyarr_attr = wrap.array_attrs(self.pyarr) - if len(dims)>1: + if len(dims) > 1: if self.intent.is_intent('c'): assert_(not self.pyarr.flags['FORTRAN']) assert_(self.pyarr.flags['CONTIGUOUS']) @@ -233,35 +250,36 @@ class Array(object): assert_(not self.pyarr.flags['CONTIGUOUS']) assert_(self.pyarr_attr[6] & wrap.FORTRAN) - - assert_(self.arr_attr[1]==self.pyarr_attr[1]) # nd - assert_(self.arr_attr[2]==self.pyarr_attr[2]) # dimensions - if self.arr_attr[1]<=1: - assert_(self.arr_attr[3]==self.pyarr_attr[3],\ - repr((self.arr_attr[3], self.pyarr_attr[3], - self.arr.tobytes(), self.pyarr.tobytes()))) # strides - assert_(self.arr_attr[5][-2:]==self.pyarr_attr[5][-2:],\ - repr((self.arr_attr[5], self.pyarr_attr[5]))) # descr - assert_(self.arr_attr[6]==self.pyarr_attr[6],\ - repr((self.arr_attr[6], self.pyarr_attr[6], flags2names(0*self.arr_attr[6]-self.pyarr_attr[6]), flags2names(self.arr_attr[6]), intent))) # flags + assert_(self.arr_attr[1] == self.pyarr_attr[1]) # nd + assert_(self.arr_attr[2] == self.pyarr_attr[2]) # dimensions + if self.arr_attr[1] <= 1: + assert_(self.arr_attr[3] == self.pyarr_attr[3], + repr((self.arr_attr[3], self.pyarr_attr[3], + self.arr.tobytes(), self.pyarr.tobytes()))) # strides + assert_(self.arr_attr[5][-2:] == self.pyarr_attr[5][-2:], + repr((self.arr_attr[5], self.pyarr_attr[5]))) # descr + assert_(self.arr_attr[6] == self.pyarr_attr[6], + repr((self.arr_attr[6], self.pyarr_attr[6], + flags2names(0 * self.arr_attr[6] - self.pyarr_attr[6]), + flags2names(self.arr_attr[6]), intent))) # flags if intent.is_intent('cache'): - assert_(self.arr_attr[5][3]>=self.type.elsize,\ - repr((self.arr_attr[5][3], self.type.elsize))) + assert_(self.arr_attr[5][3] >= self.type.elsize, + repr((self.arr_attr[5][3], self.type.elsize))) else: - assert_(self.arr_attr[5][3]==self.type.elsize,\ - repr((self.arr_attr[5][3], self.type.elsize))) + assert_(self.arr_attr[5][3] == self.type.elsize, + repr((self.arr_attr[5][3], self.type.elsize))) assert_(self.arr_equal(self.pyarr, self.arr)) if isinstance(self.obj, ndarray): - if typ.elsize==Type(obj.dtype).elsize: - if not intent.is_intent('copy') and self.arr_attr[1]<=1: + if typ.elsize == Type(obj.dtype).elsize: + if not intent.is_intent('copy') and self.arr_attr[1] <= 1: assert_(self.has_shared_memory()) def arr_equal(self, arr1, arr2): if arr1.shape != arr2.shape: return False - s = arr1==arr2 + s = arr1 == arr2 return alltrue(s.flatten()) def __str__(self): @@ -275,11 +293,11 @@ class Array(object): if not isinstance(self.obj, ndarray): return False obj_attr = wrap.array_attrs(self.obj) - return obj_attr[0]==self.arr_attr[0] + return obj_attr[0] == self.arr_attr[0] -################################################## class test_intent(unittest.TestCase): + def test_in_out(self): assert_equal(str(intent.in_.out), 'intent(in,out)') assert_(intent.in_.c.is_intent('c')) @@ -288,9 +306,11 @@ class test_intent(unittest.TestCase): assert_(intent.in_.c.is_intent_exact('in', 'c')) assert_(not intent.in_.is_intent('c')) + class _test_shared_memory: num2seq = [1, 2] num23seq = [[1, 2, 3], [4, 5, 6]] + def test_in_from_2seq(self): a = self.array([2], intent.in_, self.num2seq) assert_(not a.has_shared_memory()) @@ -299,8 +319,9 @@ class _test_shared_memory: for t in self.type.cast_types(): obj = array(self.num2seq, dtype=t.dtype) a = self.array([len(self.num2seq)], intent.in_, obj) - if t.elsize==self.type.elsize: - assert_(a.has_shared_memory(), repr((self.type.dtype, t.dtype))) + if t.elsize == self.type.elsize: + assert_( + a.has_shared_memory(), repr((self.type.dtype, t.dtype))) else: assert_(not a.has_shared_memory(), repr(t.dtype)) @@ -312,7 +333,8 @@ class _test_shared_memory: try: a = self.array([2], intent.in_.inout, self.num2seq) except TypeError as msg: - if not str(msg).startswith('failed to initialize intent(inout|inplace|cache) array'): + if not str(msg).startswith('failed to initialize intent' + '(inout|inplace|cache) array'): raise else: raise SystemError('intent(inout) should have failed on sequence') @@ -328,10 +350,12 @@ class _test_shared_memory: try: a = self.array(shape, intent.in_.inout, obj) except ValueError as msg: - if not str(msg).startswith('failed to initialize intent(inout) array'): + if not str(msg).startswith('failed to initialize intent' + '(inout) array'): raise else: - raise SystemError('intent(inout) should have failed on improper array') + raise SystemError( + 'intent(inout) should have failed on improper array') def test_c_inout_23seq(self): obj = array(self.num23seq, dtype=self.type.dtype) @@ -362,7 +386,7 @@ class _test_shared_memory: obj = array(self.num23seq, dtype=t.dtype, order='F') a = self.array([len(self.num23seq), len(self.num23seq[0])], intent.in_, obj) - if t.elsize==self.type.elsize: + if t.elsize == self.type.elsize: assert_(a.has_shared_memory(), repr(t.dtype)) else: assert_(not a.has_shared_memory(), repr(t.dtype)) @@ -372,7 +396,7 @@ class _test_shared_memory: obj = array(self.num23seq, dtype=t.dtype) a = self.array([len(self.num23seq), len(self.num23seq[0])], intent.in_.c, obj) - if t.elsize==self.type.elsize: + if t.elsize == self.type.elsize: assert_(a.has_shared_memory(), repr(t.dtype)) else: assert_(not a.has_shared_memory(), repr(t.dtype)) @@ -413,10 +437,13 @@ class _test_shared_memory: try: a = self.array(shape, intent.in_.cache, obj[::-1]) except ValueError as msg: - if not str(msg).startswith('failed to initialize intent(cache) array'): + if not str(msg).startswith('failed to initialize' + ' intent(cache) array'): raise else: - raise SystemError('intent(cache) should have failed on multisegmented array') + raise SystemError( + 'intent(cache) should have failed on multisegmented array') + def test_in_cache_from_2casttype_failure(self): for t in self.type.all_types(): if t.elsize >= self.type.elsize: @@ -424,46 +451,50 @@ class _test_shared_memory: obj = array(self.num2seq, dtype=t.dtype) shape = (len(self.num2seq),) try: - a = self.array(shape, intent.in_.cache, obj) + self.array(shape, intent.in_.cache, obj) # Should succeed except ValueError as msg: - if not str(msg).startswith('failed to initialize intent(cache) array'): + if not str(msg).startswith('failed to initialize' + ' intent(cache) array'): raise else: - raise SystemError('intent(cache) should have failed on smaller array') + raise SystemError( + 'intent(cache) should have failed on smaller array') def test_cache_hidden(self): shape = (2,) a = self.array(shape, intent.cache.hide, None) - assert_(a.arr.shape==shape) + assert_(a.arr.shape == shape) shape = (2, 3) a = self.array(shape, intent.cache.hide, None) - assert_(a.arr.shape==shape) + assert_(a.arr.shape == shape) shape = (-1, 3) try: a = self.array(shape, intent.cache.hide, None) except ValueError as msg: - if not str(msg).startswith('failed to create intent(cache|hide)|optional array'): + if not str(msg).startswith('failed to create intent' + '(cache|hide)|optional array'): raise else: - raise SystemError('intent(cache) should have failed on undefined dimensions') + raise SystemError( + 'intent(cache) should have failed on undefined dimensions') def test_hidden(self): shape = (2,) a = self.array(shape, intent.hide, None) - assert_(a.arr.shape==shape) + assert_(a.arr.shape == shape) assert_(a.arr_equal(a.arr, zeros(shape, dtype=self.type.dtype))) shape = (2, 3) a = self.array(shape, intent.hide, None) - assert_(a.arr.shape==shape) + assert_(a.arr.shape == shape) assert_(a.arr_equal(a.arr, zeros(shape, dtype=self.type.dtype))) assert_(a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']) shape = (2, 3) a = self.array(shape, intent.c.hide, None) - assert_(a.arr.shape==shape) + assert_(a.arr.shape == shape) assert_(a.arr_equal(a.arr, zeros(shape, dtype=self.type.dtype))) assert_(not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']) @@ -471,26 +502,28 @@ class _test_shared_memory: try: a = self.array(shape, intent.hide, None) except ValueError as msg: - if not str(msg).startswith('failed to create intent(cache|hide)|optional array'): + if not str(msg).startswith('failed to create intent' + '(cache|hide)|optional array'): raise else: - raise SystemError('intent(hide) should have failed on undefined dimensions') + raise SystemError('intent(hide) should have failed' + ' on undefined dimensions') def test_optional_none(self): shape = (2,) a = self.array(shape, intent.optional, None) - assert_(a.arr.shape==shape) + assert_(a.arr.shape == shape) assert_(a.arr_equal(a.arr, zeros(shape, dtype=self.type.dtype))) shape = (2, 3) a = self.array(shape, intent.optional, None) - assert_(a.arr.shape==shape) + assert_(a.arr.shape == shape) assert_(a.arr_equal(a.arr, zeros(shape, dtype=self.type.dtype))) assert_(a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']) shape = (2, 3) a = self.array(shape, intent.c.optional, None) - assert_(a.arr.shape==shape) + assert_(a.arr.shape == shape) assert_(a.arr_equal(a.arr, zeros(shape, dtype=self.type.dtype))) assert_(not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']) @@ -498,18 +531,18 @@ class _test_shared_memory: obj = self.num2seq shape = (len(obj),) a = self.array(shape, intent.optional, obj) - assert_(a.arr.shape==shape) + assert_(a.arr.shape == shape) assert_(not a.has_shared_memory()) def test_optional_from_23seq(self): obj = self.num23seq shape = (len(obj), len(obj[0])) a = self.array(shape, intent.optional, obj) - assert_(a.arr.shape==shape) + assert_(a.arr.shape == shape) assert_(not a.has_shared_memory()) a = self.array(shape, intent.optional.c, obj) - assert_(a.arr.shape==shape) + assert_(a.arr.shape == shape) assert_(not a.has_shared_memory()) def test_inplace(self): @@ -517,11 +550,12 @@ class _test_shared_memory: assert_(not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']) shape = obj.shape a = self.array(shape, intent.inplace, obj) - assert_(obj[1][2]==a.arr[1][2], repr((obj, a.arr))) - a.arr[1][2]=54 - assert_(obj[1][2]==a.arr[1][2]==array(54, dtype=self.type.dtype), repr((obj, a.arr))) + assert_(obj[1][2] == a.arr[1][2], repr((obj, a.arr))) + a.arr[1][2] = 54 + assert_(obj[1][2] == a.arr[1][2] == + array(54, dtype=self.type.dtype), repr((obj, a.arr))) assert_(a.arr is obj) - assert_(obj.flags['FORTRAN']) # obj attributes are changed inplace! + assert_(obj.flags['FORTRAN']) # obj attributes are changed inplace! assert_(not obj.flags['CONTIGUOUS']) def test_inplace_from_casttype(self): @@ -529,18 +563,19 @@ class _test_shared_memory: if t is self.type: continue obj = array(self.num23seq, dtype=t.dtype) - assert_(obj.dtype.type==t.dtype) + assert_(obj.dtype.type == t.dtype) assert_(obj.dtype.type is not self.type.dtype) assert_(not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']) shape = obj.shape a = self.array(shape, intent.inplace, obj) - assert_(obj[1][2]==a.arr[1][2], repr((obj, a.arr))) - a.arr[1][2]=54 - assert_(obj[1][2]==a.arr[1][2]==array(54, dtype=self.type.dtype), repr((obj, a.arr))) + assert_(obj[1][2] == a.arr[1][2], repr((obj, a.arr))) + a.arr[1][2] = 54 + assert_(obj[1][2] == a.arr[1][2] == + array( 54, dtype=self.type.dtype), repr((obj, a.arr))) assert_(a.arr is obj) - assert_(obj.flags['FORTRAN']) # obj attributes are changed inplace! + assert_(obj.flags['FORTRAN']) # obj attributes changed inplace! assert_(not obj.flags['CONTIGUOUS']) - assert_(obj.dtype.type is self.type.dtype) # obj type is changed inplace! + assert_(obj.dtype.type is self.type.dtype) # obj changed inplace! for t in _type_names: @@ -555,5 +590,4 @@ class test_%s_gen(unittest.TestCase, if __name__ == "__main__": setup() - import nose - nose.runmodule() + run_module_suite() diff --git a/numpy/f2py/tests/test_assumed_shape.py b/numpy/f2py/tests/test_assumed_shape.py index d6beaee63..725e7f0c1 100644 --- a/numpy/f2py/tests/test_assumed_shape.py +++ b/numpy/f2py/tests/test_assumed_shape.py @@ -1,16 +1,15 @@ from __future__ import division, absolute_import, print_function import os -import math - -from numpy.testing import * -from numpy import array +from numpy.testing import run_module_suite, assert_, dec import util + def _path(*a): return os.path.join(*((os.path.dirname(__file__),) + a)) + class TestAssumedShapeSumExample(util.F2PyTest): sources = [_path('src', 'assumed_shape', 'foo_free.f90'), _path('src', 'assumed_shape', 'foo_use.f90'), @@ -21,17 +20,16 @@ class TestAssumedShapeSumExample(util.F2PyTest): @dec.slow def test_all(self): r = self.module.fsum([1, 2]) - assert_(r==3, repr(r)) + assert_(r == 3, repr(r)) r = self.module.sum([1, 2]) - assert_(r==3, repr(r)) + assert_(r == 3, repr(r)) r = self.module.sum_with_use([1, 2]) - assert_(r==3, repr(r)) + assert_(r == 3, repr(r)) r = self.module.mod.sum([1, 2]) - assert_(r==3, repr(r)) + assert_(r == 3, repr(r)) r = self.module.mod.fsum([1, 2]) - assert_(r==3, repr(r)) + assert_(r == 3, repr(r)) if __name__ == "__main__": - import nose - nose.runmodule() + run_module_suite() diff --git a/numpy/f2py/tests/test_callback.py b/numpy/f2py/tests/test_callback.py index 16464140f..b3f21d351 100644 --- a/numpy/f2py/tests/test_callback.py +++ b/numpy/f2py/tests/test_callback.py @@ -1,11 +1,12 @@ from __future__ import division, absolute_import, print_function -from numpy.testing import * -from numpy import array import math -import util import textwrap +from numpy import array +from numpy.testing import run_module_suite, assert_, assert_equal, dec +import util + class TestF77Callback(util.F2PyTest): code = """ subroutine t(fun,a) @@ -128,5 +129,4 @@ cf2py intent(out) a if __name__ == "__main__": - import nose - nose.runmodule() + run_module_suite() diff --git a/numpy/f2py/tests/test_kind.py b/numpy/f2py/tests/test_kind.py index f96fbffdb..7426b9853 100644 --- a/numpy/f2py/tests/test_kind.py +++ b/numpy/f2py/tests/test_kind.py @@ -1,22 +1,21 @@ from __future__ import division, absolute_import, print_function import os -import math - -from numpy.testing import * -from numpy import array +from numpy.testing import run_module_suite, assert_, dec +from numpy.f2py.crackfortran import ( + _selected_int_kind_func as selected_int_kind, + _selected_real_kind_func as selected_real_kind +) import util + def _path(*a): return os.path.join(*((os.path.dirname(__file__),) + a)) -from numpy.f2py.crackfortran import _selected_int_kind_func as selected_int_kind -from numpy.f2py.crackfortran import _selected_real_kind_func as selected_real_kind class TestKind(util.F2PyTest): - sources = [_path('src', 'kind', 'foo.f90'), - ] + sources = [_path('src', 'kind', 'foo.f90')] @dec.slow def test_all(self): @@ -24,13 +23,14 @@ class TestKind(util.F2PyTest): selectedintkind = self.module.selectedintkind for i in range(40): - assert_(selectedintkind(i) in [selected_int_kind(i), -1],\ - 'selectedintkind(%s): expected %r but got %r' % (i, selected_int_kind(i), selectedintkind(i))) + assert_(selectedintkind(i) in [selected_int_kind(i), -1], + 'selectedintkind(%s): expected %r but got %r' % + (i, selected_int_kind(i), selectedintkind(i))) for i in range(20): - assert_(selectedrealkind(i) in [selected_real_kind(i), -1],\ - 'selectedrealkind(%s): expected %r but got %r' % (i, selected_real_kind(i), selectedrealkind(i))) + assert_(selectedrealkind(i) in [selected_real_kind(i), -1], + 'selectedrealkind(%s): expected %r but got %r' % + (i, selected_real_kind(i), selectedrealkind(i))) if __name__ == "__main__": - import nose - nose.runmodule() + run_module_suite() diff --git a/numpy/f2py/tests/test_mixed.py b/numpy/f2py/tests/test_mixed.py index c4cb4889b..cfc669840 100644 --- a/numpy/f2py/tests/test_mixed.py +++ b/numpy/f2py/tests/test_mixed.py @@ -1,13 +1,10 @@ from __future__ import division, absolute_import, print_function import os -import math - -from numpy.testing import * -from numpy import array +import textwrap +from numpy.testing import run_module_suite, assert_, assert_equal, dec import util -import textwrap def _path(*a): return os.path.join(*((os.path.dirname(__file__),) + a)) @@ -34,8 +31,8 @@ class TestMixed(util.F2PyTest): ------- a : int """ - assert_equal(self.module.bar11.__doc__, textwrap.dedent(expected).lstrip()) + assert_equal(self.module.bar11.__doc__, + textwrap.dedent(expected).lstrip()) if __name__ == "__main__": - import nose - nose.runmodule() + run_module_suite() diff --git a/numpy/f2py/tests/test_return_character.py b/numpy/f2py/tests/test_return_character.py index 0865d54b3..e3e2b0d7e 100644 --- a/numpy/f2py/tests/test_return_character.py +++ b/numpy/f2py/tests/test_return_character.py @@ -1,30 +1,36 @@ from __future__ import division, absolute_import, print_function -from numpy.testing import * from numpy import array from numpy.compat import asbytes +from numpy.testing import run_module_suite, assert_, dec import util + class TestReturnCharacter(util.F2PyTest): + def check_function(self, t): tname = t.__doc__.split()[0] if tname in ['t0', 't1', 's0', 's1']: - assert_( t(23)==asbytes('2')) - r = t('ab');assert_( r==asbytes('a'), repr(r)) - r = t(array('ab'));assert_( r==asbytes('a'), repr(r)) - r = t(array(77, 'u1'));assert_( r==asbytes('M'), repr(r)) + assert_(t(23) == asbytes('2')) + r = t('ab') + assert_(r == asbytes('a'), repr(r)) + r = t(array('ab')) + assert_(r == asbytes('a'), repr(r)) + r = t(array(77, 'u1')) + assert_(r == asbytes('M'), repr(r)) #assert_(_raises(ValueError, t, array([77,87]))) #assert_(_raises(ValueError, t, array(77))) elif tname in ['ts', 'ss']: - assert_( t(23)==asbytes('23 '), repr(t(23))) - assert_( t('123456789abcdef')==asbytes('123456789a')) + assert_(t(23) == asbytes('23 '), repr(t(23))) + assert_(t('123456789abcdef') == asbytes('123456789a')) elif tname in ['t5', 's5']: - assert_( t(23)==asbytes('23 '), repr(t(23))) - assert_( t('ab')==asbytes('ab '), repr(t('ab'))) - assert_( t('123456789abcdef')==asbytes('12345')) + assert_(t(23) == asbytes('23 '), repr(t(23))) + assert_(t('ab') == asbytes('ab '), repr(t('ab'))) + assert_(t('123456789abcdef') == asbytes('12345')) else: raise NotImplementedError + class TestF77ReturnCharacter(TestReturnCharacter): code = """ function t0(value) @@ -79,6 +85,7 @@ cf2py intent(out) ts for name in "t0,t1,t5,s0,s1,s5,ss".split(","): self.check_function(getattr(self.module, name)) + class TestF90ReturnCharacter(TestReturnCharacter): suffix = ".f90" code = """ @@ -138,5 +145,4 @@ end module f90_return_char self.check_function(getattr(self.module.f90_return_char, name)) if __name__ == "__main__": - import nose - nose.runmodule() + run_module_suite() diff --git a/numpy/f2py/tests/test_return_complex.py b/numpy/f2py/tests/test_return_complex.py index d144cecf1..88ef83e94 100644 --- a/numpy/f2py/tests/test_return_complex.py +++ b/numpy/f2py/tests/test_return_complex.py @@ -1,39 +1,41 @@ from __future__ import division, absolute_import, print_function -from numpy.testing import * from numpy import array from numpy.compat import long +from numpy.testing import run_module_suite, assert_, assert_raises, dec import util + class TestReturnComplex(util.F2PyTest): + def check_function(self, t): tname = t.__doc__.split()[0] if tname in ['t0', 't8', 's0', 's8']: err = 1e-5 else: err = 0.0 - assert_( abs(t(234j)-234.0j)<=err) - assert_( abs(t(234.6)-234.6)<=err) - assert_( abs(t(long(234))-234.0)<=err) - assert_( abs(t(234.6+3j)-(234.6+3j))<=err) + assert_(abs(t(234j) - 234.0j) <= err) + assert_(abs(t(234.6) - 234.6) <= err) + assert_(abs(t(long(234)) - 234.0) <= err) + assert_(abs(t(234.6 + 3j) - (234.6 + 3j)) <= err) #assert_( abs(t('234')-234.)<=err) #assert_( abs(t('234.6')-234.6)<=err) - assert_( abs(t(-234)+234.)<=err) - assert_( abs(t([234])-234.)<=err) - assert_( abs(t((234,))-234.)<=err) - assert_( abs(t(array(234))-234.)<=err) - assert_( abs(t(array(23+4j, 'F'))-(23+4j))<=err) - assert_( abs(t(array([234]))-234.)<=err) - assert_( abs(t(array([[234]]))-234.)<=err) - assert_( abs(t(array([234], 'b'))+22.)<=err) - assert_( abs(t(array([234], 'h'))-234.)<=err) - assert_( abs(t(array([234], 'i'))-234.)<=err) - assert_( abs(t(array([234], 'l'))-234.)<=err) - assert_( abs(t(array([234], 'q'))-234.)<=err) - assert_( abs(t(array([234], 'f'))-234.)<=err) - assert_( abs(t(array([234], 'd'))-234.)<=err) - assert_( abs(t(array([234+3j], 'F'))-(234+3j))<=err) - assert_( abs(t(array([234], 'D'))-234.)<=err) + assert_(abs(t(-234) + 234.) <= err) + assert_(abs(t([234]) - 234.) <= err) + assert_(abs(t((234,)) - 234.) <= err) + assert_(abs(t(array(234)) - 234.) <= err) + assert_(abs(t(array(23 + 4j, 'F')) - (23 + 4j)) <= err) + assert_(abs(t(array([234])) - 234.) <= err) + assert_(abs(t(array([[234]])) - 234.) <= err) + assert_(abs(t(array([234], 'b')) + 22.) <= err) + assert_(abs(t(array([234], 'h')) - 234.) <= err) + assert_(abs(t(array([234], 'i')) - 234.) <= err) + assert_(abs(t(array([234], 'l')) - 234.) <= err) + assert_(abs(t(array([234], 'q')) - 234.) <= err) + assert_(abs(t(array([234], 'f')) - 234.) <= err) + assert_(abs(t(array([234], 'd')) - 234.) <= err) + assert_(abs(t(array([234 + 3j], 'F')) - (234 + 3j)) <= err) + assert_(abs(t(array([234], 'D')) - 234.) <= err) #assert_raises(TypeError, t, array([234], 'a1')) assert_raises(TypeError, t, 'abc') @@ -45,8 +47,8 @@ class TestReturnComplex(util.F2PyTest): assert_raises(TypeError, t, {}) try: - r = t(10**400) - assert_( repr(r) in ['(inf+0j)', '(Infinity+0j)'], repr(r)) + r = t(10 ** 400) + assert_(repr(r) in ['(inf+0j)', '(Infinity+0j)'], repr(r)) except OverflowError: pass @@ -165,5 +167,4 @@ end module f90_return_complex self.check_function(getattr(self.module.f90_return_complex, name)) if __name__ == "__main__": - import nose - nose.runmodule() + run_module_suite() diff --git a/numpy/f2py/tests/test_return_integer.py b/numpy/f2py/tests/test_return_integer.py index 056466208..00033d698 100644 --- a/numpy/f2py/tests/test_return_integer.py +++ b/numpy/f2py/tests/test_return_integer.py @@ -1,29 +1,31 @@ from __future__ import division, absolute_import, print_function -from numpy.testing import * from numpy import array from numpy.compat import long +from numpy.testing import run_module_suite, assert_, assert_raises, dec import util + class TestReturnInteger(util.F2PyTest): + def check_function(self, t): - assert_( t(123)==123, repr(t(123))) - assert_( t(123.6)==123) - assert_( t(long(123))==123) - assert_( t('123')==123) - assert_( t(-123)==-123) - assert_( t([123])==123) - assert_( t((123,))==123) - assert_( t(array(123))==123) - assert_( t(array([123]))==123) - assert_( t(array([[123]]))==123) - assert_( t(array([123], 'b'))==123) - assert_( t(array([123], 'h'))==123) - assert_( t(array([123], 'i'))==123) - assert_( t(array([123], 'l'))==123) - assert_( t(array([123], 'B'))==123) - assert_( t(array([123], 'f'))==123) - assert_( t(array([123], 'd'))==123) + assert_(t(123) == 123, repr(t(123))) + assert_(t(123.6) == 123) + assert_(t(long(123)) == 123) + assert_(t('123') == 123) + assert_(t(-123) == -123) + assert_(t([123]) == 123) + assert_(t((123,)) == 123) + assert_(t(array(123)) == 123) + assert_(t(array([123])) == 123) + assert_(t(array([[123]])) == 123) + assert_(t(array([123], 'b')) == 123) + assert_(t(array([123], 'h')) == 123) + assert_(t(array([123], 'i')) == 123) + assert_(t(array([123], 'l')) == 123) + assert_(t(array([123], 'B')) == 123) + assert_(t(array([123], 'f')) == 123) + assert_(t(array([123], 'd')) == 123) #assert_raises(ValueError, t, array([123],'S3')) assert_raises(ValueError, t, 'abc') @@ -38,6 +40,7 @@ class TestReturnInteger(util.F2PyTest): assert_raises(OverflowError, t, 100000000000000000000000) assert_raises(OverflowError, t, 10000000011111111111111.23) + class TestF77ReturnInteger(TestReturnInteger): code = """ function t0(value) @@ -174,5 +177,4 @@ end module f90_return_integer self.check_function(getattr(self.module.f90_return_integer, name)) if __name__ == "__main__": - import nose - nose.runmodule() + run_module_suite() diff --git a/numpy/f2py/tests/test_return_logical.py b/numpy/f2py/tests/test_return_logical.py index 82f86b67f..f88a25d7a 100644 --- a/numpy/f2py/tests/test_return_logical.py +++ b/numpy/f2py/tests/test_return_logical.py @@ -1,50 +1,52 @@ from __future__ import division, absolute_import, print_function -from numpy.testing import * from numpy import array from numpy.compat import long +from numpy.testing import run_module_suite, assert_, assert_raises, dec import util + class TestReturnLogical(util.F2PyTest): + def check_function(self, t): - assert_( t(True)==1, repr(t(True))) - assert_( t(False)==0, repr(t(False))) - assert_( t(0)==0) - assert_( t(None)==0) - assert_( t(0.0)==0) - assert_( t(0j)==0) - assert_( t(1j)==1) - assert_( t(234)==1) - assert_( t(234.6)==1) - assert_( t(long(234))==1) - assert_( t(234.6+3j)==1) - assert_( t('234')==1) - assert_( t('aaa')==1) - assert_( t('')==0) - assert_( t([])==0) - assert_( t(())==0) - assert_( t({})==0) - assert_( t(t)==1) - assert_( t(-234)==1) - assert_( t(10**100)==1) - assert_( t([234])==1) - assert_( t((234,))==1) - assert_( t(array(234))==1) - assert_( t(array([234]))==1) - assert_( t(array([[234]]))==1) - assert_( t(array([234], 'b'))==1) - assert_( t(array([234], 'h'))==1) - assert_( t(array([234], 'i'))==1) - assert_( t(array([234], 'l'))==1) - assert_( t(array([234], 'f'))==1) - assert_( t(array([234], 'd'))==1) - assert_( t(array([234+3j], 'F'))==1) - assert_( t(array([234], 'D'))==1) - assert_( t(array(0))==0) - assert_( t(array([0]))==0) - assert_( t(array([[0]]))==0) - assert_( t(array([0j]))==0) - assert_( t(array([1]))==1) + assert_(t(True) == 1, repr(t(True))) + assert_(t(False) == 0, repr(t(False))) + assert_(t(0) == 0) + assert_(t(None) == 0) + assert_(t(0.0) == 0) + assert_(t(0j) == 0) + assert_(t(1j) == 1) + assert_(t(234) == 1) + assert_(t(234.6) == 1) + assert_(t(long(234)) == 1) + assert_(t(234.6 + 3j) == 1) + assert_(t('234') == 1) + assert_(t('aaa') == 1) + assert_(t('') == 0) + assert_(t([]) == 0) + assert_(t(()) == 0) + assert_(t({}) == 0) + assert_(t(t) == 1) + assert_(t(-234) == 1) + assert_(t(10 ** 100) == 1) + assert_(t([234]) == 1) + assert_(t((234,)) == 1) + assert_(t(array(234)) == 1) + assert_(t(array([234])) == 1) + assert_(t(array([[234]])) == 1) + assert_(t(array([234], 'b')) == 1) + assert_(t(array([234], 'h')) == 1) + assert_(t(array([234], 'i')) == 1) + assert_(t(array([234], 'l')) == 1) + assert_(t(array([234], 'f')) == 1) + assert_(t(array([234], 'd')) == 1) + assert_(t(array([234 + 3j], 'F')) == 1) + assert_(t(array([234], 'D')) == 1) + assert_(t(array(0)) == 0) + assert_(t(array([0])) == 0) + assert_(t(array([[0]])) == 0) + assert_(t(array([0j])) == 0) + assert_(t(array([1])) == 1) assert_raises(ValueError, t, array([0, 0])) @@ -113,6 +115,7 @@ c end for name in "t0,t1,t2,t4,s0,s1,s2,s4".split(","): self.check_function(getattr(self.module, name)) + class TestF90ReturnLogical(TestReturnLogical): suffix = ".f90" code = """ @@ -183,5 +186,4 @@ end module f90_return_logical self.check_function(getattr(self.module.f90_return_logical, name)) if __name__ == "__main__": - import nose - nose.runmodule() + run_module_suite() diff --git a/numpy/f2py/tests/test_return_real.py b/numpy/f2py/tests/test_return_real.py index f9a09f620..57aa9badf 100644 --- a/numpy/f2py/tests/test_return_real.py +++ b/numpy/f2py/tests/test_return_real.py @@ -1,37 +1,38 @@ from __future__ import division, absolute_import, print_function -from numpy.testing import * from numpy import array from numpy.compat import long -import math +from numpy.testing import run_module_suite, assert_, assert_raises, dec import util + class TestReturnReal(util.F2PyTest): + def check_function(self, t): if t.__doc__.split()[0] in ['t0', 't4', 's0', 's4']: err = 1e-5 else: err = 0.0 - assert_( abs(t(234)-234.0)<=err) - assert_( abs(t(234.6)-234.6)<=err) - assert_( abs(t(long(234))-234.0)<=err) - assert_( abs(t('234')-234)<=err) - assert_( abs(t('234.6')-234.6)<=err) - assert_( abs(t(-234)+234)<=err) - assert_( abs(t([234])-234)<=err) - assert_( abs(t((234,))-234.)<=err) - assert_( abs(t(array(234))-234.)<=err) - assert_( abs(t(array([234]))-234.)<=err) - assert_( abs(t(array([[234]]))-234.)<=err) - assert_( abs(t(array([234], 'b'))+22)<=err) - assert_( abs(t(array([234], 'h'))-234.)<=err) - assert_( abs(t(array([234], 'i'))-234.)<=err) - assert_( abs(t(array([234], 'l'))-234.)<=err) - assert_( abs(t(array([234], 'B'))-234.)<=err) - assert_( abs(t(array([234], 'f'))-234.)<=err) - assert_( abs(t(array([234], 'd'))-234.)<=err) + assert_(abs(t(234) - 234.0) <= err) + assert_(abs(t(234.6) - 234.6) <= err) + assert_(abs(t(long(234)) - 234.0) <= err) + assert_(abs(t('234') - 234) <= err) + assert_(abs(t('234.6') - 234.6) <= err) + assert_(abs(t(-234) + 234) <= err) + assert_(abs(t([234]) - 234) <= err) + assert_(abs(t((234,)) - 234.) <= err) + assert_(abs(t(array(234)) - 234.) <= err) + assert_(abs(t(array([234])) - 234.) <= err) + assert_(abs(t(array([[234]])) - 234.) <= err) + assert_(abs(t(array([234], 'b')) + 22) <= err) + assert_(abs(t(array([234], 'h')) - 234.) <= err) + assert_(abs(t(array([234], 'i')) - 234.) <= err) + assert_(abs(t(array([234], 'l')) - 234.) <= err) + assert_(abs(t(array([234], 'B')) - 234.) <= err) + assert_(abs(t(array([234], 'f')) - 234.) <= err) + assert_(abs(t(array([234], 'd')) - 234.) <= err) if t.__doc__.split()[0] in ['t0', 't4', 's0', 's4']: - assert_( t(1e200)==t(1e300)) # inf + assert_(t(1e200) == t(1e300)) # inf #assert_raises(ValueError, t, array([234], 'S1')) assert_raises(ValueError, t, 'abc') @@ -43,11 +44,12 @@ class TestReturnReal(util.F2PyTest): assert_raises(Exception, t, {}) try: - r = t(10**400) - assert_( repr(r) in ['inf', 'Infinity'], repr(r)) + r = t(10 ** 400) + assert_(repr(r) in ['inf', 'Infinity'], repr(r)) except OverflowError: pass + class TestCReturnReal(TestReturnReal): suffix = ".pyf" module_name = "c_ext_return_real" @@ -85,6 +87,7 @@ end python module c_ext_return_real for name in "t4,t8,s4,s8".split(","): self.check_function(getattr(self.module, name)) + class TestF77ReturnReal(TestReturnReal): code = """ function t0(value) @@ -139,6 +142,7 @@ cf2py intent(out) td for name in "t0,t4,t8,td,s0,s4,s8,sd".split(","): self.check_function(getattr(self.module, name)) + class TestF90ReturnReal(TestReturnReal): suffix = ".f90" code = """ @@ -199,5 +203,4 @@ end module f90_return_real if __name__ == "__main__": - import nose - nose.runmodule() + run_module_suite() diff --git a/numpy/f2py/tests/test_size.py b/numpy/f2py/tests/test_size.py index e4f21b519..aeb70486a 100644 --- a/numpy/f2py/tests/test_size.py +++ b/numpy/f2py/tests/test_size.py @@ -1,19 +1,17 @@ from __future__ import division, absolute_import, print_function import os -import math - -from numpy.testing import * -from numpy import array +from numpy.testing import run_module_suite, assert_equal, dec import util + def _path(*a): return os.path.join(*((os.path.dirname(__file__),) + a)) + class TestSizeSumExample(util.F2PyTest): - sources = [_path('src', 'size', 'foo.f90'), - ] + sources = [_path('src', 'size', 'foo.f90')] @dec.slow def test_all(self): @@ -43,5 +41,4 @@ class TestSizeSumExample(util.F2PyTest): assert_equal(r, [1, 2, 3, 4, 5, 6], repr(r)) if __name__ == "__main__": - import nose - nose.runmodule() + run_module_suite() |