-
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.
feat: add some dunder methods to
Schema
- Loading branch information
1 parent
db85617
commit 212c0ae
Showing
6 changed files
with
109 additions
and
11 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import pytest | ||
|
||
from safeds.data.tabular.typing import ColumnType, Schema | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("schema", "column", "expected"), | ||
[ | ||
(Schema({}), "C", False), | ||
(Schema({"A": ColumnType.null()}), "A", True), | ||
(Schema({"A": ColumnType.null()}), "B", False), | ||
], | ||
ids=["empty", "has column", "doesn't have column"], | ||
) | ||
def test_should_check_if_column_is_in_schema(schema: Schema, column: str, expected: bool) -> None: | ||
assert (column in schema) == expected |
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,29 @@ | ||
import pytest | ||
|
||
from safeds.data.tabular.typing import ColumnType, Schema | ||
from safeds.exceptions import ColumnNotFoundError | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("schema", "name", "expected"), | ||
[ | ||
( | ||
Schema({"col1": ColumnType.int64()}), | ||
"col1", | ||
ColumnType.int64(), | ||
), | ||
( | ||
Schema({"col1": ColumnType.string()}), | ||
"col1", | ||
ColumnType.string(), | ||
), | ||
], | ||
ids=["int column", "string column"], | ||
) | ||
def test_should_return_data_type_of_column(schema: Schema, name: str, expected: ColumnType) -> None: | ||
assert schema[name] == expected | ||
|
||
|
||
def test_should_raise_if_column_name_is_unknown() -> None: | ||
with pytest.raises(ColumnNotFoundError): | ||
_ignored = Schema({})["col1"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
|
||
from safeds.data.tabular.typing import ColumnType, Schema | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("schema", "expected"), | ||
[ | ||
(Schema({}), []), | ||
(Schema({"col1": ColumnType.null()}), ["col1"]), | ||
(Schema({"col1": ColumnType.null(), "col2": ColumnType.null()}), ["col1", "col2"]), | ||
], | ||
ids=[ | ||
"empty", | ||
"one column", | ||
"two columns", | ||
], | ||
) | ||
def test_should_return_column_names(schema: Schema, expected: list[str]) -> None: | ||
assert list(schema) == expected |
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,20 @@ | ||
import pytest | ||
|
||
from safeds.data.tabular.typing import ColumnType, Schema | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("schema", "expected"), | ||
[ | ||
(Schema({}), 0), | ||
(Schema({"col1": ColumnType.null()}), 1), | ||
(Schema({"col1": ColumnType.null(), "col2": ColumnType.null()}), 2), | ||
], | ||
ids=[ | ||
"empty", | ||
"one column", | ||
"two columns", | ||
], | ||
) | ||
def test_should_return_number_of_columns(schema: Schema, expected: int) -> None: | ||
assert len(schema) == expected |