Skip to content

Commit 30ba774

Browse files
committed
Fix up tests except for actually failing one
1 parent b3aa299 commit 30ba774

6 files changed

Lines changed: 54 additions & 25 deletions

File tree

src/example_fgen_basic/fpyfgen/derived_type_manager_helpers.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ subroutine get_derived_type_free_instance_number(instance_index, n_instances, in
3333
class(BaseFinalisable), dimension(n_instances), intent(inout) :: instance_array
3434
!! Array of instances
3535

36-
integer :: i
36+
integer :: i = 1
3737

3838
! Default if no available models are found
3939
instance_index = invalid_instance_index

tests/unit/test_error_v.py

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,49 @@ def test_build_finalise():
2020

2121

2222
def test_build_finalise_multiple_instances_same_index():
23-
pytest.skip("TODO: turn back on")
2423
inst = ErrorV.from_build_args(code=2, message="Hello world")
2524

25+
original_instance_index = inst.instance_index
26+
2627
assert inst.code == 2
2728
assert inst.message == "Hello world"
2829

29-
inst_same_ptr = ErrorV(inst.instance_ptr)
30+
inst_same_index = ErrorV(inst.instance_index)
3031

31-
assert inst_same_ptr.code == 2
32-
assert inst_same_ptr.message == "Hello world"
32+
assert inst_same_index.code == 2
33+
assert inst_same_index.message == "Hello world"
3334
assert inst.initialised
34-
assert inst.is_associated
3535

3636
inst.finalise()
37-
inst_same_ptr.finalise()
37+
# # Currently this causes a hard stop.
38+
# # That's the right behaviour.
39+
# # We will make it not be a hard fail when we switch to result types.
40+
# inst_same_index.finalise()
3841
assert not inst.initialised
39-
assert not inst.is_associated
40-
41-
# Fun mess you can get yourself into if you use the same pointer
42-
# and it is finalised elsewhere
43-
assert inst_same_ptr.code != 2
44-
# This is true as the Python has no way of knowing
45-
# that it has been finalised elsewhere
46-
# (you basically need rust's borrow checker to not stuff this up)
47-
assert inst_same_ptr.initialised
48-
# This is how you can check for actual association
49-
# (given this, maybe want to change how `initialised` works)
50-
assert not inst_same_ptr.is_associated
42+
43+
### Problem 1 ###
44+
# # With the current implementation,
45+
# # finalising via `inst` does not cause `inst_same_index` to also be finalised
46+
# assert not inst_same_index.initialised
47+
48+
inst_new = ErrorV.from_build_args(code=3, message="Didn't expect this")
49+
# New instance uses the newly freed index.
50+
assert inst_new.instance_index == original_instance_index
51+
# Which means the new instance and the instance
52+
# which was initialised previously now have the same instance index
53+
assert inst_new.instance_index == inst_same_index.instance_index
54+
55+
### Problem 2 ###
56+
# So, if we look at `inst_same_index`'s attribute values, we get a surprise
57+
# The code isn't 2 as was set above.
58+
# Instead, the value has changed 'in the background' i.e. our view is 'stale'.
59+
assert inst_same_index.code == 3
60+
assert inst_same_index.message == "Didn't expect this"
61+
62+
# Something like this is what we actually want to happen
63+
# (if we try to access via inst_same_index again,
64+
# we get told that our view is out of date).
65+
# Could be warning or error, not sure what makes more sense...
66+
with pytest.raises(StaleViewError):
67+
inst_same_index.code
68+
inst_same_index.message

tests/unit/test_error_v_creation.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
(deliberately, just to see how it goes).
77
"""
88

9+
import re
10+
911
import pytest
1012
from IPython.lib.pretty import pretty
1113

@@ -54,6 +56,9 @@ def test_error_too_many_instances():
5456
create_error(1)
5557

5658

59+
@pytest.mark.xfail(
60+
reason="Not implemented yet - do in a future PR once we have a result type"
61+
)
5762
def test_increase_number_of_instances():
5863
raise NotImplementedError
5964
# - Make 4096 instances
@@ -66,16 +71,22 @@ def test_increase_number_of_instances():
6671
def test_error_str(file_regression):
6772
res = create_error(1.0)
6873

69-
file_regression.check(str(res))
74+
# Don't worry about the value of instance_index
75+
res_check = re.sub(r"instance_index=\d*", "instance_index=n", str(res))
76+
file_regression.check(res_check)
7077

7178

7279
def test_error_pprint(file_regression):
7380
res = create_error(1.0)
7481

75-
file_regression.check(pretty(res))
82+
# Don't worry about the value of instance_index
83+
res_check = re.sub(r"instance_index=\d*", "instance_index=n", pretty(res))
84+
file_regression.check(res_check)
7685

7786

7887
def test_error_html(file_regression):
7988
res = create_error(1.0)
8089

81-
file_regression.check(res._repr_html_(), extension=".html")
90+
# Don't worry about the value of instance_index
91+
res_check = re.sub(r"instance_index=\d*", "instance_index=n", res._repr_html_())
92+
file_regression.check(res_check, extension=".html")

tests/unit/test_error_v_creation/test_error_html.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<div class='fgen-wrap'>
3232
<div class='fgen-header'>
3333
<div class='fgen-basefinalizable-cls'>ErrorV</div>
34-
<div class='fgen-basefinalizable-instance-index'>instance_index=6</div>
34+
<div class='fgen-basefinalizable-instance-index'>instance_index=n</div>
3535
<table><tbody>
3636
<tr><th>code</th><td style='text-align:left;'>0</td></tr>
3737
<tr><th>message</th><td style='text-align:left;'></td></tr>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ErrorV(instance_index=5, code=0, message=)
1+
ErrorV(instance_index=n, code=0, message=)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ErrorV(instance_index=4, code=0, message=)
1+
ErrorV(instance_index=n, code=0, message=)

0 commit comments

Comments
 (0)