|
| 1 | +import os |
| 2 | +import subprocess |
| 3 | +import sys |
| 4 | + |
| 5 | +from . import example_rich_tags as mod |
| 6 | + |
| 7 | + |
| 8 | +def test_script(): |
| 9 | + result = subprocess.run( |
| 10 | + [sys.executable, "-m", "coverage", "run", mod.__file__, "create", "DeadPool"], |
| 11 | + capture_output=True, |
| 12 | + encoding="utf-8", |
| 13 | + ) |
| 14 | + assert result.returncode == 0 |
| 15 | + assert "Creating user: DeadPool" in result.stdout |
| 16 | + |
| 17 | + result = subprocess.run( |
| 18 | + [sys.executable, "-m", "coverage", "run", mod.__file__, "delete", "DeadPool"], |
| 19 | + capture_output=True, |
| 20 | + encoding="utf-8", |
| 21 | + ) |
| 22 | + assert result.returncode == 0 |
| 23 | + assert "Deleting user: DeadPool" in result.stdout |
| 24 | + |
| 25 | + result = subprocess.run( |
| 26 | + [sys.executable, "-m", "coverage", "run", mod.__file__, "delete-all"], |
| 27 | + capture_output=True, |
| 28 | + encoding="utf-8", |
| 29 | + ) |
| 30 | + assert result.returncode == 0 |
| 31 | + assert "Deleting all users" in result.stdout |
| 32 | + |
| 33 | + |
| 34 | +def test_completion_complete_subcommand_bash(): |
| 35 | + result = subprocess.run( |
| 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 |
| 47 | + |
| 48 | + |
| 49 | +def test_completion_complete_subcommand_zsh(): |
| 50 | + result = subprocess.run( |
| 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 ( |
| 61 | + """_arguments '*: :(("delete":"Delete a user with USERNAME."\n""" |
| 62 | + """\"delete-all":"Delete ALL users in the database."))'""" |
| 63 | + ) in result.stdout |
| 64 | + |
| 65 | + |
| 66 | +def test_completion_complete_subcommand_fish(): |
| 67 | + result = subprocess.run( |
| 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 ( |
| 79 | + "delete\tDelete a user with USERNAME.\ndelete-all\tDelete ALL users in the database." |
| 80 | + in result.stdout |
| 81 | + ) |
| 82 | + |
| 83 | + |
| 84 | +def test_completion_complete_subcommand_powershell(): |
| 85 | + result = subprocess.run( |
| 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 ( |
| 96 | + "delete:::Delete a user with USERNAME.\ndelete-all:::Delete ALL users in the database." |
| 97 | + ) in result.stdout |
| 98 | + |
| 99 | + |
| 100 | +def test_completion_complete_subcommand_pwsh(): |
| 101 | + result = subprocess.run( |
| 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 ( |
| 112 | + "delete:::Delete a user with USERNAME.\ndelete-all:::Delete ALL users in the database." |
| 113 | + ) in result.stdout |
0 commit comments