Skip to content

Commit eb193e4

Browse files
committed
Increase integration test coverage
1 parent 75d48ec commit eb193e4

6 files changed

Lines changed: 412 additions & 1 deletion

File tree

pixi.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ docstring-coverage = 'interrogate -c pyproject.toml src/easydiffraction'
168168
cov = { depends-on = [
169169
'docstring-coverage',
170170
'unit-tests-coverage',
171-
'functional-tests-coverage',
172171
'integration-tests-coverage',
173172
] }
174173

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# SPDX-FileCopyrightText: 2026 EasyScience contributors <https://github.com/easyscience>
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
"""Shared fixtures for integration tests."""
5+
6+
import tempfile
7+
8+
import pytest
9+
10+
from easydiffraction import ExperimentFactory
11+
from easydiffraction import Project
12+
from easydiffraction import StructureFactory
13+
from easydiffraction import download_data
14+
15+
TEMP_DIR = tempfile.gettempdir()
16+
17+
18+
@pytest.fixture(scope='session')
19+
def lbco_fitted_project():
20+
"""Build and fit an LBCO CWL project (session-scoped for reuse)."""
21+
model = StructureFactory.from_scratch(name='lbco')
22+
model.space_group.name_h_m = 'P m -3 m'
23+
model.cell.length_a = 3.88
24+
model.atom_sites.create(
25+
label='La',
26+
type_symbol='La',
27+
fract_x=0,
28+
fract_y=0,
29+
fract_z=0,
30+
wyckoff_letter='a',
31+
occupancy=0.5,
32+
b_iso=0.1,
33+
)
34+
model.atom_sites.create(
35+
label='Ba',
36+
type_symbol='Ba',
37+
fract_x=0,
38+
fract_y=0,
39+
fract_z=0,
40+
wyckoff_letter='a',
41+
occupancy=0.5,
42+
b_iso=0.1,
43+
)
44+
model.atom_sites.create(
45+
label='Co',
46+
type_symbol='Co',
47+
fract_x=0.5,
48+
fract_y=0.5,
49+
fract_z=0.5,
50+
wyckoff_letter='b',
51+
b_iso=0.1,
52+
)
53+
model.atom_sites.create(
54+
label='O',
55+
type_symbol='O',
56+
fract_x=0,
57+
fract_y=0.5,
58+
fract_z=0.5,
59+
wyckoff_letter='c',
60+
b_iso=0.1,
61+
)
62+
63+
data_path = download_data(id=3, destination=TEMP_DIR)
64+
expt = ExperimentFactory.from_data_path(name='hrpt', data_path=data_path)
65+
expt.instrument.setup_wavelength = 1.494
66+
expt.instrument.calib_twotheta_offset = 0
67+
expt.peak.broad_gauss_u = 0.1
68+
expt.peak.broad_gauss_v = -0.1
69+
expt.peak.broad_gauss_w = 0.2
70+
expt.peak.broad_lorentz_x = 0
71+
expt.peak.broad_lorentz_y = 0
72+
expt.linked_phases.create(id='lbco', scale=5.0)
73+
expt.background.create(id='1', x=10, y=170)
74+
expt.background.create(id='2', x=165, y=170)
75+
76+
project = Project()
77+
project.structures.add(model)
78+
project.experiments.add(expt)
79+
project.analysis.current_minimizer = 'lmfit'
80+
81+
model.cell.length_a.free = True
82+
expt.linked_phases['lbco'].scale.free = True
83+
expt.instrument.calib_twotheta_offset.free = True
84+
expt.background['1'].y.free = True
85+
expt.background['2'].y.free = True
86+
87+
project.analysis.fit(verbosity='silent')
88+
89+
return project
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# SPDX-FileCopyrightText: 2026 EasyScience contributors <https://github.com/easyscience>
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
"""Integration tests for Analysis display methods and CIF serialization."""
5+
6+
7+
def test_display_all_params(lbco_fitted_project):
8+
project = lbco_fitted_project
9+
project.analysis.display.all_params()
10+
11+
12+
def test_display_fittable_params(lbco_fitted_project):
13+
project = lbco_fitted_project
14+
project.analysis.display.fittable_params()
15+
16+
17+
def test_display_free_params(lbco_fitted_project):
18+
project = lbco_fitted_project
19+
project.analysis.display.free_params()
20+
21+
22+
def test_display_how_to_access_parameters(lbco_fitted_project):
23+
project = lbco_fitted_project
24+
project.analysis.display.how_to_access_parameters()
25+
26+
27+
def test_display_parameter_cif_uids(lbco_fitted_project):
28+
project = lbco_fitted_project
29+
project.analysis.display.parameter_cif_uids()
30+
31+
32+
def test_display_constraints_empty(lbco_fitted_project):
33+
project = lbco_fitted_project
34+
project.analysis.display.constraints()
35+
36+
37+
def test_display_fit_results(lbco_fitted_project):
38+
project = lbco_fitted_project
39+
assert project.analysis.fit_results is not None
40+
project.analysis.display.fit_results()
41+
42+
43+
def test_display_as_cif(lbco_fitted_project):
44+
project = lbco_fitted_project
45+
project.analysis.display.as_cif()
46+
47+
48+
def test_analysis_as_cif(lbco_fitted_project):
49+
project = lbco_fitted_project
50+
cif_text = project.analysis.as_cif()
51+
assert isinstance(cif_text, str)
52+
assert len(cif_text) > 0
53+
54+
55+
def test_analysis_help(lbco_fitted_project):
56+
project = lbco_fitted_project
57+
project.analysis.help()
58+
59+
60+
def test_show_current_minimizer(lbco_fitted_project):
61+
project = lbco_fitted_project
62+
project.analysis.show_current_minimizer()
63+
64+
65+
def test_show_available_minimizers(lbco_fitted_project):
66+
from easydiffraction.analysis.analysis import Analysis
67+
68+
Analysis.show_available_minimizers()
69+
70+
71+
def test_show_supported_aliases_types(lbco_fitted_project):
72+
project = lbco_fitted_project
73+
project.analysis.show_supported_aliases_types()
74+
project.analysis.show_current_aliases_type()
75+
76+
77+
def test_show_supported_constraints_types(lbco_fitted_project):
78+
project = lbco_fitted_project
79+
project.analysis.show_supported_constraints_types()
80+
project.analysis.show_current_constraints_type()
81+
82+
83+
def test_show_supported_fit_mode_types(lbco_fitted_project):
84+
project = lbco_fitted_project
85+
project.analysis.show_supported_fit_mode_types()
86+
project.analysis.show_current_fit_mode_type()
87+
88+
89+
def test_fit_results_attributes(lbco_fitted_project):
90+
project = lbco_fitted_project
91+
results = project.analysis.fit_results
92+
assert results is not None
93+
assert results.reduced_chi_square is not None
94+
assert results.reduced_chi_square > 0
95+
assert isinstance(results.success, bool)
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# SPDX-FileCopyrightText: 2026 EasyScience contributors <https://github.com/easyscience>
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
"""Integration tests for help(), show_as_cif(), and switchable-category show methods."""
5+
6+
7+
def test_project_str(lbco_fitted_project):
8+
project = lbco_fitted_project
9+
text = str(project)
10+
assert 'Project' in text
11+
assert '1 structures' in text
12+
assert '1 experiments' in text
13+
14+
15+
def test_project_help(lbco_fitted_project):
16+
project = lbco_fitted_project
17+
project.help()
18+
19+
20+
def test_project_full_name(lbco_fitted_project):
21+
project = lbco_fitted_project
22+
assert project.full_name == project.name
23+
24+
25+
def test_structure_help(lbco_fitted_project):
26+
project = lbco_fitted_project
27+
model = project.structures['lbco']
28+
model.help()
29+
30+
31+
def test_structure_show_as_cif(lbco_fitted_project):
32+
project = lbco_fitted_project
33+
model = project.structures['lbco']
34+
model.show_as_cif()
35+
36+
37+
def test_structure_as_cif(lbco_fitted_project):
38+
project = lbco_fitted_project
39+
model = project.structures['lbco']
40+
cif_text = model.as_cif
41+
assert isinstance(cif_text, str)
42+
assert '_space_group' in cif_text
43+
44+
45+
def test_structure_switchable_category_types(lbco_fitted_project):
46+
project = lbco_fitted_project
47+
model = project.structures['lbco']
48+
# Cell
49+
model.show_supported_cell_types()
50+
model.show_current_cell_type()
51+
assert isinstance(model.cell_type, str)
52+
# Space group
53+
model.show_supported_space_group_types()
54+
model.show_current_space_group_type()
55+
assert isinstance(model.space_group_type, str)
56+
# Atom sites
57+
model.show_supported_atom_sites_types()
58+
model.show_current_atom_sites_type()
59+
assert isinstance(model.atom_sites_type, str)
60+
61+
62+
def test_experiment_help(lbco_fitted_project):
63+
project = lbco_fitted_project
64+
expt = project.experiments['hrpt']
65+
expt.help()
66+
67+
68+
def test_experiment_show_as_cif(lbco_fitted_project):
69+
project = lbco_fitted_project
70+
expt = project.experiments['hrpt']
71+
expt.show_as_cif()
72+
73+
74+
def test_experiment_as_cif(lbco_fitted_project):
75+
project = lbco_fitted_project
76+
expt = project.experiments['hrpt']
77+
cif_text = expt.as_cif
78+
assert isinstance(cif_text, str)
79+
assert len(cif_text) > 0
80+
81+
82+
def test_experiment_switchable_category_types(lbco_fitted_project):
83+
project = lbco_fitted_project
84+
expt = project.experiments['hrpt']
85+
# Instrument
86+
expt.show_supported_instrument_types()
87+
expt.show_current_instrument_type()
88+
assert isinstance(expt.instrument_type, str)
89+
# Background
90+
expt.show_supported_background_types()
91+
expt.show_current_background_type()
92+
assert isinstance(expt.background_type, str)
93+
# Peak profile
94+
expt.show_supported_peak_profile_types()
95+
expt.show_current_peak_profile_type()
96+
assert isinstance(expt.peak_profile_type, str)
97+
# Linked phases
98+
expt.show_supported_linked_phases_types()
99+
expt.show_current_linked_phases_type()
100+
assert isinstance(expt.linked_phases_type, str)
101+
# Calculator
102+
expt.show_supported_calculator_types()
103+
expt.show_current_calculator_type()
104+
assert isinstance(expt.calculator_type, str)
105+
# Diffrn
106+
expt.show_supported_diffrn_types()
107+
expt.show_current_diffrn_type()
108+
assert isinstance(expt.diffrn_type, str)
109+
110+
111+
def test_experiment_data_info(lbco_fitted_project):
112+
project = lbco_fitted_project
113+
expt = project.experiments['hrpt']
114+
# Data access
115+
assert expt.data is not None
116+
assert expt.data.x is not None
117+
assert len(expt.data.x) > 0
118+
assert expt.data.intensity_meas is not None
119+
120+
121+
def test_structure_cell_properties(lbco_fitted_project):
122+
project = lbco_fitted_project
123+
model = project.structures['lbco']
124+
# Access cell parameters
125+
assert model.cell.length_a.value > 0
126+
params = model.cell.parameters
127+
assert len(params) > 0
128+
129+
130+
def test_structure_atom_sites_iteration(lbco_fitted_project):
131+
project = lbco_fitted_project
132+
model = project.structures['lbco']
133+
count = 0
134+
for site in model.atom_sites:
135+
assert site.label.value is not None
136+
assert site.type_symbol.value is not None
137+
count += 1
138+
assert count == 4
139+
140+
141+
def test_structures_collection_names(lbco_fitted_project):
142+
project = lbco_fitted_project
143+
names = project.structures.names
144+
assert 'lbco' in names
145+
# Parameters
146+
params = project.structures.parameters
147+
assert len(params) > 0
148+
fittable = project.structures.fittable_parameters
149+
assert len(fittable) > 0
150+
free = project.structures.free_parameters
151+
assert len(free) > 0
152+
153+
154+
def test_experiments_collection_names(lbco_fitted_project):
155+
project = lbco_fitted_project
156+
names = project.experiments.names
157+
assert 'hrpt' in names
158+
params = project.experiments.parameters
159+
assert len(params) > 0
160+
fittable = project.experiments.fittable_parameters
161+
assert len(fittable) > 0
162+
free = project.experiments.free_parameters
163+
assert len(free) > 0
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SPDX-FileCopyrightText: 2026 EasyScience contributors <https://github.com/easyscience>
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
"""Integration tests for the Plotter facade on a fitted project."""
5+
6+
7+
def test_plot_meas(lbco_fitted_project):
8+
project = lbco_fitted_project
9+
project.plotter.plot_meas(expt_name='hrpt')
10+
11+
12+
def test_plot_calc(lbco_fitted_project):
13+
project = lbco_fitted_project
14+
project.plotter.plot_calc(expt_name='hrpt')
15+
16+
17+
def test_plot_meas_vs_calc(lbco_fitted_project):
18+
project = lbco_fitted_project
19+
project.plotter.plot_meas_vs_calc(expt_name='hrpt')
20+
21+
22+
def test_plot_meas_with_range(lbco_fitted_project):
23+
project = lbco_fitted_project
24+
project.plotter.plot_meas(expt_name='hrpt', x_min=20, x_max=80)
25+
26+
27+
def test_plot_meas_vs_calc_with_range(lbco_fitted_project):
28+
project = lbco_fitted_project
29+
project.plotter.plot_meas_vs_calc(expt_name='hrpt', x_min=20, x_max=80)

0 commit comments

Comments
 (0)