Completed
Push — pyup-update-pytest-3.2.3-to-3.... ( 5144af )
by Michael
07:18 queued 07:12
created

answer_prompts()   A

Complexity

Conditions 1

Size

Total Lines 8

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 8
rs 9.4285
1
from datetime import date
2
import shlex
3
import textwrap
4
from pathlib import Path
5
6
from plumbum.cmd import git
0 ignored issues
show
Configuration introduced by
The import plumbum.cmd 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...
7
import pytest
8
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...
9
10
import changes
11
from changes.commands import stage, publish
12
from .conftest import github_merge_commit, ISSUE_URL, LABEL_URL, PULL_REQUEST_JSON, BUG_LABEL_JSON, RELEASES_URL
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/79).

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

Loading history...
13
14
15
@pytest.fixture
16
def answer_prompts(mocker):
17
    prompt = mocker.patch(
18
        'changes.commands.publish.click.confirm',
19
        autospec=True,
20
    )
21
    prompt.side_effect = [
22
        'y'
23
    ]
24
25
26
def test_publish_no_staged_release(
27
    capsys,
28
    configured
29
):
30
    changes.initialise()
31
    publish.publish()
32
33
    expected_output = textwrap.dedent(
34
        """\
35
        No staged release to publish...
36
        """
37
    )
38
    out, _ = capsys.readouterr()
39
    assert expected_output == out
40
41
42
@responses.activate
43
def test_publish(
44
    capsys,
45
    configured,
46
    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 16).

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...
47
):
48
49
    github_merge_commit(111)
50
    responses.add(
51
        responses.GET,
52
        ISSUE_URL,
53
        json=PULL_REQUEST_JSON,
54
        status=200,
55
        content_type='application/json'
56
    )
57
    responses.add(
58
        responses.GET,
59
        LABEL_URL,
60
        json=BUG_LABEL_JSON,
61
        status=200,
62
        content_type='application/json'
63
    )
64
    responses.add(
65
        responses.POST,
66
        RELEASES_URL,
67
        json={'upload_url': 'foo'},
68
        status=200,
69
        content_type='application/json'
70
    )
71
72
    changes.initialise()
73
    stage.stage(
74
        draft=False,
75
        release_name='Icarus',
76
        release_description='The first flight'
77
    )
78
79
    release_notes_path = Path(
80
        'docs/releases/0.0.2-{}-Icarus.md'.format(
81
            date.today().isoformat()
82
        )
83
    )
84
    assert release_notes_path.exists()
85
86
    publish.publish()
87
88
    pre = textwrap.dedent(
89
        """\
90
        Staging [fix] release for version 0.0.2...
91
        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...
92
        Generating Release...
93
        Writing release notes to {release_notes_path}...
94
        Publishing release 0.0.2...
95
        Running: git add version.txt .bumpversion.cfg {release_notes_path}...
96
        Running: git commit --message="# 0.0.2 ({release_date}) Icarus
97
        """.format(
98
            release_notes_path=release_notes_path,
99
            release_date=date.today().isoformat(),
100
        )
101
    ).splitlines()
102
103
    expected_release_notes_content = [
104
        'The first flight',
105
        '## Bug',
106
        '    ',
107
        '* #111 The title of the pull request',
108
        '    ',
109
    ]
110
111
    post = textwrap.dedent(
112
        """\
113
        "...
114
        Running: git tag 0.0.2...
115
        Running: git push --tags...
116
        Creating GitHub Release...
117
        Published release 0.0.2...
118
        """
119
    ).splitlines()
120
121
    out, _ = capsys.readouterr()
122
123
    assert pre + expected_release_notes_content + post == out.splitlines()
124
125
    last_commit = git(shlex.split('show --name-only'))
126
    expected_files = [
127
        'version.txt',
128
        '.bumpversion.cfg',
129
        release_notes_path,
130
    ]
131
    assert [
132
        expected_file
133
        for expected_file in expected_files
134
        if str(expected_file) in last_commit
135
    ]
136
137
    assert '0.0.2' in git(shlex.split('tag --list'))
138
139
    assert release_notes_path.exists()
140
    expected_release_notes = [
141
        '# 0.0.2 ({}) Icarus'.format(date.today().isoformat()),
142
        'The first flight',
143
        '## Bug',
144
        '    ',
145
        '* #111 The title of the pull request',
146
        '    ',
147
    ]
148
    assert expected_release_notes == release_notes_path.read_text().splitlines()
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (80/79).

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

Loading history...
Bug introduced by
The Instance of Path does not seem to have a member named read_text.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
149