File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed
Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ packages = [
1313]
1414
1515[tool .poetry .scripts ]
16- template_bin = ' sample.main:run '
16+ template_bin = ' sample.main:main '
1717
1818[tool .poetry .dependencies ]
1919python = " ~3.14"
Original file line number Diff line number Diff line change 11"""Main template."""
22
3+ import sys
4+
35import numpy as np
46
57
@@ -27,3 +29,10 @@ def run(k: int = 10) -> list[float]:
2729 list samples of size k
2830 """
2931 return get_sample (k )
32+
33+
34+ def main () -> int :
35+ """Run default sample generation for CLI usage."""
36+ sample = run ()
37+ sys .stdout .write (f"{ sample } \n " )
38+ return 0
Original file line number Diff line number Diff line change 22
33import pytest
44
5- from sample .main import get_sample , run
5+ from sample .main import get_sample , main , run
66
77
88def test_get_sample_returns_requested_number_of_values () -> None :
@@ -29,3 +29,17 @@ def fake_get_sample(k: int) -> list[float]:
2929
3030 monkeypatch .setattr ("sample.main.get_sample" , fake_get_sample )
3131 assert run (2 ) == expected
32+
33+
34+ def test_main_writes_sample_and_returns_zero (
35+ monkeypatch : pytest .MonkeyPatch ,
36+ capsys : pytest .CaptureFixture [str ],
37+ ) -> None :
38+ """Main writes the sample to stdout and exits with status code 0."""
39+ expected = [0.1 , 0.2 ]
40+
41+ monkeypatch .setattr ("sample.main.run" , lambda : expected )
42+
43+ assert main () == 0
44+ captured = capsys .readouterr ()
45+ assert captured .out .strip () == str (expected )
You can’t perform that action at this time.
0 commit comments