diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2015-07-25 23:22:12 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2015-07-25 23:22:12 -0600 |
commit | 0fa1a9fa0a54fce6e741333308bdafa83c0663b2 (patch) | |
tree | 96ef2d826482ab52974efca8bfcf4c1940f3507b /numpy | |
parent | a0121573e6685f09e5f613280d616070b8ff99cb (diff) | |
download | numpy-0fa1a9fa0a54fce6e741333308bdafa83c0663b2.tar.gz |
STY: PEP8 fixes in numpy/f2py/tests.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/f2py/tests/test_array_from_pyobj.py | 2 | ||||
-rw-r--r-- | numpy/f2py/tests/test_callback.py | 36 | ||||
-rw-r--r-- | numpy/f2py/tests/test_kind.py | 4 | ||||
-rw-r--r-- | numpy/f2py/tests/test_mixed.py | 8 | ||||
-rw-r--r-- | numpy/f2py/tests/test_regression.py | 2 | ||||
-rw-r--r-- | numpy/f2py/tests/util.py | 18 |
6 files changed, 46 insertions, 24 deletions
diff --git a/numpy/f2py/tests/test_array_from_pyobj.py b/numpy/f2py/tests/test_array_from_pyobj.py index 21ed7c1fb..9551c099e 100644 --- a/numpy/f2py/tests/test_array_from_pyobj.py +++ b/numpy/f2py/tests/test_array_from_pyobj.py @@ -571,7 +571,7 @@ class _test_shared_memory: 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))) + array(54, dtype=self.type.dtype), repr((obj, a.arr))) assert_(a.arr is obj) assert_(obj.flags['FORTRAN']) # obj attributes changed inplace! assert_(not obj.flags['CONTIGUOUS']) diff --git a/numpy/f2py/tests/test_callback.py b/numpy/f2py/tests/test_callback.py index b3f21d351..6824a2042 100644 --- a/numpy/f2py/tests/test_callback.py +++ b/numpy/f2py/tests/test_callback.py @@ -7,6 +7,7 @@ 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) @@ -85,35 +86,38 @@ cf2py intent(out) a def check_function(self, name): t = getattr(self.module, name) - r = t(lambda : 4) - assert_( r==4, repr(r)) - r = t(lambda a:5, fun_extra_args=(6,)) - assert_( r==5, repr(r)) - r = t(lambda a:a, fun_extra_args=(6,)) - assert_( r==6, repr(r)) - r = t(lambda a:5+a, fun_extra_args=(7,)) - assert_( r==12, repr(r)) - r = t(lambda a:math.degrees(a), fun_extra_args=(math.pi,)) - assert_( r==180, repr(r)) + r = t(lambda: 4) + assert_(r == 4, repr(r)) + r = t(lambda a: 5, fun_extra_args=(6,)) + assert_(r == 5, repr(r)) + r = t(lambda a: a, fun_extra_args=(6,)) + assert_(r == 6, repr(r)) + r = t(lambda a: 5 + a, fun_extra_args=(7,)) + assert_(r == 12, repr(r)) + r = t(lambda a: math.degrees(a), fun_extra_args=(math.pi,)) + assert_(r == 180, repr(r)) r = t(math.degrees, fun_extra_args=(math.pi,)) - assert_( r==180, repr(r)) + assert_(r == 180, repr(r)) r = t(self.module.func, fun_extra_args=(6,)) - assert_( r==17, repr(r)) + assert_(r == 17, repr(r)) r = t(self.module.func0) - assert_( r==11, repr(r)) + assert_(r == 11, repr(r)) r = t(self.module.func0._cpointer) - assert_( r==11, repr(r)) + assert_(r == 11, repr(r)) + class A(object): + def __call__(self): return 7 + def mth(self): return 9 a = A() r = t(a) - assert_( r==7, repr(r)) + assert_(r == 7, repr(r)) r = t(a.mth) - assert_( r==9, repr(r)) + assert_(r == 9, repr(r)) def test_string_callback(self): diff --git a/numpy/f2py/tests/test_kind.py b/numpy/f2py/tests/test_kind.py index 7426b9853..2552234a1 100644 --- a/numpy/f2py/tests/test_kind.py +++ b/numpy/f2py/tests/test_kind.py @@ -25,12 +25,12 @@ class TestKind(util.F2PyTest): 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))) + (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))) + (i, selected_real_kind(i), selectedrealkind(i))) if __name__ == "__main__": run_module_suite() diff --git a/numpy/f2py/tests/test_mixed.py b/numpy/f2py/tests/test_mixed.py index cfc669840..9055083bf 100644 --- a/numpy/f2py/tests/test_mixed.py +++ b/numpy/f2py/tests/test_mixed.py @@ -6,9 +6,11 @@ import textwrap from numpy.testing import run_module_suite, assert_, assert_equal, dec import util + def _path(*a): return os.path.join(*((os.path.dirname(__file__),) + a)) + class TestMixed(util.F2PyTest): sources = [_path('src', 'mixed', 'foo.f'), _path('src', 'mixed', 'foo_fixed.f90'), @@ -16,9 +18,9 @@ class TestMixed(util.F2PyTest): @dec.slow def test_all(self): - assert_( self.module.bar11() == 11) - assert_( self.module.foo_fixed.bar12() == 12) - assert_( self.module.foo_free.bar13() == 13) + assert_(self.module.bar11() == 11) + assert_(self.module.foo_fixed.bar12() == 12) + assert_(self.module.foo_free.bar13() == 13) @dec.slow def test_docstring(self): diff --git a/numpy/f2py/tests/test_regression.py b/numpy/f2py/tests/test_regression.py index 9bd3f3fe3..b30af0c4c 100644 --- a/numpy/f2py/tests/test_regression.py +++ b/numpy/f2py/tests/test_regression.py @@ -8,9 +8,11 @@ from numpy.testing import dec, assert_raises, assert_equal import util + def _path(*a): return os.path.join(*((os.path.dirname(__file__),) + a)) + class TestIntentInOut(util.F2PyTest): # Check that intent(in out) translates as intent(inout) sources = [_path('src', 'regression', 'inout.f90')] diff --git a/numpy/f2py/tests/util.py b/numpy/f2py/tests/util.py index 56aff2b66..5b4e072e7 100644 --- a/numpy/f2py/tests/util.py +++ b/numpy/f2py/tests/util.py @@ -33,6 +33,7 @@ except ImportError: _module_dir = None + def _cleanup(): global _module_dir if _module_dir is not None: @@ -46,6 +47,7 @@ def _cleanup(): pass _module_dir = None + def get_module_dir(): global _module_dir if _module_dir is None: @@ -55,18 +57,21 @@ def get_module_dir(): sys.path.insert(0, _module_dir) return _module_dir + def get_temp_module_name(): # Assume single-threaded, and the module dir usable only by this thread d = get_module_dir() for j in range(5403, 9999999): name = "_test_ext_module_%d" % j fn = os.path.join(d, name) - if name not in sys.modules and not os.path.isfile(fn+'.py'): + if name not in sys.modules and not os.path.isfile(fn + '.py'): return name raise RuntimeError("Failed to create a temporary module name") + def _memoize(func): memo = {} + def wrapper(*a, **kw): key = repr((a, kw)) if key not in memo: @@ -86,6 +91,7 @@ def _memoize(func): # Building modules # + @_memoize def build_module(source_files, options=[], skip=[], only=[], module_name=None): """ @@ -144,6 +150,7 @@ def build_module(source_files, options=[], skip=[], only=[], module_name=None): __import__(module_name) return sys.modules[module_name] + @_memoize def build_code(source_code, options=[], skip=[], only=[], suffix=None, module_name=None): @@ -169,6 +176,8 @@ def build_code(source_code, options=[], skip=[], only=[], suffix=None, # _compiler_status = None + + def _get_compiler_status(): global _compiler_status if _compiler_status is not None: @@ -220,12 +229,15 @@ sys.exit(99) # Finished return _compiler_status + def has_c_compiler(): return _get_compiler_status()[0] + def has_f77_compiler(): return _get_compiler_status()[1] + def has_f90_compiler(): return _get_compiler_status()[2] @@ -233,6 +245,7 @@ def has_f90_compiler(): # Building with distutils # + @_memoize def build_module_distutils(source_files, config_code, module_name, **kw): """ @@ -270,7 +283,7 @@ def configuration(parent_name='',top_path=None): if __name__ == "__main__": from numpy.distutils.core import setup setup(configuration=configuration) -""" % dict(config_code=config_code, syspath = repr(sys.path)) +""" % dict(config_code=config_code, syspath=repr(sys.path)) script = os.path.join(d, get_temp_module_name() + '.py') dst_sources.append(script) @@ -304,6 +317,7 @@ if __name__ == "__main__": # Unittest convenience # + class F2PyTest(object): code = None sources = None |