forked from click-contrib/click-didyoumean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_core.py
134 lines (105 loc) · 2.59 KB
/
test_core.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import click
import pytest
from click.testing import CliRunner
from click_didyoumean import DYMCommandCollection, DYMGroup
@pytest.fixture()
def runner():
return CliRunner()
def test_basic_functionality_with_group(runner):
@click.group(cls=DYMGroup)
def cli():
pass
@cli.command()
def foo():
pass
@cli.command()
def bar():
pass
@cli.command()
def barrr():
pass
result = runner.invoke(cli, ["barr"])
assert result.output == (
"Usage: cli [OPTIONS] COMMAND [ARGS]...\n"
"Try 'cli --help' for help.\n"
"\n"
"Error: No such command 'barr'.\n\n"
"Did you mean one of these?\n"
" barrr\n"
" bar\n"
)
def test_basic_functionality_with_commandcollection(runner):
@click.group()
def cli1():
pass
@cli1.command()
def foo():
pass
@cli1.command()
def bar():
pass
@click.group()
def cli2():
pass
@cli2.command()
def barrr():
pass
cli = DYMCommandCollection(sources=[cli1, cli2])
result = runner.invoke(cli, ["barr"])
assert result.output == (
"Usage: root [OPTIONS] COMMAND [ARGS]...\n"
"Try 'root --help' for help.\n"
"\n"
"Error: No such command 'barr'.\n\n"
"Did you mean one of these?\n"
" barrr\n"
" bar\n"
)
def test_cutoff_factor(runner):
@click.group(cls=DYMGroup, max_suggestions=3, cutoff=1.0)
def cli():
pass
@cli.command()
def foo():
pass
@cli.command()
def bar():
pass
@cli.command()
def barrr():
pass
# if cutoff factor is 1.0 the match must be perfect.
result = runner.invoke(cli, ["barr"])
assert result.output == (
"Usage: cli [OPTIONS] COMMAND [ARGS]...\n"
"Try 'cli --help' for help.\n"
"\n"
"Error: No such command 'barr'.\n"
)
def test_max_suggetions(runner):
@click.group(cls=DYMGroup, max_suggestions=2, cutoff=0.5)
def cli():
pass
@cli.command()
def foo():
pass
@cli.command()
def bar():
pass
@cli.command()
def barrr():
pass
@cli.command()
def baarr():
pass
# if cutoff factor is 1.0 the match must be perfect.
result = runner.invoke(cli, ["barr"])
assert result.output == (
"Usage: cli [OPTIONS] COMMAND [ARGS]...\n"
"Try 'cli --help' for help.\n"
"\n"
"Error: No such command 'barr'.\n\n"
"Did you mean one of these?\n"
" barrr\n"
" baarr\n"
)