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