Skip to content

Commit

Permalink
Add test case for #56
Browse files Browse the repository at this point in the history
  • Loading branch information
rjfarmer committed Feb 29, 2024
1 parent da40381 commit b8497f9
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/gh56.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@


! SPDX-License-Identifier: GPL-2.0+

module gh56

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)


public :: get_array, print3, my_t

type my_t
real, allocatable :: d(:)
integer :: n
end type

contains

function get_array(N) result(retval)
type(my_t) :: retval
integer, intent(in) :: N
integer :: i

allocate( retval%d(N) )
retval%n = N

! substitute with real data
do i=1,N
retval% d(i) = i
end do
end function

subroutine print3(x)
type(my_t), intent(in) :: x
print *, x%d(:3)
end subroutine



end module gh56


34 changes: 34 additions & 0 deletions tests/gh56_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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/gh56.{gf.lib_ext()}"
MOD = "./tests/gh56.mod"

x = gf.fFort(SO, MOD)


@pytest.mark.skip("Not fixed yet")
class Testgh56Methods:
def test_gh56(self, capfd):
y1 = x.get_array(10).result

y2 = x.get_array(5).result

assert len(y1["d"]) == 10
assert len(y2["d"]) == 5

assert y1["d"] == np.array(
[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0], dtype=np.float32
)

assert y2["d"] == np.array([1.0, 2.0, 3.0, 4.0, 5.0], dtype=np.float32)

0 comments on commit b8497f9

Please sign in to comment.