Skip to content

Add .coveragerc and improve coverage. #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 1, 2022
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
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[report]
exclude_lines =
pragma: no cover
if TYPE_CHECKING.*:
\.\.\.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include CITATION
include LICENSE

exclude .coveragerc
exclude *.yaml
exclude *.yml
exclude tox.ini
Expand Down
1 change: 1 addition & 0 deletions docs/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
pytask.
- :gh:`208` fixes the best practices guide for parametrizations.
- :gh:`209` cancels previous CI runs automatically.
- :gh:`212` add ``.coveragerc`` and improve coverage.


0.1.5 - 2022-01-10
Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _to_human_readable_size(bytes_: int, units: list[str] | None = None) -> str:
units = [" bytes", " KB", " MB", " GB", " TB"] if units is None else units
return (
str(bytes_) + units[0]
if bytes_ < 1024
if bytes_ < 1024 or len(units) == 1
else _to_human_readable_size(bytes_ >> 10, units[1:])
)

Expand Down
24 changes: 23 additions & 1 deletion tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from _pytask.cli import cli
from _pytask.database import create_database
from _pytask.outcomes import ExitCode
from _pytask.profile import _to_human_readable_size
from _pytask.profile import Runtime
from pony import orm
from pytask import main
Expand Down Expand Up @@ -66,7 +67,12 @@ def task_example(): time.sleep(2)
def test_profile_if_there_is_information_on_collected_tasks(tmp_path, runner):
source = """
import time
def task_example(): time.sleep(2)
import pytask

@pytask.mark.produces("out.txt")
def task_example(produces):
time.sleep(2)
produces.write_text("There are nine billion bicycles in Beijing.")
"""
tmp_path.joinpath("task_example.py").write_text(textwrap.dedent(source))

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


@pytest.mark.end_to_end
Expand All @@ -99,3 +107,17 @@ def task_example(): time.sleep(2)
assert "Duration (in s)" in result.output
assert "0." in result.output
assert tmp_path.joinpath(f"profile.{export}").exists()


@pytest.mark.parametrize(
"bytes_, units, expected",
[
(2**10, None, "1 KB"),
(2**20, None, "1 MB"),
(2**30, None, "1 GB"),
(2**30, [" bytes", " KB", " MB"], "1024 MB"),
],
)
def test_to_human_readable_size(bytes_, units, expected):
result = _to_human_readable_size(bytes_, units)
assert result == expected