|
| 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 |
0 commit comments