Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Test flatten_literal_params #5

Merged
merged 6 commits into from
Jun 12, 2024
Merged
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ Running `coverage html` and opening the document in the browser gives the follow

Thijmen

flatten_literal_params

[commit](https://github.com/tthijm/sep/commit/2afde74ee94eb7e6cdc476356aa41f1ca09d87cf)

![](./assets/flatten_literal_params_custom.png)

\_human_join

[commit](https://github.com/tthijm/sep/commit/88c98ebc05c4d67bcdce7d3046ffa786f79b9284)
Expand Down Expand Up @@ -70,6 +76,17 @@ Thijmen

Thijmen

test_flatten_literal_params

[commit](https://github.com/tthijm/sep/commit/18e8104041610c32f9dedff6740688c4d1934550) + [commit](https://github.com/tthijm/sep/commit/138ca9a4c4b0a5f8fba254271f6b913b80d20b95)

![](./assets/flatten_literal_params_before.png)

![](./assets/flatten_literal_params_after.png)

The coverage improvement is +100%.
The coverage has been improved, because `flatten_literal_params` used to not be tested, while the new `test_flatten_literal_params` considers every branch to be taken.

test\_\_human_join

[commit](https://github.com/tthijm/sep/commit/92796db0afb5feff4b51b3c7e4874c2ba0eae7b9)
Expand Down
Binary file added assets/flatten_literal_params_after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/flatten_literal_params_before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/flatten_literal_params_custom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,21 @@ def test_format_dt(dt: datetime.datetime, style: typing.Optional[utils.Timestamp
assert utils.format_dt(dt, style=style) == formatted


@pytest.mark.parametrize(
("parameters", "flattened"),
[
# Python 3.8: Literal[Literal[0]].__args__ == (Literal[0],)
# Python 3.x: Literal[Literal[0]].__args__ == (0,)
([], ()),
([0, 1, 2], (0, 1, 2)),
([0, typing.Literal["a", 1], "b"], (0, "a", 1, "b")),
([0, "a", typing.Literal[1, "b", 2], typing.Literal["c"]], (0, "a", 1, "b", 2, "c")),
],
)
def test_flatten_literal_params(parameters: typing.Iterable[typing.Any], flattened: typing.Tuple[typing.Any, ...]) -> None:
assert utils.flatten_literal_params(parameters) == flattened


def test__human_join() -> None:
assert utils._human_join([]) == ""
assert utils._human_join(["cat"]) == "cat"
Expand Down
Loading