1
|
|
|
# pylint: disable=redefined-outer-name,unused-variable,expression-not-assigned |
2
|
|
|
|
3
|
|
|
from __future__ import unicode_literals |
4
|
|
|
|
5
|
|
|
import os |
6
|
|
|
import sys |
7
|
|
|
|
8
|
|
|
import pytest |
|
|
|
|
9
|
|
|
import scripttest |
|
|
|
|
10
|
|
|
from expecter import expect |
|
|
|
|
11
|
|
|
import six |
12
|
|
|
|
13
|
|
|
SLUG = "jacebrowning/coverage-space-cli-demo" |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
@pytest.fixture |
17
|
|
|
def env(tmpdir): |
18
|
|
|
path = str(tmpdir.join('test')) |
19
|
|
|
env = scripttest.TestFileEnvironment(path) |
20
|
|
|
env.environ.pop('CI', None) |
21
|
|
|
env.environ.pop('CONTINUOUS_INTEGRATION', None) |
22
|
|
|
env.environ.pop('TRAVIS', None) |
23
|
|
|
env.environ.pop('APPVEYOR', None) |
24
|
|
|
return env |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
def cli(env, *args): |
28
|
|
|
prog = os.path.join(os.path.dirname(sys.executable), 'coverage.space') |
29
|
|
|
cmd = env.run(prog, *args, expect_error=True) |
30
|
|
|
six.print_(cmd) |
31
|
|
|
return cmd |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
def describe_cli(): |
35
|
|
|
|
36
|
|
|
def it_fails_when_missing_arguments(env): |
37
|
|
|
cmd = cli(env) |
38
|
|
|
|
39
|
|
|
expect(cmd.returncode) == 1 |
40
|
|
|
expect(cmd.stderr).contains("Usage:") |
41
|
|
|
|
42
|
|
|
def describe_update(): |
43
|
|
|
|
44
|
|
|
@pytest.fixture |
45
|
|
|
def slug(): |
46
|
|
|
return SLUG + "/update" |
47
|
|
|
|
48
|
|
|
def it_can_update_metrics(env, slug): |
49
|
|
|
cmd = cli(env, slug, 'unit', '100') |
50
|
|
|
|
51
|
|
|
expect(cmd.returncode) == 0 |
52
|
|
|
expect(cmd.stderr) == "" |
53
|
|
|
expect(cmd.stdout) == "" |
54
|
|
|
|
55
|
|
|
def it_indicates_when_metrics_decrease(env, slug): |
56
|
|
|
cmd = cli(env, slug, 'unit', '0') |
57
|
|
|
|
58
|
|
|
expect(cmd.returncode) == 0 |
59
|
|
|
expect(cmd.stderr) == "" |
60
|
|
|
expect(cmd.stdout).contains("coverage decreased") |
61
|
|
|
|
62
|
|
|
def it_fails_when_metrics_decrease_if_requested(env, slug): |
63
|
|
|
cmd = cli(env, slug, 'unit', '0', '--exit-code') |
64
|
|
|
|
65
|
|
|
expect(cmd.returncode) == 1 |
66
|
|
|
expect(cmd.stderr) == "" |
67
|
|
|
expect(cmd.stdout).contains("coverage decreased") |
68
|
|
|
|
69
|
|
|
def it_always_display_metrics_when_verbose(env, slug): |
70
|
|
|
cmd = cli(env, slug, 'unit', '100', '--verbose') |
71
|
|
|
|
72
|
|
|
expect(cmd.returncode) == 0 |
73
|
|
|
expect(cmd.stderr) != "" # expect lots of logging |
74
|
|
|
expect(cmd.stdout).contains("coverage increased") |
75
|
|
|
|
76
|
|
|
def it_skips_when_running_on_ci(env, slug): |
77
|
|
|
env.environ['CI'] = 'true' |
78
|
|
|
|
79
|
|
|
cmd = cli(env, slug, 'unit', '0', '--exit-code') |
80
|
|
|
|
81
|
|
|
expect(cmd.returncode) == 0 |
82
|
|
|
expect(cmd.stderr).contains("Coverage check skipped") |
83
|
|
|
expect(cmd.stdout) == "" |
84
|
|
|
|
85
|
|
|
def describe_reset(): |
86
|
|
|
|
87
|
|
|
@pytest.fixture |
88
|
|
|
def slug(): |
89
|
|
|
return SLUG + "/reset" |
90
|
|
|
|
91
|
|
|
def it_can_reset_metrics(env, slug): |
92
|
|
|
cmd = cli(env, slug, '--reset') |
93
|
|
|
|
94
|
|
|
expect(cmd.returncode) == 0 |
95
|
|
|
expect(cmd.stderr) == "" |
96
|
|
|
expect(cmd.stdout).contains("coverage reset") |
97
|
|
|
|
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.