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
|
|
|
|
9
|
|
|
import pytest |
|
|
|
|
10
|
|
|
import scripttest |
|
|
|
|
11
|
|
|
from expecter import expect |
|
|
|
|
12
|
|
|
|
13
|
|
|
|
14
|
|
|
ROOT = os.path.abspath(os.path.dirname(__file__)) |
15
|
|
|
FILES = os.path.join(ROOT, "files") |
16
|
|
|
BIN = os.path.join(FILES, "bin") |
17
|
|
|
|
18
|
|
|
SAMPLE_OUTPUT = """ |
19
|
|
|
Checking for Valid Program... |
20
|
|
|
|
21
|
|
|
$ working --version |
22
|
|
|
1.2.3 |
23
|
|
|
✔ MATCHED: 1.2. |
24
|
|
|
|
25
|
|
|
Checking for Invalid Program... |
26
|
|
|
|
27
|
|
|
$ working --version |
28
|
|
|
1.2.3 |
29
|
|
|
✖ EXPECTED: 4. |
30
|
|
|
|
31
|
|
|
Checking for Broken Program... |
32
|
|
|
|
33
|
|
|
$ broken --version |
34
|
|
|
An error occurred. |
35
|
|
|
✖ EXPECTED: 1.2.3 |
36
|
|
|
|
37
|
|
|
Checking for Missing Program... |
38
|
|
|
|
39
|
|
|
$ missing --version |
40
|
|
|
sh: command not found: missing |
41
|
|
|
✖ EXPECTED: 1.2.3 |
42
|
|
|
|
43
|
|
|
Results: ✔ ✖ ✖ ✖ |
44
|
|
|
|
45
|
|
|
""" |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
@pytest.fixture |
49
|
|
|
def env(tmpdir): |
50
|
|
|
path = str(tmpdir.join("test")) |
51
|
|
|
env = scripttest.TestFileEnvironment(path) |
52
|
|
|
return env |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
def cli(env, *args): |
56
|
|
|
prog = os.path.join(os.path.dirname(sys.executable), "verchew") |
57
|
|
|
cmd = env.run(prog, *args, expect_error=True) |
58
|
|
|
return cmd |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
def describe_cli(): |
62
|
|
|
|
63
|
|
|
def it_displays_help_information(env): |
64
|
|
|
cmd = cli(env, '--help') |
65
|
|
|
|
66
|
|
|
expect(cmd.returncode) == 0 |
67
|
|
|
expect(cmd.stdout).contains("usage: verchew") |
68
|
|
|
|
69
|
|
|
def it_displays_version_information(env): |
70
|
|
|
cmd = cli(env, '--version') |
71
|
|
|
|
72
|
|
|
expect(cmd.returncode) == 0 |
73
|
|
|
expect(cmd.stdout or cmd.stderr).contains("verchew v0.") |
74
|
|
|
|
75
|
|
|
def it_displays_results_when_run(env): |
76
|
|
|
env.environ['PATH'] = BIN |
77
|
|
|
cmd = cli(env, '--root', FILES) |
78
|
|
|
|
79
|
|
|
expect(cmd.returncode) == 1 |
80
|
|
|
expect(cmd.stderr) == "" |
81
|
|
|
expect(cmd.stdout) == SAMPLE_OUTPUT |
82
|
|
|
|
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.