summaryrefslogtreecommitdiff
path: root/numpy/f2py/tests
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2020-03-26 19:44:29 +0200
committerGitHub <noreply@github.com>2020-03-26 19:44:29 +0200
commit5ff70eb0fd61a39207d5166479507e1b099cb707 (patch)
treef0bebbf93285969e33289994c6a70afb1e828b31 /numpy/f2py/tests
parentdfd4c9de8d849363e3d4cda7a0792ed0670165cf (diff)
parent0198fcfd4143edf8ec23f2e028044e17c3c93368 (diff)
downloadnumpy-5ff70eb0fd61a39207d5166479507e1b099cb707.tar.gz
Merge pull request #15781 from dcaliste/public
BUG: don't add 'public' or 'private' if the other one exists
Diffstat (limited to 'numpy/f2py/tests')
-rw-r--r--numpy/f2py/tests/test_crackfortran.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/numpy/f2py/tests/test_crackfortran.py b/numpy/f2py/tests/test_crackfortran.py
index 18a1474b0..735804024 100644
--- a/numpy/f2py/tests/test_crackfortran.py
+++ b/numpy/f2py/tests/test_crackfortran.py
@@ -1,6 +1,9 @@
import numpy as np
from numpy.testing import assert_array_equal
from . import util
+from numpy.f2py import crackfortran
+import tempfile
+import textwrap
class TestNoSpace(util.F2PyTest):
@@ -33,3 +36,53 @@ class TestNoSpace(util.F2PyTest):
self.module.subc([w, k])
assert_array_equal(k, w + 1)
assert self.module.t0(23) == b'2'
+
+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("""\
+ module foo
+ private
+ integer :: a
+ public :: setA
+ integer :: b
+ contains
+ subroutine setA(v)
+ integer, intent(in) :: v
+ a = v
+ end subroutine setA
+ end module foo
+ """))
+ mod = crackfortran.crackfortran([str(f_path)])
+ assert len(mod) == 1
+ mod = mod[0]
+ assert 'private' in mod['vars']['a']['attrspec']
+ assert 'public' not in mod['vars']['a']['attrspec']
+ assert 'private' in mod['vars']['b']['attrspec']
+ assert 'public' not in mod['vars']['b']['attrspec']
+ assert 'private' not in mod['vars']['seta']['attrspec']
+ assert 'public' in mod['vars']['seta']['attrspec']
+
+ def test_defaultPublic(self, tmp_path):
+ f_path = tmp_path / "mod.f90"
+ with f_path.open('w') as ff:
+ ff.write(textwrap.dedent("""\
+ module foo
+ public
+ integer, private :: a
+ public :: setA
+ contains
+ subroutine setA(v)
+ integer, intent(in) :: v
+ a = v
+ end subroutine setA
+ end module foo
+ """))
+ mod = crackfortran.crackfortran([str(f_path)])
+ assert len(mod) == 1
+ mod = mod[0]
+ assert 'private' in mod['vars']['a']['attrspec']
+ assert 'public' not in mod['vars']['a']['attrspec']
+ assert 'private' not in mod['vars']['seta']['attrspec']
+ assert 'public' in mod['vars']['seta']['attrspec']