summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRohit Goswami <rog32@hi.is>2021-12-05 20:41:31 +0000
committerRohit Goswami <rog32@hi.is>2021-12-05 22:27:27 +0000
commit90e20e58eda7547678c6d2a4c121b0317de9c74d (patch)
treee0e3a0302f50d5822610bf809e24c5dca87f75a1
parente4ca1fbcc96f956708f2deacb6ae1806cd132fe5 (diff)
downloadnumpy-90e20e58eda7547678c6d2a4c121b0317de9c74d.tar.gz
MAINT: Update to better python styles
Co-authored-by: Pearu Peterson <pearu.peterson@gmail.com>
-rw-r--r--numpy/f2py/tests/test_array_from_pyobj.py28
-rw-r--r--numpy/f2py/tests/test_crackfortran.py5
-rw-r--r--numpy/f2py/tests/test_semicolon_split.py16
-rw-r--r--numpy/f2py/tests/util.py39
4 files changed, 43 insertions, 45 deletions
diff --git a/numpy/f2py/tests/test_array_from_pyobj.py b/numpy/f2py/tests/test_array_from_pyobj.py
index 26060561a..78569a8d6 100644
--- a/numpy/f2py/tests/test_array_from_pyobj.py
+++ b/numpy/f2py/tests/test_array_from_pyobj.py
@@ -401,8 +401,8 @@ class TestSharedMemory:
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")
@@ -418,8 +418,8 @@ class TestSharedMemory:
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(
@@ -508,8 +508,8 @@ class TestSharedMemory:
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(
@@ -524,8 +524,8 @@ class TestSharedMemory:
try:
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(
@@ -544,8 +544,8 @@ class TestSharedMemory:
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(
@@ -573,12 +573,12 @@ class TestSharedMemory:
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, )
diff --git a/numpy/f2py/tests/test_crackfortran.py b/numpy/f2py/tests/test_crackfortran.py
index a9a818155..41d9840ed 100644
--- a/numpy/f2py/tests/test_crackfortran.py
+++ b/numpy/f2py/tests/test_crackfortran.py
@@ -42,9 +42,8 @@ class TestNoSpace(util.F2PyTest):
class TestPublicPrivate:
def test_defaultPrivate(self, tmp_path):
f_path = tmp_path / "mod.f90"
- with f_path.open("w") as ff:
- ff.write(
- textwrap.dedent("""\
+ f_path.write_text(
+ textwrap.dedent("""\
module foo
private
integer :: a
diff --git a/numpy/f2py/tests/test_semicolon_split.py b/numpy/f2py/tests/test_semicolon_split.py
index 138ba85a8..745c472f8 100644
--- a/numpy/f2py/tests/test_semicolon_split.py
+++ b/numpy/f2py/tests/test_semicolon_split.py
@@ -13,8 +13,8 @@ from numpy.testing import assert_equal
class TestMultiline(util.F2PyTest):
suffix = ".pyf"
module_name = "multiline"
- code = """
-python module {module}
+ code = f"""
+python module {module_name}
usercode '''
void foo(int* x) {{
char dummy = ';';
@@ -27,8 +27,8 @@ void foo(int* x) {{
integer intent(out) :: x
end subroutine foo
end interface
-end python module {module}
- """.format(module=module_name)
+end python module {module_name}
+ """
def test_multiline(self):
assert_equal(self.module.foo(), 42)
@@ -42,8 +42,8 @@ end python module {module}
class TestCallstatement(util.F2PyTest):
suffix = ".pyf"
module_name = "callstatement"
- code = """
-python module {module}
+ code = f"""
+python module {module_name}
usercode '''
void foo(int* x) {{
}}
@@ -59,8 +59,8 @@ void foo(int* x) {{
}}
end subroutine foo
end interface
-end python module {module}
- """.format(module=module_name)
+end python module {module_name}
+ """
def test_callstatement(self):
assert_equal(self.module.foo(), 42)
diff --git a/numpy/f2py/tests/util.py b/numpy/f2py/tests/util.py
index 069a27905..c115970f4 100644
--- a/numpy/f2py/tests/util.py
+++ b/numpy/f2py/tests/util.py
@@ -16,6 +16,7 @@ import textwrap
import re
import pytest
import contextlib
+import numpy
from pathlib import Path
from numpy.compat import asbytes, asstr
@@ -98,8 +99,7 @@ def build_module(source_files, options=[], skip=[], only=[], module_name=None):
"""
- code = "import sys; sys.path = %s; import numpy.f2py; " "numpy.f2py.main()" % repr(
- sys.path)
+ code = f"import sys; sys.path = {sys.path!r}; import numpy.f2py; numpy.f2py.main()"
d = get_module_dir()
@@ -188,10 +188,10 @@ def _get_compiler_status():
# XXX: this is really ugly. But I don't know how to invoke Distutils
# in a safer way...
- code = textwrap.dedent("""\
+ code = textwrap.dedent(f"""\
import os
import sys
- sys.path = %(syspath)s
+ sys.path = {repr(sys.path)}
def configuration(parent_name='',top_path=None):
global config
@@ -203,7 +203,7 @@ def _get_compiler_status():
setup(configuration=configuration)
config_cmd = config.get_config_cmd()
- have_c = config_cmd.try_compile('void foo() {}')
+ have_c = config_cmd.try_compile('void foo() {{}}')
print('COMPILERS:%%d,%%d,%%d' %% (have_c,
config.have_f77c(),
config.have_f90c()))
@@ -275,22 +275,21 @@ def build_module_distutils(source_files, config_code, module_name, **kw):
# Build script
config_code = textwrap.dedent(config_code).replace("\n", "\n ")
- code = (textwrap.dedent("""\
- import os
- import sys
- sys.path = %(syspath)s
-
- def configuration(parent_name='',top_path=None):
- from numpy.distutils.misc_util import Configuration
- config = Configuration('', parent_name, top_path)
- %(config_code)s
- return config
+ code = fr"""
+import os
+import sys
+sys.path = {repr(sys.path)}
- if __name__ == "__main__":
- from numpy.distutils.core import setup
- setup(configuration=configuration)
- """) % dict(config_code=config_code, syspath=repr(sys.path)))
+def configuration(parent_name='',top_path=None):
+ from numpy.distutils.misc_util import Configuration
+ config = Configuration('', parent_name, top_path)
+ {config_code}
+ return config
+if __name__ == "__main__":
+ from numpy.distutils.core import setup
+ setup(configuration=configuration)
+ """
script = os.path.join(d, get_temp_module_name() + ".py")
dst_sources.append(script)
with open(script, "wb") as f:
@@ -392,7 +391,7 @@ class F2PyTest:
def getpath(*a):
# Package root
- d = Path(__file__).parent.parent.resolve()
+ d = Path(numpy.f2py.__file__).parent.resolve()
return d.joinpath(*a)