Skip to content

Commit 658314e

Browse files
Comment tests
1 parent fac0bfa commit 658314e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tests/unit_tests/experiment/test_experiment.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def experiment(self):
1919
return experiment
2020

2121
def test_init_array(self, experiment):
22-
# THEN EXPECT
22+
"Test initialization with a Scipp DataArray"
23+
# WHEN THEN EXPECT
2324
assert experiment.name == "test_experiment"
2425
assert isinstance(experiment._data, sc.DataArray)
2526
assert "Q" in experiment._data.dims
@@ -32,6 +33,7 @@ def test_init_array(self, experiment):
3233
)
3334

3435
def test_init_string(self, tmp_path):
36+
"Test initialization with a filename string - should load the file"
3537
# WHEN
3638
Q = sc.linspace("Q", 0.5, 1.5, num=10, unit="1/Angstrom")
3739
energy = sc.linspace("energy", -5, 5, num=11, unit="meV")
@@ -57,6 +59,7 @@ def test_init_string(self, tmp_path):
5759
)
5860

5961
def test_init_no_data(self):
62+
"Test initialization with no data"
6063
# WHEN
6164
experiment = Experiment(name="empty_experiment")
6265

@@ -65,11 +68,13 @@ def test_init_no_data(self):
6568
assert experiment._data is None
6669

6770
def test_init_invalid_data(self):
71+
"Test initialization with invalid data type"
6872
# WHEN / THEN EXPECT
6973
with pytest.raises(TypeError):
7074
Experiment(name="invalid_experiment", data=123)
7175

7276
def test_load_hdf5(self, tmp_path, experiment):
77+
"Test loading data from an HDF5 file. First use scipp to save data to a file, then load it using the method."
7378
# WHEN
7479
# First create a file to load from
7580
filename = tmp_path / "test.h5"
@@ -86,21 +91,25 @@ def test_load_hdf5(self, tmp_path, experiment):
8691
assert new_experiment.name == "loaded_data"
8792

8893
def test_load_hdf5_invalid_name_raises(self, experiment):
94+
"Test loading data from an HDF5 file, giving the Experiment an invalid name"
8995
# WHEN / THEN EXPECT
9096
with pytest.raises(TypeError):
9197
experiment.load_hdf5("some_file.h5", name=123)
9298

9399
def test_load_hdf5_invalid_filename_raises(self, experiment):
100+
"Test loading data from an HDF5 file with an invalid filename"
94101
# WHEN / THEN EXPECT
95102
with pytest.raises(TypeError):
96103
experiment.load_hdf5(123)
97104

98105
def test_load_hdf5_invalid_file_raises(self, experiment):
106+
"Test loading data from a non-existent HDF5 file"
99107
# WHEN / THEN EXPECT
100108
with pytest.raises(OSError):
101109
experiment.load_hdf5("non_existent_file.h5")
102110

103111
def test_save_hdf5(self, tmp_path, experiment):
112+
"Test saving data to an HDF5 file. Load the saved file using scipp and compare to the original data."
104113
# WHEN THEN
105114
filename = tmp_path / "saved_data.h5"
106115
experiment.save_hdf5(str(filename))
@@ -111,6 +120,7 @@ def test_save_hdf5(self, tmp_path, experiment):
111120
assert sc.identical(original_data, loaded_data)
112121

113122
def test_save_hdf5_default_name(self, tmp_path, experiment):
123+
"Test saving data to an HDF5 file with default filename (based on experiment name). Load the saved file using scipp and compare to the original data."
114124
# WHEN THEN
115125
current_dir = tmp_path
116126
experiment.name = "default_name_experiment"
@@ -123,6 +133,7 @@ def test_save_hdf5_default_name(self, tmp_path, experiment):
123133
assert sc.identical(original_data, loaded_data)
124134

125135
def test_save_hdf5_no_data_raises(self):
136+
"Test saving data to an HDF5 file when no data is present in the experiment"
126137
# WHEN
127138
experiment = Experiment(name="no_data_experiment")
128139

@@ -131,11 +142,13 @@ def test_save_hdf5_no_data_raises(self):
131142
experiment.save_hdf5("should_fail.h5")
132143

133144
def test_save_hdf5_invalid_filename_raises(self, experiment):
145+
"Test saving data to an HDF5 file with an invalid filename"
134146
# WHEN / THEN EXPECT
135147
with pytest.raises(TypeError):
136148
experiment.save_hdf5(123)
137149

138150
def test_remove_data(self, experiment):
151+
"Test removing data from the experiment"
139152
# WHEN
140153
experiment.remove_data()
141154

@@ -152,6 +165,7 @@ def test_repr(self, experiment):
152165
)
153166

154167
def test_copy_experiment(self, experiment):
168+
"Test copying an Experiment object. The copied object should have the same attributes but be a different object in memory."
155169
# WHEN
156170
copied_experiment = copy(experiment)
157171

0 commit comments

Comments
 (0)