77from _pytask .cli import cli
88from _pytask .database import create_database
99from _pytask .outcomes import ExitCode
10+ from _pytask .profile import _to_human_readable_size
1011from _pytask .profile import Runtime
1112from pony import orm
1213from pytask import main
@@ -66,7 +67,12 @@ def task_example(): time.sleep(2)
6667def 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