Skip to content

Commit b267d06

Browse files
committed
Add tests and compilation
1 parent eda78aa commit b267d06

11 files changed

Lines changed: 170 additions & 17 deletions

File tree

meson.build

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,10 @@ if pyprojectwheelbuild_enabled
147147
# this is where that operation happens.
148148
# Files get copied to <python directory>/site-packages/<subdir>
149149
foreach python_src : python_srcs
150-
message(python_src)
151-
message(python_project_name)
152-
message(fs.relative_to(python_src, python_project_name))
150+
message(fs.relative_to(python_src, 'src' / python_project_name))
153151
py.install_sources(
154152
python_src,
155-
subdir: python_project_name / fs.relative_to(python_src, python_project_name),
153+
subdir: fs.parent(fs.relative_to(python_src, 'src')),
156154
pure: false,
157155
)
158156

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ tests-min = [
9999
# Key dependencies
100100
# ----------------
101101
"pytest>=8.3.4",
102+
"pytest-regressions>=2.8.2",
102103
]
103104
# Full test dependencies.
104105
tests-full = [
@@ -112,6 +113,7 @@ tests-full = [
112113
tests = [
113114
{include-group = "tests-min"},
114115
{include-group = "tests-full"},
116+
"ipython>=8.18.1",
115117
]
116118
all-dev = [
117119
{include-group = "dev"},

requirements-only-tests-locked.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
# This file was autogenerated by uv via the following command:
22
# uv export -o requirements-only-tests-locked.txt --no-hashes --no-dev --no-emit-project --only-group tests
3+
asttokens==3.0.0
34
colorama==0.4.6 ; sys_platform == 'win32'
45
coverage==7.6.10
6+
decorator==5.1.1
57
exceptiongroup==1.3.0 ; python_full_version < '3.11'
8+
executing==2.1.0
69
iniconfig==2.0.0
10+
ipython==8.18.1 ; python_full_version < '3.10'
11+
ipython==8.37.0 ; python_full_version == '3.10.*'
12+
ipython==9.4.0 ; python_full_version >= '3.11'
13+
ipython-pygments-lexers==1.1.1 ; python_full_version >= '3.11'
14+
jedi==0.19.2
15+
matplotlib-inline==0.1.7
716
packaging==24.2
17+
parso==0.8.4
18+
pexpect==4.9.0 ; (python_full_version < '3.10' and sys_platform == 'emscripten') or (sys_platform != 'emscripten' and sys_platform != 'win32')
819
pluggy==1.5.0
20+
prompt-toolkit==3.0.48
21+
ptyprocess==0.7.0 ; (python_full_version < '3.10' and sys_platform == 'emscripten') or (sys_platform != 'emscripten' and sys_platform != 'win32')
22+
pure-eval==0.2.3
23+
pygments==2.19.1
924
pytest==8.3.4
1025
pytest-cov==6.0.0
26+
pytest-datadir==1.8.0
27+
pytest-regressions==2.8.2
28+
pyyaml==6.0.2
29+
stack-data==0.6.3
1130
tomli==2.2.1 ; python_full_version <= '3.11'
12-
typing-extensions==4.12.2 ; python_full_version < '3.11'
31+
traitlets==5.14.3
32+
typing-extensions==4.12.2 ; python_full_version < '3.12'
33+
wcwidth==0.2.13

requirements-only-tests-min-locked.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ iniconfig==2.0.0
66
packaging==24.2
77
pluggy==1.5.0
88
pytest==8.3.4
9+
pytest-datadir==1.8.0
10+
pytest-regressions==2.8.2
11+
pyyaml==6.0.2
912
tomli==2.2.1 ; python_full_version < '3.11'
1013
typing-extensions==4.12.2 ; python_full_version < '3.11'

src/example_fgen_basic/error_v/creation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
from example_fgen_basic.pyfgen_runtime.exceptions import CompiledExtensionNotFoundError
99

1010
try:
11-
from example._lib import ( # type: ignore
11+
from example_fgen_basic._lib import ( # type: ignore
1212
m_error_v_creation_w,
1313
)
14-
except (ModuleNotFoundError, ImportError) as exc:
14+
except (ModuleNotFoundError, ImportError) as exc: # pragma: no cover
1515
raise CompiledExtensionNotFoundError("example._lib.m_error_v_creation_w") from exc
1616

1717

src/example_fgen_basic/error_v/error_v.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from __future__ import annotations
66

7+
from typing import Any
8+
79
from attrs import define
810

911
from example_fgen_basic.pyfgen_runtime.base_finalisable import (
@@ -13,10 +15,10 @@
1315
from example_fgen_basic.pyfgen_runtime.exceptions import CompiledExtensionNotFoundError
1416

1517
try:
16-
from example._lib import ( # type: ignore
18+
from example_fgen_basic._lib import ( # type: ignore
1719
m_error_v_creation_w,
1820
)
19-
except (ModuleNotFoundError, ImportError) as exc:
21+
except (ModuleNotFoundError, ImportError) as exc: # pragma: no cover
2022
raise CompiledExtensionNotFoundError("example._lib.m_error_v_creation_w") from exc
2123

2224

@@ -26,6 +28,15 @@ class ErrorV(FinalisableWrapperBase):
2628
TODO: auto docstring e.g. "Wrapper around the Fortran :class:`ErrorV`"
2729
"""
2830

31+
# Bug in Ipython pretty hence have to put this on every object?
32+
def _repr_pretty_(self, p: Any, cycle: bool) -> None:
33+
"""
34+
Get pretty representation of self
35+
36+
Used by IPython notebooks and other tools
37+
"""
38+
super()._repr_pretty_(p=p, cycle=cycle)
39+
2940
@property
3041
def exposed_attributes(self) -> tuple[str, ...]:
3142
"""

tests/unit/test_error_v_creation.py

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

9+
import pytest
10+
from IPython.lib.pretty import pretty
11+
912
from example_fgen_basic.error_v import ErrorV
1013
from example_fgen_basic.error_v.creation import create_error
1114

@@ -38,10 +41,40 @@ def test_create_error_negative():
3841
assert res.message == "Negative number supplied"
3942

4043

41-
# Tests to write:
42-
# - if we create more errors than we have available, we don't segfault.
43-
# Instead, we should get an error back.
44-
# That error should just use the instance ID of the last available array index
45-
# (it is ok to overwrite an already used error to avoid a complete failure,
46-
# but we should probably include that we did this in the error message).
47-
# - we can resize the available number of error instances to avoid hitting limits
44+
def test_error_too_many_instances():
45+
pytest.skip("Causes segfault right now")
46+
# - if we create more errors than we have available, we don't segfault.
47+
# Instead, we should get an error back.
48+
# That error should just use the instance ID of the last available array index
49+
# (it is ok to overwrite an already used error to avoid a complete failure,
50+
# but we should probably include that we did this in the error message).
51+
# TODO: expect error here
52+
for _ in range(4097):
53+
create_error(1)
54+
55+
56+
def test_increase_number_of_instances():
57+
raise NotImplementedError
58+
# - Make 4096 instances
59+
# - show that making one more raises an error
60+
# - increase number of instances
61+
# - show that making one more now works without error
62+
63+
64+
# Some test to illustrate what the formatting does
65+
def test_error_str(file_regression):
66+
res = create_error(1.0)
67+
68+
file_regression.check(str(res))
69+
70+
71+
def test_error_pprint(file_regression):
72+
res = create_error(1.0)
73+
74+
file_regression.check(pretty(res))
75+
76+
77+
def test_error_html(file_regression):
78+
res = create_error(1.0)
79+
80+
file_regression.check(res._repr_html_(), extension=".html")
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<div>
2+
<style>
3+
.fgen-wrap {
4+
/*font-family: monospace;*/
5+
width: 540px;
6+
}
7+
8+
.fgen-header {
9+
padding: 6px 0 6px 3px;
10+
border-bottom: solid 1px #777;
11+
color: #555;;
12+
}
13+
14+
.fgen-header > div {
15+
display: inline;
16+
margin-top: 0;
17+
margin-bottom: 0;
18+
}
19+
20+
.fgen-basefinalizable-cls,
21+
.fgen-basefinalizable-instance-index {
22+
margin-left: 2px;
23+
margin-right: 10px;
24+
}
25+
26+
.fgen-basefinalizable-cls {
27+
font-weight: bold;
28+
color: #000000;
29+
}
30+
</style>
31+
<div class='fgen-wrap'>
32+
<div class='fgen-header'>
33+
<div class='fgen-basefinalizable-cls'>ErrorV</div>
34+
<div class='fgen-basefinalizable-instance-index'>instance_index=6</div>
35+
<table><tbody>
36+
<tr><th>code</th><td style='text-align:left;'>0</td></tr>
37+
<tr><th>message</th><td style='text-align:left;'></td></tr>
38+
</tbody></table>
39+
</div>
40+
</div>
41+
</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ErrorV(instance_index=5, code=0, message=)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ErrorV(instance_index=4, code=0, message=)

0 commit comments

Comments
 (0)