Completed
Push — pyup-update-toml-0.9.2-to-0.9.... ( 3e288d )
by Michael
21:07 queued 21:02
created

answer_prompts()   B

Complexity

Conditions 3

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
c 0
b 0
f 0
dl 0
loc 33
rs 8.8571
1
import os
2
import textwrap
3
from pathlib import Path
4
5
import pytest
6
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...
7
8
from changes.commands import init
9
from .conftest import AUTH_TOKEN_ENVVAR, LABEL_URL, BUG_LABEL_JSON
10
11
12
@pytest.fixture
13
def answer_prompts(mocker):
14
    _ = mocker.patch(
15
        'changes.config.click.launch',
16
        autospec=True,
17
    )
18
19
    prompt = mocker.patch(
20
        'changes.config.click.prompt',
21
        autospec=True,
22
    )
23
    prompt.side_effect = [
24
        'foo',
25
        'docs/releases',
26
        'version.txt',
27
        '.'
28
    ]
29
30
    prompt = mocker.patch(
31
        'changes.config.choose_labels',
32
        autospec=True
33
    )
34
    prompt.return_value = ['bug']
35
36
    saved_token = None
37
    if os.environ.get(AUTH_TOKEN_ENVVAR):
38
        saved_token = os.environ[AUTH_TOKEN_ENVVAR]
39
        del os.environ[AUTH_TOKEN_ENVVAR]
40
41
    yield
42
43
    if saved_token:
44
        os.environ[AUTH_TOKEN_ENVVAR] = saved_token
45
46
47
@responses.activate
48
def test_init_prompts_for_auth_token_and_writes_tool_config(
0 ignored issues
show
Coding Style Naming introduced by
The name test_init_prompts_for_au..._and_writes_tool_config does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
49
    capsys,
50
    git_repo,
51
    changes_config_in_tmpdir,
52
    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 13).

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...
53
):
54
    responses.add(
55
        responses.GET,
56
        LABEL_URL,
57
        json=BUG_LABEL_JSON,
58
        status=200,
59
        content_type='application/json'
60
    )
61
62
    init.init()
63
64
    assert changes_config_in_tmpdir.exists()
65
    expected_config = textwrap.dedent(
66
        """\
67
        [changes]
68
        auth_token = "foo"
69
        """
70
    )
71
    assert expected_config == changes_config_in_tmpdir.read_text()
72
73
    expected_output = textwrap.dedent(
74
        """\
75
        No auth token found, asking for it...
76
        You need a Github Auth Token for changes to create a release.
77
        Releases directory {} not found, creating it....
78
        """.format(
79
            Path('docs').joinpath('releases')
80
        )
81
    )
82
    out, _ = capsys.readouterr()
83
    assert expected_output == out
84
85
86
@responses.activate
87
def test_init_finds_auth_token_in_environment(
0 ignored issues
show
Coding Style Naming introduced by
The name test_init_finds_auth_token_in_environment does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style Naming introduced by
The name with_releases_directory_...bumpversion_file_prompt does not conform to the argument naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
88
    capsys,
89
    git_repo,
90
    with_auth_token_envvar,
91
    changes_config_in_tmpdir,
92
    with_releases_directory_and_bumpversion_file_prompt,
93
):
94
    responses.add(
95
        responses.GET,
96
        LABEL_URL,
97
        json=BUG_LABEL_JSON,
98
        status=200,
99
        content_type='application/json'
100
    )
101
102
    init.init()
103
104
    # envvar setting is not written to the config file
105
    assert not changes_config_in_tmpdir.exists()
106
107
    expected_output = textwrap.dedent(
108
        """\
109
        Found Github Auth Token in the environment...
110
        Releases directory {} not found, creating it....
111
        """.format(
112
            Path('docs').joinpath('releases')
113
        )
114
    )
115
    out, _ = capsys.readouterr()
116
    assert expected_output == out
117