diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..fd5df4bf --- /dev/null +++ b/.coveragerc @@ -0,0 +1,5 @@ +[report] +exclude_lines = + pragma: no cover + if TYPE_CHECKING.*: + \.\.\. diff --git a/MANIFEST.in b/MANIFEST.in index 97dc9c8c..1b7a4eb9 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,7 @@ include CITATION include LICENSE +exclude .coveragerc exclude *.yaml exclude *.yml exclude tox.ini diff --git a/docs/source/changes.rst b/docs/source/changes.rst index 42a92864..e3d19f6d 100644 --- a/docs/source/changes.rst +++ b/docs/source/changes.rst @@ -36,6 +36,7 @@ all releases are available on `PyPI `_ 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 diff --git a/src/_pytask/profile.py b/src/_pytask/profile.py index 0da72b25..3e89aa37 100644 --- a/src/_pytask/profile.py +++ b/src/_pytask/profile.py @@ -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:]) ) diff --git a/tests/test_profile.py b/tests/test_profile.py index fbb8904f..ff7a6efb 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -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 @@ -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)) @@ -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 @@ -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