-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 150-improve-error-handling-of-taggedtable
- Loading branch information
Showing
6 changed files
with
374 additions
and
9 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
tests/safeds/data/tabular/containers/_table/test_get_similar_columns.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import pytest | ||
from safeds.data.tabular.containers import Table | ||
from safeds.exceptions._data import UnknownColumnNameError | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("table", "column_name", "expected"), | ||
[ | ||
(Table({"column1": ["col1_1"], "x": ["y"], "cilumn2": ["cil2_1"]}), "col1", ["column1"]), | ||
( | ||
Table( | ||
{ | ||
"column1": ["col1_1"], | ||
"col2": ["col2_1"], | ||
"col3": ["col2_1"], | ||
"col4": ["col2_1"], | ||
"cilumn2": ["cil2_1"], | ||
}, | ||
), | ||
"clumn1", | ||
["column1", "cilumn2"], | ||
), | ||
( | ||
Table({"column1": ["a"], "column2": ["b"], "column3": ["c"]}), | ||
"notexisting", | ||
[], | ||
), | ||
( | ||
Table({"column1": ["col1_1"], "x": ["y"], "cilumn2": ["cil2_1"]}), | ||
"x", | ||
["x"], | ||
), | ||
(Table({}), "column1", []), | ||
], | ||
ids=["one similar", "two similar/ dynamic increase", "no similar", "exact match", "empty table"], | ||
) | ||
def test_should_get_similar_column_names(table: Table, column_name: str, expected: list[str]) -> None: | ||
assert table._get_similar_columns(column_name) == expected | ||
|
||
|
||
def test_should_raise_error_if_column_name_unknown() -> None: | ||
with pytest.raises( | ||
UnknownColumnNameError, | ||
match=r"Could not find column\(s\) 'col3'.\nDid you mean '\['col1', 'col2'\]'?", | ||
): | ||
raise UnknownColumnNameError(["col3"], ["col1", "col2"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
from safeds.exceptions import UnknownColumnNameError | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("column_names", "similar_columns", "expected_error_message"), | ||
[ | ||
(["column1"], [], r"Could not find column\(s\) 'column1'\."), | ||
(["column1", "column2"], [], r"Could not find column\(s\) 'column1, column2'\."), | ||
(["column1"], ["column_a"], r"Could not find column\(s\) 'column1'\.\nDid you mean '\['column_a'\]'\?"), | ||
( | ||
["column1", "column2"], | ||
["column_a"], | ||
r"Could not find column\(s\) 'column1, column2'\.\nDid you mean '\['column_a'\]'\?", | ||
), | ||
( | ||
["column1"], | ||
["column_a", "column_b"], | ||
r"Could not find column\(s\) 'column1'\.\nDid you mean '\['column_a', 'column_b'\]'\?", | ||
), | ||
( | ||
["column1", "column2"], | ||
["column_a", "column_b"], | ||
r"Could not find column\(s\) 'column1, column2'\.\nDid you mean '\['column_a', 'column_b'\]'\?", | ||
), | ||
], | ||
ids=[ | ||
"one_unknown_no_suggestions", | ||
"two_unknown_no_suggestions", | ||
"one_unknown_one_suggestion", | ||
"two_unknown_one_suggestion", | ||
"one_unknown_two_suggestions", | ||
"two_unknown_two_suggestions", | ||
], | ||
) | ||
def test_empty_similar_columns( | ||
column_names: list[str], | ||
similar_columns: list[str], | ||
expected_error_message: str, | ||
) -> None: | ||
with pytest.raises(UnknownColumnNameError, match=expected_error_message): | ||
raise UnknownColumnNameError(column_names, similar_columns) |