Coverage for tests / test_tutorial / test_parameter_types / test_datetime / test_tutorial001.py: 100%
26 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
1import subprocess 1abcdefgh
2import sys 1abcdefgh
4from typer.testing import CliRunner 1abcdefgh
6from docs_src.parameter_types.datetime import tutorial001_py39 as mod 1abcdefgh
8runner = CliRunner() 1abcdefgh
9app = mod.app 1abcdefgh
12def test_help(): 1abcdefgh
13 result = runner.invoke(app, ["--help"]) 1abcdefgh
14 assert result.exit_code == 0 1abcdefgh
15 assert "[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]" in result.output 1abcdefgh
18def test_main(): 1abcdefgh
19 result = runner.invoke(app, ["1956-01-31T10:00:00"]) 1abcdefgh
20 assert result.exit_code == 0 1abcdefgh
21 assert "Interesting day to be born: 1956-01-31 10:00:00" in result.output 1abcdefgh
22 assert "Birth hour: 10" in result.output 1abcdefgh
25def test_invalid(): 1abcdefgh
26 result = runner.invoke(app, ["july-19-1989"]) 1abcdefgh
27 assert result.exit_code != 0 1abcdefgh
28 assert ( 1abcdefgh
29 "Invalid value for 'BIRTH:[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]':"
30 in result.output
31 )
32 assert "'july-19-1989' does not match the formats" in result.output 1abcdefgh
33 assert "%Y-%m-%d" in result.output 1abcdefgh
34 assert "%Y-%m-%dT%H:%M:%S" in result.output 1abcdefgh
35 assert "%Y-%m-%d %H:%M:%S" in result.output 1abcdefgh
38def test_script(): 1abcdefgh
39 result = subprocess.run( 1abcdefgh
40 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
41 capture_output=True,
42 encoding="utf-8",
43 )
44 assert "Usage" in result.stdout 1abcdefgh