Coverage for tests / test_tutorial / test_parameter_types / test_uuid / test_tutorial001.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-11-18 11:12 +0000

1import subprocess 1abcdefghij

2import sys 1abcdefghij

3import uuid 1abcdefghij

4 

5from typer.testing import CliRunner 1abcdefghij

6 

7from docs_src.parameter_types.uuid import tutorial001 as mod 1abcdefghij

8 

9runner = CliRunner() 1abcdefghij

10app = mod.app 1abcdefghij

11 

12 

13def test_main(): 1abcdefghij

14 result = runner.invoke(app, ["d48edaa6-871a-4082-a196-4daab372d4a1"]) 1abcdefghij

15 assert result.exit_code == 0 1abcdefghij

16 assert "User ID is d48edaa6-871a-4082-a196-4daab372d4a1" in result.output 1abcdefghij

17 assert "UUID version is: 4" in result.output 1abcdefghij

18 

19 

20def test_main_with_uuid_object(): 1abcdefghij

21 user_id = uuid.UUID("d48edaa6-871a-4082-a196-4daab372d4a1") 1abcdefghij

22 result = runner.invoke(app, [], default_map={"user_id": user_id}) 1abcdefghij

23 assert result.exit_code == 0 1abcdefghij

24 assert "User ID is d48edaa6-871a-4082-a196-4daab372d4a1" in result.output 1abcdefghij

25 assert "UUID version is: 4" in result.output 1abcdefghij

26 

27 

28def test_invalid_uuid(): 1abcdefghij

29 result = runner.invoke(app, ["7479706572-72756c6573"]) 1abcdefghij

30 assert result.exit_code != 0 1abcdefghij

31 assert "Invalid value for 'user_id'" in result.output 1abcdefghij

32 assert "should be a valid UUID" in result.output 1abcdefghij

33 

34 

35def test_script(): 1abcdefghij

36 result = subprocess.run( 1abcdefghij

37 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"], 

38 capture_output=True, 

39 encoding="utf-8", 

40 ) 

41 assert "Usage" in result.stdout 1abcdefghij