Skip to content

Commit 1069a0c

Browse files
committed
Add first set of tests
1 parent 8006dda commit 1069a0c

File tree

2 files changed

+24
-120
lines changed

2 files changed

+24
-120
lines changed

tests/unit/test_error_v.py

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
"""
22
Tests of `example_fgen_basic.error_v.creation`
3-
4-
Note that this is the only test of the Fortran code.
5-
I haven't written unit tests for the Fortran directly
6-
(deliberately, just to see how it goes).
73
"""
84

9-
import re
10-
11-
import pytest
12-
from IPython.lib.pretty import pretty
5+
import numpy as np
136

147
from example_fgen_basic.error_v import ErrorV
15-
from example_fgen_basic.error_v.creation import create_error
8+
from example_fgen_basic.error_v.creation import create_error, create_errors
9+
10+
# Tests to write:
11+
# - passing derived types to Fortran (new test module)
12+
# - retrieving multiple derived type instances from Fortran
13+
# (basically checking the manager's auto-resizing of the number of instances)
1614

1715

1816
def test_create_error_odd():
@@ -43,50 +41,24 @@ def test_create_error_negative():
4341
assert res.message == "Negative number supplied"
4442

4543

46-
def test_error_too_many_instances():
47-
# @Marco we will fix this when we introduce a result type in a future step
48-
pytest.skip("Causes segfault right now")
49-
# - if we create more errors than we have available, we don't segfault.
50-
# Instead, we should get an error back.
51-
# That error should just use the instance ID of the last available array index
52-
# (it is ok to overwrite an already used error to avoid a complete failure,
53-
# but we should probably include that we did this in the error message).
54-
# TODO: expect error here
55-
for _ in range(4097):
44+
def test_create_error_lots_of_repeated_calls():
45+
# We should be able to just keep calling `create_error`
46+
# without hitting segfaults or other weirdness.
47+
# This is basically testing that we're freeing the temporary
48+
# Fortran derived types correctly
49+
# (and sort of a speed test, this shouldn't be noticeably slow)
50+
# hence we may move this test somewhere more generic at some point.
51+
for _ in range(1e5):
5652
create_error(1)
5753

5854

59-
@pytest.mark.xfail(
60-
reason="Not implemented yet - do in a future PR once we have a result type"
61-
)
62-
def test_increase_number_of_instances():
63-
raise NotImplementedError
64-
# - Make 4096 instances
65-
# - show that making one more raises an error
66-
# - increase number of instances
67-
# - show that making one more now works without error
68-
69-
70-
# Some test to illustrate what the formatting does
71-
def test_error_str(file_regression):
72-
res = create_error(1.0)
73-
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)
77-
78-
79-
def test_error_pprint(file_regression):
80-
res = create_error(1.0)
81-
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)
85-
86-
87-
def test_error_html(file_regression):
88-
res = create_error(1.0)
55+
def test_create_multiple_errors():
56+
res = create_errors(np.arange(6))
8957

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")
58+
for i, v in enumerate(res):
59+
if i % 2 == 0:
60+
assert res.code == 1
61+
assert res.message == "Even number supplied"
62+
else:
63+
assert res.code == 0
64+
assert res.message == ""

0 commit comments

Comments
 (0)