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

Commit

Permalink
Test _human_join (#6)
Browse files Browse the repository at this point in the history
* Add custom coverage test

* Revert "Add custom coverage test"

* Add test

* Add coverages to report
  • Loading branch information
tthijm authored Jun 12, 2024
1 parent 824a293 commit 043e75e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ docs/crowdin.py
*.mo
/.coverage
build/*
!assets/*
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ Programming language: <TODO>
## Coverage measurement

### Existing tool
The coverage tool [coverage.py](https://coverage.readthedocs.io/en/7.5.3/) was used for this project.

The coverage tool [coverage.py](https://coverage.readthedocs.io/en/7.5.3/) was used for this project.
After installing the dependencies and executing `coverage run -m pytest` we get the following output:
![63781](https://github.com/tthijm/sep/assets/74216566/0962f4e0-a7f4-45c0-ab12-59110c55d6c2)

Running `coverage html` and opening the document in the browser gives the following:
![23724](https://github.com/tthijm/sep/assets/74216566/5991a9ef-81a1-494f-8016-700ee72d375e)
![4629](https://github.com/tthijm/sep/assets/74216566/83bdba3d-9217-4be0-a67c-9ae2f0db3ad9)


### Your own coverage tool

<The following is supposed to be repeated for each group member>
Expand All @@ -38,6 +38,14 @@ Running `coverage html` and opening the document in the browser gives the follow

<Provide the same kind of information provided for Function 1>

Thijmen

\_human_join

[commit](https://github.com/tthijm/sep/commit/88c98ebc05c4d67bcdce7d3046ffa786f79b9284)

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

## Coverage improvement

### Individual tests
Expand All @@ -60,6 +68,19 @@ Running `coverage html` and opening the document in the browser gives the follow

<Provide the same kind of information provided for Test 1>

Thijmen

test\_\_human_join

[commit](https://github.com/tthijm/sep/commit/92796db0afb5feff4b51b3c7e4874c2ba0eae7b9)

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

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

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

### Overall

<Provide a screenshot of the old coverage results by running an existing tool (the same as you already showed above)>
Expand Down
Binary file added assets/_human_join_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/_human_join_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/_human_join_custom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,11 @@ def test_is_inside_class():
)
def test_format_dt(dt: datetime.datetime, style: typing.Optional[utils.TimestampStyle], formatted: str):
assert utils.format_dt(dt, style=style) == formatted


def test__human_join() -> None:
assert utils._human_join([]) == ""
assert utils._human_join(["cat"]) == "cat"
assert utils._human_join(["cat", "dog"]) == "cat or dog"
assert utils._human_join(["cat", "dog", "fish"]) == "cat, dog or fish"
assert utils._human_join(["cat", "dog", "fish", "bird"], delimiter="; ", final="and") == "cat; dog; fish and bird"

0 comments on commit 043e75e

Please sign in to comment.