Skip to content

Commit

Permalink
fix: added the missing ids in parameterized tests (#412)
Browse files Browse the repository at this point in the history
Closes #362 

### Summary of Changes

Some parameterized tests didn't have ids. The missing ids are added now.
  • Loading branch information
PhilipGutberlet authored Jul 7, 2023
1 parent f94b768 commit dab6419
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 19 deletions.
35 changes: 16 additions & 19 deletions tests/safeds/data/image/containers/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ class TestFromJpegFile:
@pytest.mark.parametrize(
"path",
["image/white_square.jpg", Path("image/white_square.jpg")],
ids=["jpg", "jpg_Path"],
)
def test_should_load_jpeg_file(self, path: str | Path) -> None:
Image.from_jpeg_file(resolve_resource_path(path))

@pytest.mark.parametrize(
"path",
["image/missing_file.jpg", Path("image/missing_file.jpg")],
ids=["missing_file_jpg", "missing_file_jpg_Path"],
)
def test_should_raise_if_file_not_found(self, path: str | Path) -> None:
with pytest.raises(FileNotFoundError):
Expand All @@ -30,13 +32,15 @@ class TestFromPngFile:
@pytest.mark.parametrize(
"path",
["image/white_square.png", Path("image/white_square.png")],
ids=["png", "png_Path"],
)
def test_should_load_png_file(self, path: str | Path) -> None:
Image.from_png_file(resolve_resource_path(path))

@pytest.mark.parametrize(
"path",
["image/missing_file.png", Path("image/missing_file.png")],
ids=["missing_file_png", "missing_file_png_Path"],
)
def test_should_raise_if_file_not_found(self, path: str | Path) -> None:
with pytest.raises(FileNotFoundError):
Expand All @@ -50,6 +54,7 @@ class TestFormat:
(Image.from_jpeg_file(resolve_resource_path("image/white_square.jpg")), ImageFormat.JPEG),
(Image.from_png_file(resolve_resource_path("image/white_square.png")), ImageFormat.PNG),
],
ids=["jpg", "png"],
)
def test_should_return_correct_format(self, image: Image, format_: ImageFormat) -> None:
assert image.format == format_
Expand Down Expand Up @@ -78,10 +83,7 @@ def test_should_return_image_properties(self, image: Image, width: int, height:


class TestToJpegFile:
@pytest.mark.parametrize(
"path",
["image/white_square.jpg"],
)
@pytest.mark.parametrize("path", ["image/white_square.jpg"], ids=["jpg_file"])
def test_should_save_jpeg_file_by_str(self, path: str) -> None:
image = Image.from_jpeg_file(resolve_resource_path(path))

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

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

@pytest.mark.parametrize(
"path",
["image/white_square.jpg"],
)
@pytest.mark.parametrize("path", ["image/white_square.jpg"], ids=["jpg"])
def test_should_save_jpeg_file_by_path(self, path: str) -> None:
image = Image.from_jpeg_file(resolve_resource_path(path))

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


class TestToPngFile:
@pytest.mark.parametrize(
"path",
["image/white_square.png"],
)
@pytest.mark.parametrize("path", ["image/white_square.png"], ids=["png"])
def test_should_save_png_file_by_str(self, path: str) -> None:
image = Image.from_png_file(resolve_resource_path(path))

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

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

@pytest.mark.parametrize(
"path",
["image/white_square.png"],
)
@pytest.mark.parametrize("path", ["image/white_square.png"], ids=["png"])
def test_should_save_png_file_by_path(self, path: str) -> None:
image = Image.from_png_file(resolve_resource_path(path))

Expand All @@ -149,13 +142,15 @@ class TestReprJpeg:
@pytest.mark.parametrize(
"image",
[Image.from_jpeg_file(resolve_resource_path("image/white_square.jpg"))],
ids=["jpg"],
)
def test_should_return_bytes_if_image_is_jpeg(self, image: Image) -> None:
assert isinstance(image._repr_jpeg_(), bytes)

@pytest.mark.parametrize(
"image",
[Image.from_png_file(resolve_resource_path("image/white_square.png"))],
ids=["png"],
)
def test_should_return_none_if_image_is_not_jpeg(self, image: Image) -> None:
assert image._repr_jpeg_() is None
Expand All @@ -165,13 +160,15 @@ class TestReprPng:
@pytest.mark.parametrize(
"image",
[Image.from_png_file(resolve_resource_path("image/white_square.png"))],
ids=["png"],
)
def test_should_return_bytes_if_image_is_png(self, image: Image) -> None:
assert isinstance(image._repr_png_(), bytes)

@pytest.mark.parametrize(
"image",
[Image.from_jpeg_file(resolve_resource_path("image/white_square.jpg"))],
ids=["jpg"],
)
def test_should_return_none_if_image_is_not_png(self, image: Image) -> None:
assert image._repr_png_() is None
Expand Down Expand Up @@ -262,7 +259,7 @@ def test_should_be_original(self) -> None:


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


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


class TestSharpen:
@pytest.mark.parametrize("factor", [-1, 0.5, 10])
@pytest.mark.parametrize("factor", [-1, 0.5, 10], ids=["negative factor", "small factor", "large factor"])
def test_should_sharpen(self, factor: float) -> None:
image = Image.from_png_file(resolve_resource_path("image/sharpen/to_sharpen.png"))
image2 = image.sharpen(factor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_should_slice_rows(table: Table, test_table: Table, second_test_table: T
(-4, 0, 1, r"There is no element at index '-4'"),
(0, -4, 1, r"There is no element in the range \[0, -4\]"),
],
ids=["Start > End", "Start > Length", "End > Length", "Start < 0", "End < 0"],
)
def test_should_raise_if_index_out_of_bounds(start: int, end: int, step: int, error_message: str) -> None:
table = Table({"col1": [1, 2, 1], "col2": [1, 2, 4]})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
),
],
ids=["Empty table", "Table with one row"],
)
def test_should_return_dict_for_table(table: Table, expected: dict[str, list[Any]]) -> None:
assert table.to_dict() == expected
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def test_should_return_transformed_table(
),
Table(),
],
ids=["non-empty table", "empty table"],
)
def test_should_raise_if_column_not_found(table_to_fit: Table) -> None:
table_to_fit = Table(
Expand Down
1 change: 1 addition & 0 deletions tests/safeds/data/tabular/transformation/test_imputer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class TestStr:
(Imputer.Strategy.Median(), "Median"),
(Imputer.Strategy.Mode(), "Mode"),
],
ids=["Constant", "Mean", "Median", "Mode"],
)
def test_should_return_correct_string_representation(self, strategy: ImputerStrategy, expected: str) -> None:
assert str(strategy) == expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class TestFitAndTransform:
),
),
],
ids=["no_column_names", "with_column_names"],
)
def test_should_return_transformed_table(
self,
Expand Down Expand Up @@ -205,6 +206,7 @@ class TestInverseTransform:
},
),
],
ids=["no_column_names"],
)
def test_should_return_original_table(self, table: Table) -> None:
transformer = LabelEncoder().fit(table, None)
Expand Down
2 changes: 2 additions & 0 deletions tests/safeds/data/tabular/transformation/test_range_scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class TestFitAndTransform:
),
),
],
ids=["one_column", "two_columns"],
)
def test_should_return_transformed_table(
self,
Expand Down Expand Up @@ -183,6 +184,7 @@ def test_should_return_transformed_table(
),
),
],
ids=["one_column", "two_columns"],
)
def test_should_return_transformed_table_with_correct_range(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class TestFitAndTransformOnMultipleTables:
),
),
],
ids=["two_columns"],
)
def test_should_return_transformed_tables(
self,
Expand Down Expand Up @@ -224,6 +225,7 @@ class TestInverseTransform:
},
),
],
ids=["one_column"],
)
def test_should_return_original_table(self, table: Table) -> None:
transformer = StandardScaler().fit(table, None)
Expand Down
1 change: 1 addition & 0 deletions tests/safeds/ml/classical/regression/test_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ class TestMeanSquaredError:
@pytest.mark.parametrize(
("predicted", "expected", "result"),
[([1, 2], [1, 2], 0), ([0, 0], [1, 1], 1), ([1, 1, 1], [2, 2, 11], 34)],
ids=["perfect_prediction", "bad_prediction", "worst_prediction"],
)
def test_valid_data(self, predicted: list[float], expected: list[float], result: float) -> None:
table = Table({"predicted": predicted, "expected": expected}).tag_columns(
Expand Down

0 comments on commit dab6419

Please sign in to comment.