Skip to content

Commit dab6419

Browse files
fix: added the missing ids in parameterized tests (#412)
Closes #362 ### Summary of Changes Some parameterized tests didn't have ids. The missing ids are added now.
1 parent f94b768 commit dab6419

File tree

9 files changed

+27
-19
lines changed

9 files changed

+27
-19
lines changed

tests/safeds/data/image/containers/test_image.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ class TestFromJpegFile:
1313
@pytest.mark.parametrize(
1414
"path",
1515
["image/white_square.jpg", Path("image/white_square.jpg")],
16+
ids=["jpg", "jpg_Path"],
1617
)
1718
def test_should_load_jpeg_file(self, path: str | Path) -> None:
1819
Image.from_jpeg_file(resolve_resource_path(path))
1920

2021
@pytest.mark.parametrize(
2122
"path",
2223
["image/missing_file.jpg", Path("image/missing_file.jpg")],
24+
ids=["missing_file_jpg", "missing_file_jpg_Path"],
2325
)
2426
def test_should_raise_if_file_not_found(self, path: str | Path) -> None:
2527
with pytest.raises(FileNotFoundError):
@@ -30,13 +32,15 @@ class TestFromPngFile:
3032
@pytest.mark.parametrize(
3133
"path",
3234
["image/white_square.png", Path("image/white_square.png")],
35+
ids=["png", "png_Path"],
3336
)
3437
def test_should_load_png_file(self, path: str | Path) -> None:
3538
Image.from_png_file(resolve_resource_path(path))
3639

3740
@pytest.mark.parametrize(
3841
"path",
3942
["image/missing_file.png", Path("image/missing_file.png")],
43+
ids=["missing_file_png", "missing_file_png_Path"],
4044
)
4145
def test_should_raise_if_file_not_found(self, path: str | Path) -> None:
4246
with pytest.raises(FileNotFoundError):
@@ -50,6 +54,7 @@ class TestFormat:
5054
(Image.from_jpeg_file(resolve_resource_path("image/white_square.jpg")), ImageFormat.JPEG),
5155
(Image.from_png_file(resolve_resource_path("image/white_square.png")), ImageFormat.PNG),
5256
],
57+
ids=["jpg", "png"],
5358
)
5459
def test_should_return_correct_format(self, image: Image, format_: ImageFormat) -> None:
5560
assert image.format == format_
@@ -78,10 +83,7 @@ def test_should_return_image_properties(self, image: Image, width: int, height:
7883

7984

8085
class TestToJpegFile:
81-
@pytest.mark.parametrize(
82-
"path",
83-
["image/white_square.jpg"],
84-
)
86+
@pytest.mark.parametrize("path", ["image/white_square.jpg"], ids=["jpg_file"])
8587
def test_should_save_jpeg_file_by_str(self, path: str) -> None:
8688
image = Image.from_jpeg_file(resolve_resource_path(path))
8789

@@ -94,10 +96,7 @@ def test_should_save_jpeg_file_by_str(self, path: str) -> None:
9496

9597
assert image._image.tobytes() == image_read_back._image.tobytes()
9698

97-
@pytest.mark.parametrize(
98-
"path",
99-
["image/white_square.jpg"],
100-
)
99+
@pytest.mark.parametrize("path", ["image/white_square.jpg"], ids=["jpg"])
101100
def test_should_save_jpeg_file_by_path(self, path: str) -> None:
102101
image = Image.from_jpeg_file(resolve_resource_path(path))
103102

@@ -112,10 +111,7 @@ def test_should_save_jpeg_file_by_path(self, path: str) -> None:
112111

113112

114113
class TestToPngFile:
115-
@pytest.mark.parametrize(
116-
"path",
117-
["image/white_square.png"],
118-
)
114+
@pytest.mark.parametrize("path", ["image/white_square.png"], ids=["png"])
119115
def test_should_save_png_file_by_str(self, path: str) -> None:
120116
image = Image.from_png_file(resolve_resource_path(path))
121117

@@ -128,10 +124,7 @@ def test_should_save_png_file_by_str(self, path: str) -> None:
128124

129125
assert image._image.tobytes() == image_read_back._image.tobytes()
130126

131-
@pytest.mark.parametrize(
132-
"path",
133-
["image/white_square.png"],
134-
)
127+
@pytest.mark.parametrize("path", ["image/white_square.png"], ids=["png"])
135128
def test_should_save_png_file_by_path(self, path: str) -> None:
136129
image = Image.from_png_file(resolve_resource_path(path))
137130

@@ -149,13 +142,15 @@ class TestReprJpeg:
149142
@pytest.mark.parametrize(
150143
"image",
151144
[Image.from_jpeg_file(resolve_resource_path("image/white_square.jpg"))],
145+
ids=["jpg"],
152146
)
153147
def test_should_return_bytes_if_image_is_jpeg(self, image: Image) -> None:
154148
assert isinstance(image._repr_jpeg_(), bytes)
155149

156150
@pytest.mark.parametrize(
157151
"image",
158152
[Image.from_png_file(resolve_resource_path("image/white_square.png"))],
153+
ids=["png"],
159154
)
160155
def test_should_return_none_if_image_is_not_jpeg(self, image: Image) -> None:
161156
assert image._repr_jpeg_() is None
@@ -165,13 +160,15 @@ class TestReprPng:
165160
@pytest.mark.parametrize(
166161
"image",
167162
[Image.from_png_file(resolve_resource_path("image/white_square.png"))],
163+
ids=["png"],
168164
)
169165
def test_should_return_bytes_if_image_is_png(self, image: Image) -> None:
170166
assert isinstance(image._repr_png_(), bytes)
171167

172168
@pytest.mark.parametrize(
173169
"image",
174170
[Image.from_jpeg_file(resolve_resource_path("image/white_square.jpg"))],
171+
ids=["jpg"],
175172
)
176173
def test_should_return_none_if_image_is_not_png(self, image: Image) -> None:
177174
assert image._repr_png_() is None
@@ -262,7 +259,7 @@ def test_should_be_original(self) -> None:
262259

263260

264261
class TestAdjustContrast:
265-
@pytest.mark.parametrize("factor", [0.75, 5])
262+
@pytest.mark.parametrize("factor", [0.75, 5], ids=["small factor", "large factor"])
266263
def test_should_adjust_contrast(self, factor: float) -> None:
267264
image = Image.from_png_file(resolve_resource_path("image/contrast/to_adjust_contrast.png"))
268265
image2 = image.adjust_contrast(factor)
@@ -288,7 +285,7 @@ def test_should_raise(self) -> None:
288285

289286

290287
class TestBrightness:
291-
@pytest.mark.parametrize("factor", [0.5, 10])
288+
@pytest.mark.parametrize("factor", [0.5, 10], ids=["small factor", "large factor"])
292289
def test_should_adjust_brightness(self, factor: float) -> None:
293290
image = Image.from_png_file(resolve_resource_path("image/brightness/to_brighten.png"))
294291
image2 = image.adjust_brightness(factor)
@@ -360,7 +357,7 @@ def test_should_return_cropped_image(self, image: Image, expected: Image) -> Non
360357

361358

362359
class TestSharpen:
363-
@pytest.mark.parametrize("factor", [-1, 0.5, 10])
360+
@pytest.mark.parametrize("factor", [-1, 0.5, 10], ids=["negative factor", "small factor", "large factor"])
364361
def test_should_sharpen(self, factor: float) -> None:
365362
image = Image.from_png_file(resolve_resource_path("image/sharpen/to_sharpen.png"))
366363
image2 = image.sharpen(factor)

tests/safeds/data/tabular/containers/_table/test_slice_rows.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def test_should_slice_rows(table: Table, test_table: Table, second_test_table: T
3636
(-4, 0, 1, r"There is no element at index '-4'"),
3737
(0, -4, 1, r"There is no element in the range \[0, -4\]"),
3838
],
39+
ids=["Start > End", "Start > Length", "End > Length", "Start < 0", "End < 0"],
3940
)
4041
def test_should_raise_if_index_out_of_bounds(start: int, end: int, step: int, error_message: str) -> None:
4142
table = Table({"col1": [1, 2, 1], "col2": [1, 2, 4]})

tests/safeds/data/tabular/containers/_table/test_to_dict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
},
2525
),
2626
],
27+
ids=["Empty table", "Table with one row"],
2728
)
2829
def test_should_return_dict_for_table(table: Table, expected: dict[str, list[Any]]) -> None:
2930
assert table.to_dict() == expected

tests/safeds/data/tabular/containers/_table/test_transform_table.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def test_should_return_transformed_table(
9494
),
9595
Table(),
9696
],
97+
ids=["non-empty table", "empty table"],
9798
)
9899
def test_should_raise_if_column_not_found(table_to_fit: Table) -> None:
99100
table_to_fit = Table(

tests/safeds/data/tabular/transformation/test_imputer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class TestStr:
3232
(Imputer.Strategy.Median(), "Median"),
3333
(Imputer.Strategy.Mode(), "Mode"),
3434
],
35+
ids=["Constant", "Mean", "Median", "Mode"],
3536
)
3637
def test_should_return_correct_string_representation(self, strategy: ImputerStrategy, expected: str) -> None:
3738
assert str(strategy) == expected

tests/safeds/data/tabular/transformation/test_label_encoder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class TestFitAndTransform:
130130
),
131131
),
132132
],
133+
ids=["no_column_names", "with_column_names"],
133134
)
134135
def test_should_return_transformed_table(
135136
self,
@@ -205,6 +206,7 @@ class TestInverseTransform:
205206
},
206207
),
207208
],
209+
ids=["no_column_names"],
208210
)
209211
def test_should_return_original_table(self, table: Table) -> None:
210212
transformer = LabelEncoder().fit(table, None)

tests/safeds/data/tabular/transformation/test_range_scaler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class TestFitAndTransform:
142142
),
143143
),
144144
],
145+
ids=["one_column", "two_columns"],
145146
)
146147
def test_should_return_transformed_table(
147148
self,
@@ -183,6 +184,7 @@ def test_should_return_transformed_table(
183184
),
184185
),
185186
],
187+
ids=["one_column", "two_columns"],
186188
)
187189
def test_should_return_transformed_table_with_correct_range(
188190
self,

tests/safeds/data/tabular/transformation/test_standard_scaler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class TestFitAndTransformOnMultipleTables:
143143
),
144144
),
145145
],
146+
ids=["two_columns"],
146147
)
147148
def test_should_return_transformed_tables(
148149
self,
@@ -224,6 +225,7 @@ class TestInverseTransform:
224225
},
225226
),
226227
],
228+
ids=["one_column"],
227229
)
228230
def test_should_return_original_table(self, table: Table) -> None:
229231
transformer = StandardScaler().fit(table, None)

tests/safeds/ml/classical/regression/test_regressor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ class TestMeanSquaredError:
346346
@pytest.mark.parametrize(
347347
("predicted", "expected", "result"),
348348
[([1, 2], [1, 2], 0), ([0, 0], [1, 1], 1), ([1, 1, 1], [2, 2, 11], 34)],
349+
ids=["perfect_prediction", "bad_prediction", "worst_prediction"],
349350
)
350351
def test_valid_data(self, predicted: list[float], expected: list[float], result: float) -> None:
351352
table = Table({"predicted": predicted, "expected": expected}).tag_columns(

0 commit comments

Comments
 (0)