Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions tests/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ def test_item_base_has_no_unwrap() -> None:


def test_integer_unwrap() -> None:
elementary_test(item(666), int)
elementary_test(item(666), int, 666)


def test_float_unwrap() -> None:
elementary_test(item(2.78), float)
elementary_test(item(2.78), float, 2.78)


@pytest.mark.skipif(
Expand All @@ -116,25 +116,25 @@ def test_float_is_not_a_sequence() -> None:


def test_false_unwrap() -> None:
elementary_test(item(False), bool)
elementary_test(item(False), bool, False)


def test_true_unwrap() -> None:
elementary_test(item(True), bool)
elementary_test(item(True), bool, True)


def test_datetime_unwrap() -> None:
dt = datetime.now(tz=timezone.utc)
elementary_test(item(dt), datetime)
elementary_test(item(dt), datetime, dt)


def test_string_unwrap() -> None:
elementary_test(item("hello"), str)
elementary_test(item("hello"), str, "hello")


def test_null_unwrap() -> None:
n = Null()
elementary_test(n, type(None))
elementary_test(n, type(None), None)


def test_aot_unwrap() -> None:
Expand All @@ -147,6 +147,7 @@ def test_aot_unwrap() -> None:
vu = du[ku]
assert_is_ppo(ku, str)
assert_is_ppo(vu, str)
assert unwrapped == [{"a": "A"}, {"b": "B"}]


def test_aot_set_item() -> None:
Expand All @@ -164,12 +165,12 @@ def test_aot_set_item() -> None:

def test_time_unwrap() -> None:
t = time(3, 8, 14)
elementary_test(item(t), time)
elementary_test(item(t), time, t)


def test_date_unwrap() -> None:
d = date.today()
elementary_test(item(d), date)
elementary_test(item(d), date, d)


def test_array_unwrap() -> None:
Expand All @@ -183,6 +184,7 @@ def test_array_unwrap() -> None:
assert_is_ppo(a_unwrapped[0], int)
assert_is_ppo(a_unwrapped[1], float)
assert_is_ppo(a_unwrapped[2], bool)
assert a_unwrapped == [666, 2.78, False]


def test_abstract_table_unwrap() -> None:
Expand All @@ -197,6 +199,7 @@ def test_abstract_table_unwrap() -> None:
vu = sub_table[ku]
assert_is_ppo(ku, str)
assert_is_ppo(vu, str)
assert table_unwrapped == {"table": {"foo": "bar"}, "baz": "borg"}


def test_key_comparison() -> None:
Expand Down
1 change: 1 addition & 0 deletions tests/test_toml_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def test_toml_document_unwrap() -> None:
assert_is_ppo(unwrapped["tool"], dict)
assert_is_ppo(next(iter(unwrapped["tool"])), str)
assert_is_ppo(unwrapped["tool"]["poetry"]["name"], str)
assert unwrapped == {"tool": {"poetry": {"name": "foo"}}}


def test_toml_document_with_dotted_keys(example: Callable[[str], str]) -> None:
Expand Down
7 changes: 6 additions & 1 deletion tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def assert_is_ppo(v_unwrapped: object, unwrapped_type: type) -> None:
assert isinstance(v_unwrapped, unwrapped_type)


def elementary_test(v: Item, unwrapped_type: type) -> None:
_DEFAULT = object()


def elementary_test(v: Item, unwrapped_type: type, expected: object = _DEFAULT) -> None:
v_unwrapped = v.unwrap()
assert_is_ppo(v_unwrapped, unwrapped_type)
if expected is not _DEFAULT:
assert v_unwrapped == expected