Completed
Push — stage ( 901070...369057 )
by Michael
09:53
created

init_prompts()   B

Complexity

Conditions 3

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
c 0
b 0
f 0
dl 0
loc 27
rs 8.8571
1
import os
2
import textwrap
3
4
import pytest
5
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...
6
7
from changes.commands import init
8
from .conftest import AUTH_TOKEN_ENVVAR
9
10
@pytest.fixture
11
def init_prompts(mocker):
12
    _ = mocker.patch(
13
        'changes.config.click.launch',
14
        autospec=True,
15
    )
16
17
    prompt = mocker.patch(
18
        'changes.config.click.prompt',
19
        autospec=True,
20
    )
21
    prompt.side_effect = [
22
        'foo',
23
        'docs/releases',
24
        'test_app/__init__.py',
25
        '.'
26
    ]
27
28
    saved_token = None
29
    if os.environ.get(AUTH_TOKEN_ENVVAR):
30
        saved_token = os.environ[AUTH_TOKEN_ENVVAR]
31
        del os.environ[AUTH_TOKEN_ENVVAR]
32
33
    yield
34
35
    if saved_token:
36
        os.environ[AUTH_TOKEN_ENVVAR] = saved_token
37
38
39
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...
40
    capsys,
41
    git_repo,
42
    patch_user_home_to_tmpdir_path,
43
    init_prompts,
0 ignored issues
show
Comprehensibility Bug introduced by
init_prompts is re-defining a name which is already available in the outer-scope (previously defined on line 11).

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...
44
):
45
46
    init.init()
47
48
    assert patch_user_home_to_tmpdir_path.exists()
49
    expected_config = textwrap.dedent(
50
        """\
51
        [changes]
52
        auth_token = "foo"
53
        """
54
    )
55
    assert expected_config == patch_user_home_to_tmpdir_path.read_text()
56
57
    expected_output = textwrap.dedent(
58
        """\
59
        No auth token found, asking for it...
60
        You need a Github Auth Token for changes to create a release.
61
        Indexing repository...
62
        """
63
    )
64
    out, _ = capsys.readouterr()
65
    assert expected_output == out
66
67
68
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...
69
    capsys,
70
    git_repo,
71
    with_auth_token_envvar,
72
    patch_user_home_to_tmpdir_path,
73
    with_releases_directory_and_bumpversion_file_prompt,
74
):
75
76
    init.init()
77
78
    assert patch_user_home_to_tmpdir_path.exists()
79
    expected_config = textwrap.dedent(
80
        """\
81
        [changes]
82
        auth_token = "foo"
83
        """
84
    )
85
    assert expected_config == patch_user_home_to_tmpdir_path.read_text()
86
87
    expected_output = textwrap.dedent(
88
        """\
89
        Found Github Auth Token in the environment...
90
        Indexing repository...
91
        """
92
    )
93
    out, _ = capsys.readouterr()
94
    assert expected_output == out
95