Completed
Push — publish ( 7d876b )
by Michael
06:43
created

test_publish()   B

Complexity

Conditions 2

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 44
rs 8.8571
1
"""
2
For testing:
3
mkdir /tmp/fake-push-repo
4
git init /tmp/fake-push-repo
5
git remote set-url --push origin /tmp/fake-push-repo
6
"""
7
import textwrap
8
from pathlib import Path
9
10
import pytest
11
import responses
0 ignored issues
show
Configuration introduced by
The import responses 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...
12
13
from changes.commands import init, stage, publish
14
from .conftest import github_merge_commit, ISSUE_URL, LABEL_URL, PULL_REQUEST_JSON, BUG_LABEL_JSON
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (98/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
15
16
17
@pytest.fixture
18
def answer_prompts(mocker):
19
    prompt = mocker.patch(
20
        'changes.commands.publish.click.confirm',
21
        autospec=True,
22
    )
23
    prompt.side_effect = [
24
        'y'
25
    ]
26
27
28
def test_publish_no_staged_release(
29
    capsys,
30
    configured
31
):
32
    init.init()
33
    publish.publish()
34
35
    expected_output = textwrap.dedent(
36
        """\
37
        No staged release to publish...
38
        """
39
    )
40
    out, _ = capsys.readouterr()
41
    assert expected_output == out
42
43
44
@responses.activate
45
def test_publish(
46
    capsys,
47
    configured,
48
    answer_prompts,
0 ignored issues
show
Comprehensibility Bug introduced by
answer_prompts is re-defining a name which is already available in the outer-scope (previously defined on line 18).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
49
):
50
51
    github_merge_commit(111)
52
    responses.add(
53
        responses.GET,
54
        ISSUE_URL.format('111'),
55
        json=PULL_REQUEST_JSON,
56
        status=200,
57
        content_type='application/json'
58
    )
59
    responses.add(
60
        responses.GET,
61
        LABEL_URL,
62
        json=BUG_LABEL_JSON,
63
        status=200,
64
        content_type='application/json'
65
    )
66
67
    init.init()
68
    stage.stage(
69
        draft=False,
70
        release_name='Icarus',
71
        release_description='The first flight'
72
    )
73
    publish.publish()
74
75
    expected_output = textwrap.dedent(
76
        """\
77
        Staging [fix] release for version 0.0.2...
78
        Running: bumpversion --verbose --allow-dirty --no-commit --no-tag patch...
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (82/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
79
        Generating Release...
80
        Writing release notes to {}...
81
        Publish release 0.0.2...
82
        """.format(
83
            Path('docs').joinpath('releases').joinpath('0.0.2.md')
84
        )
85
    )
86
    out, _ = capsys.readouterr()
87
    assert expected_output == out
88