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 os |
8
|
|
|
import sys |
9
|
|
|
import logging |
10
|
|
|
|
11
|
|
|
import pytest |
|
|
|
|
12
|
|
|
import scripttest |
|
|
|
|
13
|
|
|
from expecter import expect |
|
|
|
|
14
|
|
|
|
15
|
|
|
|
16
|
|
|
ROOT = os.path.abspath(os.path.dirname(__file__)) |
17
|
|
|
FILES = os.path.join(ROOT, "files") |
18
|
|
|
BIN = os.path.join(FILES, "bin") |
19
|
|
|
|
20
|
|
|
SAMPLE_OUTPUT = """ |
21
|
|
|
Checking for Valid Program... |
22
|
|
|
|
23
|
|
|
$ working --version |
24
|
|
|
1.2.3 |
25
|
|
|
✔ MATCHED: 1.2. |
26
|
|
|
|
27
|
|
|
Checking for Invalid Program... |
28
|
|
|
|
29
|
|
|
$ working --version |
30
|
|
|
1.2.3 |
31
|
|
|
✖ EXPECTED: 4. |
32
|
|
|
|
33
|
|
|
Checking for Broken Program... |
34
|
|
|
|
35
|
|
|
$ broken --version |
36
|
|
|
An error occurred. |
37
|
|
|
✖ EXPECTED: 1.2.3 |
38
|
|
|
|
39
|
|
|
Checking for Missing Program... |
40
|
|
|
|
41
|
|
|
$ missing --version |
42
|
|
|
sh: command not found: missing |
43
|
|
|
✖ EXPECTED: 1.2.3 |
44
|
|
|
|
45
|
|
|
Results: ✔ ✖ ✖ ✖ |
46
|
|
|
|
47
|
|
|
""" |
48
|
|
|
|
49
|
|
|
SAMPLE_OUTPUT_PYTHON_2 = """ |
50
|
|
|
Checking for Valid Program... |
51
|
|
|
|
52
|
|
|
$ working --version |
53
|
|
|
1.2.3 |
54
|
|
|
~ MATCHED: 1.2. |
55
|
|
|
|
56
|
|
|
Checking for Invalid Program... |
57
|
|
|
|
58
|
|
|
$ working --version |
59
|
|
|
1.2.3 |
60
|
|
|
x EXPECTED: 4. |
61
|
|
|
|
62
|
|
|
Checking for Broken Program... |
63
|
|
|
|
64
|
|
|
$ broken --version |
65
|
|
|
An error occurred. |
66
|
|
|
x EXPECTED: 1.2.3 |
67
|
|
|
|
68
|
|
|
Checking for Missing Program... |
69
|
|
|
|
70
|
|
|
$ missing --version |
71
|
|
|
sh: command not found: missing |
72
|
|
|
x EXPECTED: 1.2.3 |
73
|
|
|
|
74
|
|
|
Results: ~ x x x |
75
|
|
|
|
76
|
|
|
""" |
77
|
|
|
|
78
|
|
|
SAMPLE_OUTPUT_WINDOWS = """ |
79
|
|
|
Checking for Valid Program... |
80
|
|
|
|
81
|
|
|
$ working --version |
82
|
|
|
sh: command not found: working |
83
|
|
|
x EXPECTED: 1.2. |
84
|
|
|
|
85
|
|
|
Checking for Invalid Program... |
86
|
|
|
|
87
|
|
|
$ working --version |
88
|
|
|
sh: command not found: working |
89
|
|
|
x EXPECTED: 4. |
90
|
|
|
|
91
|
|
|
Checking for Broken Program... |
92
|
|
|
|
93
|
|
|
$ broken --version |
94
|
|
|
sh: command not found: broken |
95
|
|
|
x EXPECTED: 1.2.3 |
96
|
|
|
|
97
|
|
|
Checking for Missing Program... |
98
|
|
|
|
99
|
|
|
$ missing --version |
100
|
|
|
sh: command not found: missing |
101
|
|
|
x EXPECTED: 1.2.3 |
102
|
|
|
|
103
|
|
|
Results: x x x x |
104
|
|
|
|
105
|
|
|
""" |
106
|
|
|
|
107
|
|
|
log = logging.getLogger(__name__) |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
@pytest.fixture |
111
|
|
|
def env(tmpdir): |
112
|
|
|
path = str(tmpdir.join("test")) |
113
|
|
|
env = scripttest.TestFileEnvironment(path) |
114
|
|
|
return env |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
@pytest.fixture |
118
|
|
|
def env_with_bin(env): |
119
|
|
|
env.environ['PATH'] = BIN |
120
|
|
|
log.debug("ENV: %s", env.environ) |
121
|
|
|
return env |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
def cli(env, *args): |
125
|
|
|
prog = os.path.join(os.path.dirname(sys.executable), "verchew") |
126
|
|
|
cmd = env.run(prog, *args, expect_error=True) |
127
|
|
|
return cmd |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
def describe_cli(): |
131
|
|
|
|
132
|
|
|
def it_displays_help_information(env): |
133
|
|
|
cmd = cli(env, '--help') |
134
|
|
|
|
135
|
|
|
expect(cmd.returncode) == 0 |
136
|
|
|
expect(cmd.stdout).contains("usage: verchew") |
137
|
|
|
|
138
|
|
|
def it_displays_version_information(env): |
139
|
|
|
cmd = cli(env, '--version') |
140
|
|
|
|
141
|
|
|
expect(cmd.returncode) == 0 |
142
|
|
|
expect(cmd.stdout or cmd.stderr).contains("verchew v0.") |
143
|
|
|
|
144
|
|
|
@pytest.mark.skipif(sys.platform == 'win32', reason="unix-only") |
145
|
|
|
@pytest.mark.skipif(sys.version_info[0] == 2, reason="python3-only") |
146
|
|
|
def it_displays_results_on_unix_python_3(env_with_bin): |
147
|
|
|
cmd = cli(env_with_bin, '--root', FILES) |
148
|
|
|
|
149
|
|
|
expect(cmd.returncode) == 1 |
150
|
|
|
expect(cmd.stderr) == "" |
151
|
|
|
expect(cmd.stdout) == SAMPLE_OUTPUT |
152
|
|
|
|
153
|
|
|
@pytest.mark.skipif(sys.platform == 'win32', reason="unix-only") |
154
|
|
|
@pytest.mark.skipif(sys.version_info[0] == 3, reason="python2-only") |
155
|
|
|
def it_displays_results_on_unix_python_2(env_with_bin): |
156
|
|
|
cmd = cli(env_with_bin, '--root', FILES) |
157
|
|
|
|
158
|
|
|
expect(cmd.returncode) == 1 |
159
|
|
|
expect(cmd.stderr) == "" |
160
|
|
|
expect(cmd.stdout) == SAMPLE_OUTPUT_PYTHON_2 |
161
|
|
|
|
162
|
|
|
@pytest.mark.skipif(sys.platform != 'win32', reason="windows-only") |
163
|
|
|
def it_displays_results_on_windows(env_with_bin): |
164
|
|
|
cmd = cli(env_with_bin, '--root', FILES) |
165
|
|
|
|
166
|
|
|
expect(cmd.returncode) == 1 |
167
|
|
|
expect(cmd.stderr) == "" |
168
|
|
|
expect(cmd.stdout) == SAMPLE_OUTPUT_WINDOWS |
169
|
|
|
|
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.