Skip to content

Commit fb432e5

Browse files
authored
Add .coveragerc and improve coverage. (#213)
1 parent 3165454 commit fb432e5

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

.coveragerc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[report]
2+
exclude_lines =
3+
pragma: no cover
4+
if TYPE_CHECKING.*:
5+
\.\.\.

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include CITATION
22
include LICENSE
33

4+
exclude .coveragerc
45
exclude *.yaml
56
exclude *.yml
67
exclude tox.ini

docs/source/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
3636
pytask.
3737
- :gh:`208` fixes the best practices guide for parametrizations.
3838
- :gh:`209` cancels previous CI runs automatically.
39+
- :gh:`212` add ``.coveragerc`` and improve coverage.
3940

4041

4142
0.1.5 - 2022-01-10

src/_pytask/profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def _to_human_readable_size(bytes_: int, units: list[str] | None = None) -> str:
232232
units = [" bytes", " KB", " MB", " GB", " TB"] if units is None else units
233233
return (
234234
str(bytes_) + units[0]
235-
if bytes_ < 1024
235+
if bytes_ < 1024 or len(units) == 1
236236
else _to_human_readable_size(bytes_ >> 10, units[1:])
237237
)
238238

tests/test_profile.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from _pytask.cli import cli
88
from _pytask.database import create_database
99
from _pytask.outcomes import ExitCode
10+
from _pytask.profile import _to_human_readable_size
1011
from _pytask.profile import Runtime
1112
from pony import orm
1213
from pytask import main
@@ -66,7 +67,12 @@ def task_example(): time.sleep(2)
6667
def test_profile_if_there_is_information_on_collected_tasks(tmp_path, runner):
6768
source = """
6869
import time
69-
def task_example(): time.sleep(2)
70+
import pytask
71+
72+
@pytask.mark.produces("out.txt")
73+
def task_example(produces):
74+
time.sleep(2)
75+
produces.write_text("There are nine billion bicycles in Beijing.")
7076
"""
7177
tmp_path.joinpath("task_example.py").write_text(textwrap.dedent(source))
7278

@@ -78,6 +84,8 @@ def task_example(): time.sleep(2)
7884
assert "Collected 1 task." in result.output
7985
assert "Duration (in s)" in result.output
8086
assert "0." in result.output
87+
assert "Size of Products" in result.output
88+
assert "43 bytes" in result.output
8189

8290

8391
@pytest.mark.end_to_end
@@ -99,3 +107,17 @@ def task_example(): time.sleep(2)
99107
assert "Duration (in s)" in result.output
100108
assert "0." in result.output
101109
assert tmp_path.joinpath(f"profile.{export}").exists()
110+
111+
112+
@pytest.mark.parametrize(
113+
"bytes_, units, expected",
114+
[
115+
(2**10, None, "1 KB"),
116+
(2**20, None, "1 MB"),
117+
(2**30, None, "1 GB"),
118+
(2**30, [" bytes", " KB", " MB"], "1024 MB"),
119+
],
120+
)
121+
def test_to_human_readable_size(bytes_, units, expected):
122+
result = _to_human_readable_size(bytes_, units)
123+
assert result == expected

0 commit comments

Comments
 (0)