1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# pylint: disable=redefined-outer-name,unused-variable,expression-not-assigned |
3
|
|
|
|
4
|
|
|
from __future__ import unicode_literals |
5
|
|
|
|
6
|
|
|
import os |
7
|
|
|
import sys |
8
|
|
|
import logging |
9
|
|
|
|
10
|
|
|
import pytest |
|
|
|
|
11
|
|
|
import scripttest |
|
|
|
|
12
|
|
|
from expecter import expect |
|
|
|
|
13
|
|
|
|
14
|
|
|
|
15
|
|
|
ROOT = os.path.abspath(os.path.dirname(__file__)) |
16
|
|
|
FILES = os.path.join(ROOT, "files") |
17
|
|
|
BIN = os.path.join(FILES, "bin") |
18
|
|
|
|
19
|
|
|
SAMPLE_OUTPUT_UNIX = """ |
20
|
|
|
Checking for Valid Program... |
21
|
|
|
|
22
|
|
|
$ working --version |
23
|
|
|
1.2.3 |
24
|
|
|
~ MATCHED: 1.2. |
25
|
|
|
|
26
|
|
|
Checking for Invalid Program... |
27
|
|
|
|
28
|
|
|
$ working --version |
29
|
|
|
1.2.3 |
30
|
|
|
x EXPECTED: 4. |
31
|
|
|
|
32
|
|
|
Checking for Broken Program... |
33
|
|
|
|
34
|
|
|
$ broken --version |
35
|
|
|
An error occurred. |
36
|
|
|
x EXPECTED: 1.2.3 |
37
|
|
|
|
38
|
|
|
Checking for Missing Program... |
39
|
|
|
|
40
|
|
|
$ missing --version |
41
|
|
|
sh: command not found: missing |
42
|
|
|
x EXPECTED: 1.2.3 |
43
|
|
|
|
44
|
|
|
Results: ~ x x x |
45
|
|
|
|
46
|
|
|
""" |
47
|
|
|
|
48
|
|
|
SAMPLE_OUTPUT_WINDOWS = """ |
49
|
|
|
Checking for Valid Program... |
50
|
|
|
|
51
|
|
|
$ working --version |
52
|
|
|
sh: command not found: working |
53
|
|
|
x EXPECTED: 1.2. |
54
|
|
|
|
55
|
|
|
Checking for Invalid Program... |
56
|
|
|
|
57
|
|
|
$ working --version |
58
|
|
|
sh: command not found: working |
59
|
|
|
x EXPECTED: 4. |
60
|
|
|
|
61
|
|
|
Checking for Broken Program... |
62
|
|
|
|
63
|
|
|
$ broken --version |
64
|
|
|
sh: command not found: broken |
65
|
|
|
x EXPECTED: 1.2.3 |
66
|
|
|
|
67
|
|
|
Checking for Missing Program... |
68
|
|
|
|
69
|
|
|
$ missing --version |
70
|
|
|
sh: command not found: missing |
71
|
|
|
x EXPECTED: 1.2.3 |
72
|
|
|
|
73
|
|
|
Results: x x x x |
74
|
|
|
|
75
|
|
|
""" |
76
|
|
|
|
77
|
|
|
log = logging.getLogger(__name__) |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
@pytest.fixture |
81
|
|
|
def env(tmpdir): |
82
|
|
|
path = str(tmpdir.join("test")) |
83
|
|
|
env = scripttest.TestFileEnvironment(path) |
84
|
|
|
return env |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
@pytest.fixture |
88
|
|
|
def env_with_bin(env): |
89
|
|
|
env.environ['PATH'] = BIN |
90
|
|
|
log.debug("ENV: %s", env.environ) |
91
|
|
|
return env |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
def cli(env, *args): |
95
|
|
|
prog = os.path.join(os.path.dirname(sys.executable), "verchew") |
96
|
|
|
cmd = env.run(prog, *args, expect_error=True) |
97
|
|
|
return cmd |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
def describe_cli(): |
101
|
|
|
|
102
|
|
|
def it_displays_help_information(env): |
103
|
|
|
cmd = cli(env, '--help') |
104
|
|
|
|
105
|
|
|
expect(cmd.returncode) == 0 |
106
|
|
|
expect(cmd.stdout).contains("usage: verchew") |
107
|
|
|
|
108
|
|
|
def it_displays_version_information(env): |
109
|
|
|
cmd = cli(env, '--version') |
110
|
|
|
|
111
|
|
|
expect(cmd.returncode) == 0 |
112
|
|
|
expect(cmd.stdout or cmd.stderr).contains("verchew v0.") |
113
|
|
|
|
114
|
|
|
@pytest.mark.skipif(sys.platform == 'win32', reason="unix-only") |
115
|
|
|
def it_displays_results_when_run_on_unix(env_with_bin): |
116
|
|
|
cmd = cli(env_with_bin, '--root', FILES) |
117
|
|
|
|
118
|
|
|
expect(cmd.returncode) == 1 |
119
|
|
|
expect(cmd.stderr) == "" |
120
|
|
|
expect(cmd.stdout) == SAMPLE_OUTPUT_UNIX |
121
|
|
|
|
122
|
|
|
@pytest.mark.skipif(sys.platform != 'win32', reason="windows-only") |
123
|
|
|
def it_displays_results_when_run_on_windows(env_with_bin): |
124
|
|
|
cmd = cli(env_with_bin, '--root', FILES) |
125
|
|
|
|
126
|
|
|
expect(cmd.returncode) == 1 |
127
|
|
|
expect(cmd.stderr) == "" |
128
|
|
|
expect(cmd.stdout) == SAMPLE_OUTPUT_WINDOWS |
129
|
|
|
|
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.