diff options
author | Matti Picus <matti.picus@gmail.com> | 2021-07-08 23:55:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-08 15:55:22 -0500 |
commit | 882f00bd47ceacbbcf34cad5d491be43fee0c99e (patch) | |
tree | ce212e48957891ab1e0362dc4553af0572a0acbb /numpy/f2py/tests | |
parent | edb880dd9b3c7241b96ccef34c43bd9f90e4a6e4 (diff) | |
download | numpy-882f00bd47ceacbbcf34cad5d491be43fee0c99e.tar.gz |
BUG: f2py markinnerspace for multiple quotations (#19419)
Continuation of #15208
* BUG: markinnerspaces does not handle multiple quotations
* TST: test for markinnerspaces in f2py.crackfortran
* TST: tests for markinnerspaces with "
* DOC: markinnerspaces in f2py.crackfortran
* MAINT: more readable r strings in TestMarkinnerspaces
* ENH: give variables names, change 'inside' to bool
* :TEST, MAINT: add tests and changes from review
* MAINT: lint fixes
* BUG: typo
Co-authored-by: bdvd <bdvd001@gmail.com>
Diffstat (limited to 'numpy/f2py/tests')
-rw-r--r-- | numpy/f2py/tests/test_crackfortran.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/numpy/f2py/tests/test_crackfortran.py b/numpy/f2py/tests/test_crackfortran.py index d26917f0c..140f42cbc 100644 --- a/numpy/f2py/tests/test_crackfortran.py +++ b/numpy/f2py/tests/test_crackfortran.py @@ -1,8 +1,8 @@ import numpy as np -from numpy.testing import assert_array_equal +from numpy.testing import assert_array_equal, assert_equal +from numpy.f2py.crackfortran import markinnerspaces from . import util from numpy.f2py import crackfortran -import tempfile import textwrap @@ -37,6 +37,7 @@ class TestNoSpace(util.F2PyTest): 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" @@ -87,6 +88,7 @@ class TestPublicPrivate(): assert 'private' not in mod['vars']['seta']['attrspec'] assert 'public' in mod['vars']['seta']['attrspec'] + class TestExternal(util.F2PyTest): # issue gh-17859: add external attribute support code = """ @@ -116,6 +118,7 @@ class TestExternal(util.F2PyTest): r = self.module.external_as_attribute(incr) assert r == 123 + class TestCrackFortran(util.F2PyTest): suffix = '.f90' @@ -139,3 +142,26 @@ class TestCrackFortran(util.F2PyTest): def test_gh2848(self): r = self.module.gh2848(1, 2) assert r == (1, 2) + + +class TestMarkinnerspaces(): + # issue #14118: markinnerspaces does not handle multiple quotations + + def test_do_not_touch_normal_spaces(self): + test_list = ["a ", " a", "a b c", "'abcdefghij'"] + for i in test_list: + assert_equal(markinnerspaces(i), i) + + def test_one_relevant_space(self): + assert_equal(markinnerspaces("a 'b c' \\\' \\\'"), "a 'b@_@c' \\' \\'") + assert_equal(markinnerspaces(r'a "b c" \" \"'), r'a "b@_@c" \" \"') + + def test_ignore_inner_quotes(self): + assert_equal(markinnerspaces('a \'b c" " d\' e'), + "a 'b@_@c\"@_@\"@_@d' e") + assert_equal(markinnerspaces('a "b c\' \' d" e'), + "a \"b@_@c'@_@'@_@d\" e") + + def test_multiple_relevant_spaces(self): + assert_equal(markinnerspaces("a 'b c' 'd e'"), "a 'b@_@c' 'd@_@e'") + assert_equal(markinnerspaces(r'a "b c" "d e"'), r'a "b@_@c" "d@_@e"') |