Skip to content

Commit fd02c69

Browse files
committed
Fixes unit tests
1 parent 2f06002 commit fd02c69

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

src/easydiffraction/experiments/experiment.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,10 @@ def __init__(self,
182182
super().__init__(name=name,
183183
type=type)
184184

185-
self._peak_profile_type = DEFAULT_PEAK_PROFILE_TYPE[self.type.scattering_type.value][self.type.beam_mode.value]
186-
self._background_type = DEFAULT_BACKGROUND_TYPE
185+
self._background_type: str = DEFAULT_BACKGROUND_TYPE
186+
self.background = BackgroundFactory.create(
187+
background_type=self.background_type)
188+
self._peak_profile_type: str = DEFAULT_PEAK_PROFILE_TYPE[self.type.scattering_type.value][self.type.beam_mode.value]
187189
self.peak = PeakFactory.create(
188190
scattering_type=self.type.scattering_type.value,
189191
beam_mode=self.type.beam_mode.value,

tests/unit_tests/experiments/components/test_experiment_type.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ def test_experiment_type_initialization():
77
experiment_type = ExperimentType(
88
sample_form="powder",
99
beam_mode="CW",
10-
radiation_probe="neutron"
10+
radiation_probe="neutron",
11+
scattering_type="bragg"
1112
)
1213

1314
assert isinstance(experiment_type.sample_form, Descriptor)
@@ -30,7 +31,8 @@ def test_experiment_type_properties():
3031
experiment_type = ExperimentType(
3132
sample_form="single_crystal",
3233
beam_mode="TOF",
33-
radiation_probe="x-ray"
34+
radiation_probe="x-ray",
35+
scattering_type="bragg"
3436
)
3537

3638
assert experiment_type.category_key == "expt_type"
@@ -45,7 +47,8 @@ def no_test_experiment_type_locking_attributes():
4547
experiment_type = ExperimentType(
4648
sample_form="powder",
4749
beam_mode="CW",
48-
radiation_probe="neutron"
50+
radiation_probe="neutron",
51+
scattering_type="bragg"
4952
)
5053
experiment_type._locked = True # Disallow adding new attributes
5154
experiment_type.new_attribute = "value"

tests/unit_tests/experiments/components/test_peak.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,5 @@ def test_peak_factory_create_invalid_beam_mode():
142142

143143

144144
def test_peak_factory_create_invalid_profile_type():
145-
with pytest.raises(ValueError, match="Unsupported profile type 'invalid' for mode 'constant wavelength'.*"):
145+
with pytest.raises(ValueError, match="Unsupported profile type 'invalid' for beam mode 'constant wavelength'.*"):
146146
PeakFactory.create(beam_mode="constant wavelength", profile_type="invalid")

tests/unit_tests/experiments/test_experiment.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from easydiffraction.core.constants import (
1414
DEFAULT_SAMPLE_FORM,
1515
DEFAULT_BEAM_MODE,
16-
DEFAULT_RADIATION_PROBE
16+
DEFAULT_RADIATION_PROBE,
17+
DEFAULT_SCATTERING_TYPE
1718
)
1819

1920

@@ -22,7 +23,8 @@ def expt_type():
2223
return ExperimentType(
2324
sample_form=DEFAULT_SAMPLE_FORM,
2425
beam_mode=DEFAULT_BEAM_MODE,
25-
radiation_probe="xray"
26+
radiation_probe='xray',
27+
scattering_type='bragg'
2628
)
2729

2830

@@ -53,8 +55,9 @@ def test_powder_experiment_initialization(expt_type):
5355
experiment = PowderExperiment(name="PowderTest", type=expt_type)
5456
assert experiment.name == "PowderTest"
5557
assert experiment.type == expt_type
56-
assert experiment.peak is not None
5758
assert experiment.background is not None
59+
assert experiment.peak is not None
60+
assert experiment.linked_phases is not None
5861

5962

6063
def test_powder_experiment_load_ascii_data(expt_type):
@@ -69,16 +72,6 @@ def test_powder_experiment_load_ascii_data(expt_type):
6972
assert np.array_equal(experiment.datastore.pattern.meas_su, mock_data[:, 2])
7073

7174

72-
def test_powder_experiment_show_meas_chart(expt_type):
73-
experiment = PowderExperiment(name="PowderTest", type=expt_type)
74-
experiment.datastore = MagicMock()
75-
experiment.datastore.pattern.x = [1, 2, 3]
76-
experiment.datastore.pattern.meas = [10, 20, 30]
77-
with patch("easydiffraction.utils.chart_plotter.ChartPlotter.plot") as mock_plot:
78-
experiment.show_meas_chart()
79-
mock_plot.assert_called_once()
80-
81-
8275
def test_single_crystal_experiment_initialization(expt_type):
8376
experiment = ConcreteSingleCrystalExperiment(name="SingleCrystalTest", type=expt_type)
8477
assert experiment.name == "SingleCrystalTest"
@@ -99,6 +92,7 @@ def test_experiment_factory_create_powder():
9992
sample_form="powder",
10093
beam_mode=DEFAULT_BEAM_MODE,
10194
radiation_probe=DEFAULT_RADIATION_PROBE,
95+
scattering_type=DEFAULT_SCATTERING_TYPE
10296
)
10397
assert isinstance(experiment, PowderExperiment)
10498
assert experiment.name == "PowderTest"

0 commit comments

Comments
 (0)