-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_from_dict.py
37 lines (32 loc) · 985 Bytes
/
test_from_dict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from typing import Any
import pytest
from safeds.data.tabular.containers import Table
from safeds.exceptions import ColumnLengthMismatchError
@pytest.mark.parametrize(
("data", "expected"),
[
(
{},
Table(),
),
(
{
"a": [1],
"b": [2],
},
Table.from_dict(
{
"a": [1],
"b": [2],
},
),
),
],
ids=["empty", "with values"],
)
def test_should_create_table_from_dict(data: dict[str, list[Any]], expected: Table) -> None:
assert Table.from_dict(data).schema == expected.schema
assert Table.from_dict(data) == expected
def test_should_raise_error_if_columns_have_different_lengths() -> None:
with pytest.raises(ColumnLengthMismatchError, match=r"The length of at least one column differs: \na: 2\nb: 1"):
Table.from_dict({"a": [1, 2], "b": [3]})