Coverage for tests / test_tutorial / test_parameter_types / test_datetime / test_tutorial001.py: 100%
29 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
1import subprocess 1abcdefghij
2import sys 1abcdefghij
3from datetime import datetime 1abcdefghij
5from typer.testing import CliRunner 1abcdefghij
7from docs_src.parameter_types.datetime import tutorial001 as mod 1abcdefghij
9runner = CliRunner() 1abcdefghij
10app = mod.app 1abcdefghij
13def test_help(): 1abcdefghij
14 result = runner.invoke(app, ["--help"]) 1abcdefghij
15 assert result.exit_code == 0 1abcdefghij
16 assert "<datetime>" in result.output 1abcdefghij
19def test_main(): 1abcdefghij
20 result = runner.invoke(app, ["1956-01-31T10:00:00"]) 1abcdefghij
21 assert result.exit_code == 0 1abcdefghij
22 assert "Interesting day to be born: 1956-01-31 10:00:00" in result.output 1abcdefghij
23 assert "Birth hour: 10" in result.output 1abcdefghij
26def test_main_datetime_object(): 1abcdefghij
27 result = runner.invoke( 1abcdefghij
28 app, [], default_map={"birth": datetime(1956, 1, 31, 10, 0, 0)}
29 )
30 assert result.exit_code == 0 1abcdefghij
31 assert "Interesting day to be born: 1956-01-31 10:00:00" in result.output 1abcdefghij
32 assert "Birth hour: 10" in result.output 1abcdefghij
35def test_invalid(): 1abcdefghij
36 result = runner.invoke(app, ["july-19-1989"]) 1abcdefghij
37 assert result.exit_code != 0 1abcdefghij
38 assert "Invalid value for 'birth'" in result.output 1abcdefghij
39 assert "should be a valid datetime" in result.output 1abcdefghij
42def test_script(): 1abcdefghij
43 result = subprocess.run( 1abcdefghij
44 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
45 capture_output=True,
46 encoding="utf-8",
47 )
48 assert "Usage" in result.stdout 1abcdefghij