1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
|
3
|
|
|
# pylint: disable=redefined-outer-name,unused-variable,expression-not-assigned |
4
|
|
|
|
5
|
|
|
from __future__ import unicode_literals |
6
|
|
|
|
7
|
|
|
import logging |
8
|
|
|
import os |
9
|
|
|
import sys |
10
|
|
|
|
11
|
|
|
import pytest |
12
|
|
|
import scripttest |
13
|
|
|
from expecter import expect |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
TESTS_DIR = os.path.abspath(os.path.dirname(__file__)) |
17
|
|
|
ROOT_DIR = os.path.join(TESTS_DIR, "..") |
18
|
|
|
EXAMPLES_DIR = os.path.join(ROOT_DIR, "examples") |
19
|
|
|
BIN_DIR = os.path.join(EXAMPLES_DIR, "bin") |
20
|
|
|
|
21
|
|
|
STYLED_OUTPUT = """ |
22
|
|
|
Checking for Working Program... |
23
|
|
|
|
24
|
|
|
$ working-program --version |
25
|
|
|
1.2.3 |
26
|
|
|
✔ MATCHED: 1.2 |
27
|
|
|
|
28
|
|
|
Checking for Newer Working Program... |
29
|
|
|
|
30
|
|
|
$ working-program --version |
31
|
|
|
1.2.3 |
32
|
|
|
✘ EXPECTED: 4.1 | 4.2 |
33
|
|
|
⭑ MESSAGE: Version 4.x is required to get the special features. |
34
|
|
|
|
35
|
|
|
Checking for Broken Program... |
36
|
|
|
|
37
|
|
|
$ broken-program --version |
38
|
|
|
An error occurred. |
39
|
|
|
✘ EXPECTED: 1.2.3 |
40
|
|
|
|
41
|
|
|
Checking for Optional Missing Program... |
42
|
|
|
|
43
|
|
|
$ missing-program --version |
44
|
|
|
sh: command not found: missing-program |
45
|
|
|
⚠ EXPECTED: 1.2.3 |
46
|
|
|
|
47
|
|
|
Checking for Missing Program... |
48
|
|
|
|
49
|
|
|
$ missing-program --version |
50
|
|
|
sh: command not found: missing-program |
51
|
|
|
✘ EXPECTED: 1.2.3 |
52
|
|
|
|
53
|
|
|
Results: ✔ ✘ ✘ ⚠ ✘ |
54
|
|
|
|
55
|
|
|
""" |
56
|
|
|
|
57
|
|
|
UNSTYLED_OUTPUT = STYLED_OUTPUT \ |
58
|
|
|
.replace('✔', '~').replace('⭑', '*').replace('⚠', '?').replace('✘', 'x') |
59
|
|
|
|
60
|
|
|
UNSTYLED_OUTPUT_WINDOWS = """ |
61
|
|
|
Checking for Working Program... |
62
|
|
|
|
63
|
|
|
$ working-program --version |
64
|
|
|
sh: command not found: working-program |
65
|
|
|
x EXPECTED: 1.2 |
66
|
|
|
|
67
|
|
|
Checking for Newer Working Program... |
68
|
|
|
|
69
|
|
|
$ working-program --version |
70
|
|
|
sh: command not found: working-program |
71
|
|
|
x EXPECTED: 4.1 | 4.2 |
72
|
|
|
* MESSAGE: Version 4.x is required to get the special features. |
73
|
|
|
|
74
|
|
|
Checking for Broken Program... |
75
|
|
|
|
76
|
|
|
$ broken-program --version |
77
|
|
|
sh: command not found: broken-program |
78
|
|
|
x EXPECTED: 1.2.3 |
79
|
|
|
|
80
|
|
|
Checking for Optional Missing Program... |
81
|
|
|
|
82
|
|
|
$ missing-program --version |
83
|
|
|
sh: command not found: missing-program |
84
|
|
|
? EXPECTED: 1.2.3 |
85
|
|
|
|
86
|
|
|
Checking for Missing Program... |
87
|
|
|
|
88
|
|
|
$ missing-program --version |
89
|
|
|
sh: command not found: missing-program |
90
|
|
|
x EXPECTED: 1.2.3 |
91
|
|
|
|
92
|
|
|
Results: x x x ? x |
93
|
|
|
|
94
|
|
|
""" |
95
|
|
|
|
96
|
|
|
log = logging.getLogger(__name__) |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
@pytest.fixture |
100
|
|
|
def env(tmpdir): |
101
|
|
|
path = str(tmpdir.join("test")) |
102
|
|
|
env = scripttest.TestFileEnvironment(path) |
103
|
|
|
os.chdir(path) |
104
|
|
|
env.environ['PATH'] = BIN_DIR |
105
|
|
|
log.debug("ENV: %s", env.environ) |
106
|
|
|
return env |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
@pytest.fixture |
110
|
|
|
def cli(env): |
111
|
|
|
path = os.path.join(os.path.dirname(sys.executable), "verchew") |
112
|
|
|
return lambda *args: call(env, path, *args) |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
def call(env, path, *args): |
116
|
|
|
log.info("$ %s %s", path, ' '.join(args)) |
117
|
|
|
return env.run(path, *args, expect_error=True) |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
def describe_meta(): |
121
|
|
|
|
122
|
|
|
def it_displays_help_information(cli): |
123
|
|
|
cmd = cli('--help') |
124
|
|
|
|
125
|
|
|
expect(cmd.stdout).contains("usage: verchew") |
126
|
|
|
expect(cmd.returncode) == 0 |
127
|
|
|
|
128
|
|
|
def it_displays_version_information(cli): |
129
|
|
|
cmd = cli('--version') |
130
|
|
|
|
131
|
|
|
expect(cmd.stdout or cmd.stderr).contains("verchew v1.") |
132
|
|
|
expect(cmd.returncode) == 0 |
133
|
|
|
|
134
|
|
|
def describe_init(): |
135
|
|
|
|
136
|
|
|
def it_generates_a_sample_config(cli): |
137
|
|
|
cmd = cli('--init') |
138
|
|
|
|
139
|
|
|
expect(cmd.stderr) == "" |
140
|
|
|
expect(cmd.stdout).contains("Checking for Make") |
141
|
|
|
expect(cmd.returncode) == 0 |
142
|
|
|
|
143
|
|
|
def describe_main(): |
144
|
|
|
|
145
|
|
|
@pytest.mark.skipif( |
146
|
|
|
sys.version_info[0] == 2 or sys.platform == 'win32', |
147
|
|
|
reason="unix and python3 only", |
148
|
|
|
) |
149
|
|
|
def it_displays_results_on_unix_python_3(cli): |
150
|
|
|
cmd = cli('--root', EXAMPLES_DIR) |
151
|
|
|
|
152
|
|
|
expect(cmd.stderr) == "" |
153
|
|
|
expect(cmd.stdout) == STYLED_OUTPUT |
154
|
|
|
expect(cmd.returncode) == 0 |
155
|
|
|
|
156
|
|
|
@pytest.mark.skipif( |
157
|
|
|
sys.version_info[0] == 3 or sys.platform == 'win32', |
158
|
|
|
reason="unix and python2 only", |
159
|
|
|
) |
160
|
|
|
def it_displays_results_on_unix_python_2(cli): |
161
|
|
|
cmd = cli('--root', EXAMPLES_DIR) |
162
|
|
|
|
163
|
|
|
expect(cmd.stderr) == "" |
164
|
|
|
expect(cmd.stdout) == UNSTYLED_OUTPUT |
165
|
|
|
expect(cmd.returncode) == 0 |
166
|
|
|
|
167
|
|
|
@pytest.mark.skipif(sys.platform != 'win32', reason="windows only") |
168
|
|
|
def it_displays_results_on_windows(cli): |
169
|
|
|
cmd = cli('--root', EXAMPLES_DIR) |
170
|
|
|
|
171
|
|
|
expect(cmd.stderr) == "" |
172
|
|
|
expect(cmd.stdout) == UNSTYLED_OUTPUT_WINDOWS |
173
|
|
|
expect(cmd.returncode) == 0 |
174
|
|
|
|
175
|
|
|
def it_exits_with_an_error_code_if_enabled(cli): |
176
|
|
|
cmd = cli('--root', EXAMPLES_DIR, '--exit-code') |
177
|
|
|
|
178
|
|
|
expect(cmd.returncode) == 1 |
179
|
|
|
|
180
|
|
|
def describe_quiet(): |
181
|
|
|
|
182
|
|
View Code Duplication |
@pytest.mark.skipif(sys.platform == 'win32', reason="unix only") |
|
|
|
|
183
|
|
|
def it_hides_output_when_no_error(cli, tmp_path): |
184
|
|
|
verchew_ini = tmp_path / 'verchew.ini' |
185
|
|
|
verchew_ini.write_text(""" |
186
|
|
|
[Working Program] |
187
|
|
|
|
188
|
|
|
cli = working-program |
189
|
|
|
version = 1.2 |
190
|
|
|
""") |
191
|
|
|
|
192
|
|
|
cmd = cli('--root', str(tmp_path), '--quiet') |
193
|
|
|
|
194
|
|
|
expect(cmd.stderr) == "" |
195
|
|
|
expect(cmd.stdout) == "" |
196
|
|
|
expect(cmd.returncode) == 0 |
197
|
|
|
|
198
|
|
View Code Duplication |
@pytest.mark.skipif(sys.platform == 'win32', reason="unix only") |
|
|
|
|
199
|
|
|
def it_shows_failing_programs(cli, tmp_path): |
200
|
|
|
verchew_ini = tmp_path / 'verchew.ini' |
201
|
|
|
verchew_ini.write_text(""" |
202
|
|
|
[Working Program] |
203
|
|
|
|
204
|
|
|
cli = working-program |
205
|
|
|
version = 1.2 |
206
|
|
|
|
207
|
|
|
[Newer Working Program] |
208
|
|
|
|
209
|
|
|
cli = working-program |
210
|
|
|
version = 1.3 |
211
|
|
|
""") |
212
|
|
|
|
213
|
|
|
cmd = cli('--root', str(tmp_path), '--quiet') |
214
|
|
|
|
215
|
|
|
expect(cmd.stderr) == "" |
216
|
|
|
expect(cmd.stdout) == "Unmatched Newer Working Program version: 1.3\n" |
217
|
|
|
expect(cmd.returncode) == 0 |
218
|
|
|
|