Skip to content

Commit 31ebe4c

Browse files
committed
Pass error raising test
1 parent 9dc7b3f commit 31ebe4c

4 files changed

Lines changed: 13 additions & 11 deletions

File tree

src/example_fgen_basic/get_square_root.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,23 @@ def get_square_root(inv: float) -> float:
4747
TODO: use a more specific error
4848
"""
4949
result_instance_index: int = m_get_square_root_w.get_square_root(inv)
50-
5150
result = ResultDP.from_instance_index(result_instance_index)
5251

5352
if result.has_error:
5453
# TODO: be more specific
5554
raise FortranError(result.error_v.message)
55+
# raise LessThanZeroError(result.error_v.message)
5656

5757
res = result.data_v
5858

59+
# TODO: think
60+
# I like the clarity of finalising result_instance_index here
61+
# by having an explicit call
62+
# (so you can see creation and finalisation in same place).
63+
# (Probably the above is my preferred right now, but we should think about it.)
64+
# I like the safety of finalising in `from_instance_index`.
65+
# if not finalised(result_instance_index):
66+
# finalise(result_instance_index)
5967
m_result_dp_w.finalise_instance(result_instance_index)
6068

6169
return res

src/example_fgen_basic/get_square_root_wrapper.f90

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ function get_square_root(inv) result(res_instance_index)
4242
! ready for its attributes to be retrieved from Python.
4343
call result_dp_manager_set_instance_index_to(res_instance_index, res)
4444

45-
print *, "res_instance_index"
46-
print *, res_instance_index
47-
print *, "res % data_v"
48-
print *, res % data_v
49-
5045
end function get_square_root
5146

5247
end module m_get_square_root_w

src/example_fgen_basic/result/result_dp_wrapper.f90

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module m_result_dp_w
77
! The manager module, which makes this all work
88
use m_error_v_manager, only: &
99
error_v_manager_get_instance => get_instance, &
10+
error_v_manager_ensure_instance_array_size_is_at_least => ensure_instance_array_size_is_at_least, &
1011
error_v_manager_get_available_instance_index => get_available_instance_index, &
1112
error_v_manager_set_instance_index_to => set_instance_index_to
1213

@@ -137,13 +138,9 @@ subroutine get_data_v( &
137138

138139
type(ResultDP) :: instance
139140

140-
print *, "instance_index"
141-
print *, instance_index
142141
instance = result_dp_manager_get_instance(instance_index)
143142

144143
data_v = instance % data_v
145-
print *, "instance % data_v"
146-
print *, instance % data_v
147144

148145
end subroutine get_data_v
149146

@@ -181,6 +178,8 @@ subroutine get_error_v( &
181178
instance = result_dp_manager_get_instance(instance_index)
182179

183180
error_v = instance % error_v
181+
182+
call error_v_manager_ensure_instance_array_size_is_at_least(1)
184183
call error_v_manager_get_available_instance_index(error_v_instance_index)
185184
call error_v_manager_set_instance_index_to(error_v_instance_index, error_v)
186185

tests/unit/test_get_square_root.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"inv, exp, exp_error",
1313
(
1414
(4.0, 2.0, None),
15-
(-4.0, None, pytest.raises(FortranError, match="inv is negative")),
15+
(-4.0, None, pytest.raises(FortranError, match="Input value was negative")),
1616
),
1717
)
1818
def test_basic(inv, exp, exp_error):

0 commit comments

Comments
 (0)