Coverage for tests/test_completion/test_completion_complete_rich.py: 100%

29 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-04-14 00:18 +0000

1import os 1abcdefghi

2import subprocess 1abcdefghi

3import sys 1abcdefghi

4 

5from . import example_rich_tags as mod 1abcdefghi

6 

7 

8def test_script(): 1abcdefghi

9 result = subprocess.run( 1abcdefghi

10 [sys.executable, "-m", "coverage", "run", mod.__file__, "create", "DeadPool"], 

11 capture_output=True, 

12 encoding="utf-8", 

13 ) 

14 assert result.returncode == 0 1abcdefghi

15 assert "Creating user: DeadPool" in result.stdout 1abcdefghi

16 

17 result = subprocess.run( 1abcdefghi

18 [sys.executable, "-m", "coverage", "run", mod.__file__, "delete", "DeadPool"], 

19 capture_output=True, 

20 encoding="utf-8", 

21 ) 

22 assert result.returncode == 0 1abcdefghi

23 assert "Deleting user: DeadPool" in result.stdout 1abcdefghi

24 

25 result = subprocess.run( 1abcdefghi

26 [sys.executable, "-m", "coverage", "run", mod.__file__, "delete-all"], 

27 capture_output=True, 

28 encoding="utf-8", 

29 ) 

30 assert result.returncode == 0 1abcdefghi

31 assert "Deleting all users" in result.stdout 1abcdefghi

32 

33 

34def test_completion_complete_subcommand_bash(): 1abcdefghi

35 result = subprocess.run( 1abcdefghi

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

37 capture_output=True, 

38 encoding="utf-8", 

39 env={ 

40 **os.environ, 

41 "_EXAMPLE_RICH_TAGS.PY_COMPLETE": "complete_bash", 

42 "COMP_WORDS": "example_rich_tags.py del", 

43 "COMP_CWORD": "1", 

44 }, 

45 ) 

46 assert "delete\ndelete-all" in result.stdout 1abcdefghi

47 

48 

49def test_completion_complete_subcommand_zsh(): 1abcdefghi

50 result = subprocess.run( 1abcdefghi

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

52 capture_output=True, 

53 encoding="utf-8", 

54 env={ 

55 **os.environ, 

56 "_EXAMPLE_RICH_TAGS.PY_COMPLETE": "complete_zsh", 

57 "_TYPER_COMPLETE_ARGS": "example_rich_tags.py del", 

58 }, 

59 ) 

60 assert ( 1abcdefghi

61 """_arguments '*: :(("delete":"Delete a user with USERNAME."\n""" 

62 """\"delete-all":"Delete ALL users in the database."))'""" 

63 ) in result.stdout 

64 

65 

66def test_completion_complete_subcommand_fish(): 1abcdefghi

67 result = subprocess.run( 1abcdefghi

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

69 capture_output=True, 

70 encoding="utf-8", 

71 env={ 

72 **os.environ, 

73 "_EXAMPLE_RICH_TAGS.PY_COMPLETE": "complete_fish", 

74 "_TYPER_COMPLETE_ARGS": "example_rich_tags.py del", 

75 "_TYPER_COMPLETE_FISH_ACTION": "get-args", 

76 }, 

77 ) 

78 assert ( 1abcdefghi

79 "delete\tDelete a user with USERNAME.\ndelete-all\tDelete ALL users in the database." 

80 in result.stdout 

81 ) 

82 

83 

84def test_completion_complete_subcommand_powershell(): 1abcdefghi

85 result = subprocess.run( 1abcdefghi

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

87 capture_output=True, 

88 encoding="utf-8", 

89 env={ 

90 **os.environ, 

91 "_EXAMPLE_RICH_TAGS.PY_COMPLETE": "complete_powershell", 

92 "_TYPER_COMPLETE_ARGS": "example_rich_tags.py del", 

93 }, 

94 ) 

95 assert ( 1abcdefghi

96 "delete:::Delete a user with USERNAME.\ndelete-all:::Delete ALL users in the database." 

97 ) in result.stdout 

98 

99 

100def test_completion_complete_subcommand_pwsh(): 1abcdefghi

101 result = subprocess.run( 1abcdefghi

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

103 capture_output=True, 

104 encoding="utf-8", 

105 env={ 

106 **os.environ, 

107 "_EXAMPLE_RICH_TAGS.PY_COMPLETE": "complete_pwsh", 

108 "_TYPER_COMPLETE_ARGS": "example_rich_tags.py del", 

109 }, 

110 ) 

111 assert ( 1abcdefghi

112 "delete:::Delete a user with USERNAME.\ndelete-all:::Delete ALL users in the database." 

113 ) in result.stdout