-
-
Notifications
You must be signed in to change notification settings - Fork 87
/
test_completions_command.py
85 lines (63 loc) · 2.27 KB
/
test_completions_command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
import os
import pytest
from cleo import Application
from cleo import CommandTester
from .fixtures.hello_command import HelloCommand
from .fixtures.command_with_colons import CommandWithColons
app = Application()
app.add(HelloCommand())
app.add(CommandWithColons())
def test_invalid_shell():
command = app.find("completions")
tester = CommandTester(command)
with pytest.raises(ValueError):
tester.execute("pomodoro")
def test_bash(mocker):
mocker.patch(
"clikit.api.args.args.Args.script_name",
new_callable=mocker.PropertyMock,
return_value="/path/to/my/script",
)
mocker.patch(
"cleo.commands.completions_command.CompletionsCommand._generate_function_name",
return_value="_my_function",
)
command = app.find("completions")
tester = CommandTester(command)
tester.execute("bash")
with open(os.path.join(os.path.dirname(__file__), "fixtures", "bash.txt")) as f:
expected = f.read()
assert expected == tester.io.fetch_output().replace("\r\n", "\n")
def test_zsh(mocker):
mocker.patch(
"clikit.api.args.args.Args.script_name",
new_callable=mocker.PropertyMock,
return_value="/path/to/my/script",
)
mocker.patch(
"cleo.commands.completions_command.CompletionsCommand._generate_function_name",
return_value="_my_function",
)
command = app.find("completions")
tester = CommandTester(command)
tester.execute("zsh")
with open(os.path.join(os.path.dirname(__file__), "fixtures", "zsh.txt")) as f:
expected = f.read()
assert expected == tester.io.fetch_output().replace("\r\n", "\n")
def test_fish(mocker):
mocker.patch(
"clikit.api.args.args.Args.script_name",
new_callable=mocker.PropertyMock,
return_value="/path/to/my/script",
)
mocker.patch(
"cleo.commands.completions_command.CompletionsCommand._generate_function_name",
return_value="_my_function",
)
command = app.find("completions")
tester = CommandTester(command)
tester.execute("fish")
with open(os.path.join(os.path.dirname(__file__), "fixtures", "fish.txt")) as f:
expected = f.read()
assert expected == tester.io.fetch_output().replace("\r\n", "\n")