Skip to content

Commit

Permalink
Move test case to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
rjfarmer committed Feb 29, 2024
1 parent 0776fd3 commit 65db252
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 27 deletions.
30 changes: 30 additions & 0 deletions tests/gh55.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@


! SPDX-License-Identifier: GPL-2.0+

module gh55

use iso_fortran_env, only: output_unit, real128

implicit none

! Parameters
integer, parameter :: dp = selected_real_kind(p=15)
integer, parameter :: qp = selected_real_kind(p=30)
integer, parameter :: lp = selected_int_kind(16)


contains

recursive function return_char(x) result(str)
integer, intent(in) :: x
character(len=10), dimension((2 ** x - 1) ) :: str

str = ''
str(2**x-1) = 'abcdefghil'

end function return_char

end module gh55


30 changes: 30 additions & 0 deletions tests/gh55_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SPDX-License-Identifier: GPL-2.0+

import os, sys
import ctypes
from pprint import pprint

os.environ["_GFORT2PY_TEST_FLAG"] = "1"

import numpy as np
import gfort2py as gf

import pytest

SO = f"./tests/gh55.{gf.lib_ext()}"
MOD = "./tests/gh55.mod"

x = gf.fFort(SO, MOD)


@pytest.mark.skip("Currently broken needs array descriptor for strings")
class Testgh55Methods:
def test_func_str_return_array(self):

size = 3
res = x.return_char(size)

return_str = res.result

assert np.size(np.shape(return_str)) == ((2**size) - 1)
assert return_str[-1] == "abcdefghij"
2 changes: 1 addition & 1 deletion tests/make_new_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def make_test_case(name):
SO = f"./tests/{name}.{{gf.lib_ext()}}"
MOD = "./tests/{name}.mod"
x=gf.fFort(SO,MOD)
x = gf.fFort(SO,MOD)
class Test{name}Methods:
Expand Down
26 changes: 0 additions & 26 deletions tests/strings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,29 +309,3 @@ def test_check_str_opt(self):

res = x.check_str_opt("abcd", 4)
assert res.result == 4

@pytest.mark.skip("Currently under development")
def test_func_str_return_array(self):
fstr = """
recursive function return_char(x) result(str)
implicit none
integer, intent(in) :: x
character(len=10), dimension((2 ** x - 1) ) :: str
str = ''
str(2**x-1) = 'abcdefghil'
end function return_char
"""

size = 2
z = gf.compile(fstr)

res = z.return_char(size)

return_str = res.result

assert np.size(np.shape(return_str)) == ((2**size) - 1)
assert return_str[-1] == "abcdefghij"

0 comments on commit 65db252

Please sign in to comment.