-
Notifications
You must be signed in to change notification settings - Fork 24
/
clikan_test.py
executable file
·250 lines (197 loc) · 7.5 KB
/
clikan_test.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/usr/bin/env python
import click
from click.testing import CliRunner
from clikan import configure, clikan, add, promote, show, regress, delete
import os
import pathlib
import tempfile
# Configure Tests
def test_command_help():
runner = CliRunner()
result = runner.invoke(clikan, ["--help"])
assert result.exit_code == 0
assert 'Usage: clikan [OPTIONS] COMMAND [ARGS]...' in result.output
assert 'clikan: CLI personal kanban' in result.output
def test_command_version():
version_file = open(os.path.join('./', 'VERSION'))
version = version_file.read().strip()
runner = CliRunner()
result = runner.invoke(clikan, ["--version"])
assert result.exit_code == 0
assert 'clikan, version {}'.format(version) in result.output
def test_command_configure(tmp_path):
runner = CliRunner()
with tempfile.TemporaryDirectory() as tmpdirname:
with runner.isolation(
input=None,
env={"CLIKAN_HOME": tmpdirname},
color=False
):
result = runner.invoke(clikan, ["configure"])
assert result.exit_code == 0
assert 'Creating' in result.output
def test_command_configure_existing():
runner = CliRunner()
with runner.isolated_filesystem():
runner.invoke(clikan, ["configure"])
result = runner.invoke(clikan, ["configure"])
assert 'Config file exists' in result.output
## Single Argument Tests
# Add Tests
def test_command_a():
runner = CliRunner()
result = runner.invoke(clikan, ["a", "n_--task_test"])
assert result.exit_code == 0
assert 'n_--task_test' in result.output
# Show Tests
def test_no_command():
runner = CliRunner()
result = runner.invoke(clikan, [])
assert result.exit_code == 0
assert 'n_--task_test' in result.output
def test_command_s():
runner = CliRunner()
result = runner.invoke(clikan, ["s"])
assert result.exit_code == 0
assert 'n_--task_test' in result.output
def test_command_show():
runner = CliRunner()
result = runner.invoke(show)
assert result.exit_code == 0
assert 'n_--task_test' in result.output
def test_command_not_show():
runner = CliRunner()
result = runner.invoke(show)
assert result.exit_code == 0
assert 'blahdyblah' not in result.output
# Promote Tests
def test_command_promote():
runner = CliRunner()
result = runner.invoke(clikan, ['promote', '1'])
assert result.exit_code == 0
assert 'Promoting task 1 to in-progress.' in result.output
result = runner.invoke(clikan, ['promote', '1'])
assert result.exit_code == 0
assert 'Promoting task 1 to done.' in result.output
# Delete Tests
def test_command_delete():
runner = CliRunner()
result = runner.invoke(clikan, ['delete', '1'])
assert result.exit_code == 0
assert 'Removed task 1.' in result.output
result = runner.invoke(clikan, ['delete', '1'])
assert result.exit_code == 0
assert 'No existing task with' in result.output
## Multiple Argument Tests
# Add Tests
def test_command_a_multi():
runner = CliRunner()
result = runner.invoke(clikan, ["a", "n_--task_test_multi_1", "n_--task_test_multi_2", "n_--task_test_multi_3"])
assert result.exit_code == 0
assert 'n_--task_test' in result.output
# Show Test
def test_command_show_multi():
runner = CliRunner()
result = runner.invoke(show)
assert result.exit_code == 0
assert 'n_--task_test_multi_1' in result.output
assert 'n_--task_test_multi_2' in result.output
assert 'n_--task_test_multi_3' in result.output
# Promote Tests
def test_command_promote_multi():
runner = CliRunner()
result = runner.invoke(clikan, ['promote', '1', '2'])
assert result.exit_code == 0
assert 'Promoting task 1 to in-progress.' in result.output
assert 'Promoting task 2 to in-progress.' in result.output
result = runner.invoke(clikan, ['promote', '2', '3'])
assert result.exit_code == 0
assert 'Promoting task 2 to done.' in result.output
assert 'Promoting task 3 to in-progress.' in result.output
# Delete Tests
def test_command_delete_multi():
runner = CliRunner()
result = runner.invoke(clikan, ['delete', '1', '2'])
assert result.exit_code == 0
assert 'Removed task 1.' in result.output
assert 'Removed task 2.' in result.output
result = runner.invoke(clikan, ['delete', '1', '2'])
assert result.exit_code == 0
assert 'No existing task with that id: 1' in result.output
assert 'No existing task with that id: 2' in result.output
# Show after delete Test
def test_command_show_multi_after_delete():
runner = CliRunner()
result = runner.invoke(show)
assert result.exit_code == 0
assert 'n_--task_test_multi_1' not in result.output
assert 'n_--task_test_multi_2' not in result.output
assert 'n_--task_test_multi_3' in result.output
# Repaint Tests
def test_repaint_config_option():
runner = CliRunner()
version_file = open(os.path.join('./', 'VERSION'))
version = version_file.read().strip()
path_to_config = str(pathlib.Path("./tests/repaint").resolve())
with runner.isolation(
input=None,
env={"CLIKAN_HOME": path_to_config},
color=False
):
result = runner.invoke(clikan, [])
assert result.exit_code == 0
assert 'clikan' in result.output
result = runner.invoke(clikan, ["a", "n_--task_test"])
assert result.exit_code == 0
assert 'n_--task_test' in result.output
assert version in result.output
def test_no_repaint_config_option():
runner = CliRunner()
version_file = open(os.path.join('./', 'VERSION'))
version = version_file.read().strip()
path_to_config = str(pathlib.Path("./tests/no_repaint").resolve())
with runner.isolation(
input=None,
env={"CLIKAN_HOME": path_to_config},
color=False
):
result = runner.invoke(clikan, [])
assert result.exit_code == 0
assert 'clikan' in result.output
result = runner.invoke(clikan, ["a", "n_--task_test"])
assert result.exit_code == 0
assert 'n_--task_test' in result.output
assert version not in result.output
# Limit on task name length tests
def test_taskname_config_option():
runner = CliRunner()
version_file = open(os.path.join('./', 'VERSION'))
version = version_file.read().strip()
path_to_config = str(pathlib.Path("./tests/taskname").resolve())
with runner.isolation(
input=None,
env={"CLIKAN_HOME": path_to_config},
color=False
):
result = runner.invoke(clikan, [])
assert result.exit_code == 0
assert 'clikan' in result.output
result = runner.invoke(clikan, ["a", "This is a long task name, more than 40 characters (66 to be exact)"])
assert result.exit_code == 0
assert 'This is a long task name, more than 40 characters (66 to be exact)' in result.output
def test_no_taskname_config_option():
runner = CliRunner()
version_file = open(os.path.join('./', 'VERSION'))
version = version_file.read().strip()
path_to_config = str(pathlib.Path("./tests/no_taskname").resolve())
with runner.isolation(
input=None,
env={"CLIKAN_HOME": path_to_config},
color=False
):
result = runner.invoke(clikan, [])
assert result.exit_code == 0
assert 'clikan' in result.output
result = runner.invoke(clikan, ["a", "This is a long task name, more than 40 characters (66 to be exact)"])
assert result.exit_code == 0
assert 'Brevity counts:' in result.output