Completed
Push — develop ( 0e26e2...395b20 )
by Jace
06:01
created

it_fails_on_slugs_missing_a_slash()   A

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
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
0 ignored issues
show
Configuration introduced by Jace Browning
The import pytest could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

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.

Loading history...
9
import scripttest
0 ignored issues
show
Configuration introduced by Jace Browning
The import scripttest could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

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.

Loading history...
10
from expecter import expect
0 ignored issues
show
Configuration introduced by Jace Browning
The import expecter could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

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.

Loading history...
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
            expect(cmd.stdout).contains(
62
                "To reset metrics, run: coverage.space " + slug + " --reset"
63
            )
64
65
        def it_fails_when_metrics_decrease_if_requested(env, slug):
66
            cmd = cli(env, slug, 'unit', '0', '--exit-code')
67
68
            expect(cmd.returncode) == 1
69
            expect(cmd.stderr) == ""
70
            expect(cmd.stdout).contains("coverage decreased")
71
72
        def it_always_display_metrics_when_verbose(env, slug):
73
            cmd = cli(env, slug, 'unit', '100', '--verbose')
74
75
            expect(cmd.returncode) == 0
76
            expect(cmd.stderr) != ""  # expect lots of logging
77
            expect(cmd.stdout).contains("coverage increased")
78
79
        def it_skips_when_running_on_ci(env, slug):
80
            env.environ['CI'] = 'true'
81
82
            cmd = cli(env, slug, 'unit', '0', '--exit-code', '--verbose')
83
84
            expect(cmd.returncode) == 0
85
            expect(cmd.stderr).contains("Coverage check skipped")
86
            expect(cmd.stdout) == ""
87
88
        def it_fails_on_slugs_missing_a_slash(env):
89
            cmd = cli(env, 'foobar', 'unit', '100')
90
91
            expect(cmd.returncode) == 1
92
            expect(cmd.stderr).contains(
93
                "<owner/repo> slug must contain a slash")
94
            expect(cmd.stdout) == ""
95
96
    def describe_reset():
97
98
        @pytest.fixture
99
        def slug():
100
            return SLUG + "/reset"
101
102
        def it_can_reset_metrics(env, slug):
103
            cmd = cli(env, slug, '--reset')
104
105
            expect(cmd.returncode) == 0
106
            expect(cmd.stderr) == ""
107
            expect(cmd.stdout).contains("coverage reset")
108