Completed
Push — publish ( ab6fe5...6057b5 )
by Michael
06:08
created

configured()   B

Complexity

Conditions 1

Size

Total Lines 35

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 35
rs 8.8571
1
import os
2
import shlex
3
import textwrap
4
from pathlib import Path
5
6
import pytest
7
import sys
8
from click.testing import CliRunner
0 ignored issues
show
Configuration introduced by
The import click.testing 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
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...
10
11
import changes
12
13
pytest_plugins = 'pytester'
0 ignored issues
show
Coding Style Naming introduced by
The name pytest_plugins does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

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...
14
15
# TODO: textwrap.dedent.heredoc
16
INIT_CONTENT = [
17
    '"""A test app"""',
18
    '',
19
    "__version__ = '0.0.1'",
20
    "__url__ = 'https://github.com/someuser/test_app'",
21
    "__author__ = 'Some User'",
22
    "__email__ = '[email protected]'"
23
]
24
SETUP_PY = [
25
    'from setuptools import setup',
26
    "setup(name='test_app'",
27
]
28
README_MARKDOWN = [
29
    '# Test App',
30
    '',
31
    'This is the test application.'
32
]
33
34
PYTHON_MODULE = 'test_app'
35
36
FILE_CONTENT = {
37
    '%s/__init__.py' % PYTHON_MODULE: INIT_CONTENT,
38
    'setup.py': SETUP_PY,
39
    'requirements.txt': ['pytest'],
40
    'README.md': README_MARKDOWN,
41
    'CHANGELOG.md': [''],
42
}
43
ISSUE_URL = 'https://api.github.com/repos/michaeljoseph/test_app/issues/{}'
44
LABEL_URL = 'https://api.github.com/repos/michaeljoseph/test_app/labels'
45
AUTH_TOKEN_ENVVAR = 'GITHUB_AUTH_TOKEN'
46
47
48
@pytest.fixture
49
def python_module():
50
    with CliRunner().isolated_filesystem():
51
        os.mkdir(PYTHON_MODULE)
52
53
        for file_path, content in FILE_CONTENT.items():
54
            open(file_path, 'w').write(
55
                '\n'.join(content)
56
            )
57
58
        git_init(FILE_CONTENT.keys())
59
60
        yield
61
62
63
@pytest.fixture
64
def git_repo():
65
    with CliRunner().isolated_filesystem():
66
        readme_path = 'README.md'
67
        open(readme_path, 'w').write(
68
            '\n'.join(README_MARKDOWN)
69
        )
70
        version_path = 'version.txt'
71
        open(version_path, 'w').write('0.0.1')
72
73
        git_init([readme_path, version_path])
74
75
        yield
76
77
78
def git_init(files_to_add):
79
    git('init')
80
    git(shlex.split('config --local user.email "[email protected]"'))
81
    git('remote', 'add', 'origin', 'https://github.com/michaeljoseph/test_app.git')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (83/79).

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

Loading history...
82
    for file_to_add in files_to_add:
83
        git('add', file_to_add)
84
    git('commit', '-m', 'Initial commit')
85
    git(shlex.split('tag 0.0.1'))
86
87
88
def github_merge_commit(pull_request_number):
89
    from haikunator import Haikunator
0 ignored issues
show
Configuration introduced by
The import haikunator 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...
90
91
    branch_name = Haikunator().haikunate()
92
    commands = [
93
        'checkout -b {}'.format(branch_name),
94
        'commit --allow-empty -m "Test branch commit message"',
95
        'checkout master',
96
        'merge --no-ff {}'.format(branch_name),
97
98
        'commit --allow-empty --amend -m '
99
        '"Merge pull request #{} from test_app/{}"'.format(
100
            pull_request_number,
101
            branch_name,
102
        )
103
    ]
104
    for command in commands:
105
        git(shlex.split(command))
106
107
108
@pytest.fixture
109
def with_releases_directory_and_bumpversion_file_prompt(mocker):
0 ignored issues
show
Coding Style Naming introduced by
The name with_releases_directory_...bumpversion_file_prompt 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...
110
    prompt = mocker.patch(
111
        'changes.config.click.prompt',
112
        autospec=True
113
    )
114
    prompt.side_effect = [
115
        # release_directory
116
        'docs/releases',
117
        # bumpversion files
118
        'version.txt',
119
        # quit prompt
120
        '.',
121
        # label descriptions
122
        # 'Features',
123
        # 'Bug Fixes'
124
    ]
125
126
    prompt = mocker.patch(
127
        'changes.config.read_user_choices',
128
        autospec=True
129
    )
130
    prompt.return_value = ['bug']
131
132
133
@pytest.fixture
134
def with_auth_token_prompt(mocker):
135
    _ = mocker.patch('changes.config.click.launch')
136
137
    prompt = mocker.patch('changes.config.click.prompt')
138
    prompt.return_value = 'foo'
139
140
    saved_token = None
141
    if os.environ.get(AUTH_TOKEN_ENVVAR):
142
        saved_token = os.environ[AUTH_TOKEN_ENVVAR]
143
        del os.environ[AUTH_TOKEN_ENVVAR]
144
145
    yield
146
147
    if saved_token:
148
        os.environ[AUTH_TOKEN_ENVVAR] = saved_token
149
150
151
@pytest.fixture
152
def with_auth_token_envvar():
153
    saved_token = None
154
    if os.environ.get(AUTH_TOKEN_ENVVAR):
155
        saved_token = os.environ[AUTH_TOKEN_ENVVAR]
156
157
    os.environ[AUTH_TOKEN_ENVVAR] = 'foo'
158
159
    yield
160
161
    if saved_token:
162
        os.environ[AUTH_TOKEN_ENVVAR] = saved_token
163
    else:
164
        del os.environ[AUTH_TOKEN_ENVVAR]
165
166
167
@pytest.fixture
168
def changes_config_in_tmpdir(monkeypatch, tmpdir):
169
    IS_WINDOWS = 'win32' in str(sys.platform).lower()
0 ignored issues
show
Coding Style Naming introduced by
The name IS_WINDOWS does not conform to the variable 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...
170
171
    changes_config_file = Path(str(tmpdir.join('.changes')))
172
    monkeypatch.setattr(
173
        changes.config,
0 ignored issues
show
Bug introduced by
The Module changes does not seem to have a member named config.

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...
174
        'expandvars' if IS_WINDOWS else 'expanduser',
175
        lambda x: str(changes_config_file)
176
    )
177
    assert not changes_config_file.exists()
178
    return changes_config_file
179
180
181
@pytest.fixture
182
def configured(git_repo, tmpdir):
0 ignored issues
show
Comprehensibility Bug introduced by
git_repo is re-defining a name which is already available in the outer-scope (previously defined on line 64).

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...
183
    changes_config_path = Path(str(tmpdir.join('.changes')))
184
    changes_config_path.write_text(textwrap.dedent(
0 ignored issues
show
Bug introduced by
The Instance of Path does not seem to have a member named write_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...
185
        """\
186
        [changes]
187
        auth_token = "foo"
188
        """
189
    ))
190
191
    Path('.changes.toml').write_text(textwrap.dedent(
0 ignored issues
show
Bug introduced by
The Instance of Path does not seem to have a member named write_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...
192
        """\
193
        [changes]
194
        releases_directory = "docs/releases"
195
196
        [changes.labels.bug]
197
        default = true
198
        id = 208045946
199
        url = "https://api.github.com/repos/michaeljoseph/test_app/labels/bug"
200
        name = "bug"
201
        description = "Bug"
202
        color = "f29513"
203
        """
204
    ))
205
206
    Path('.bumpversion.cfg').write_text(textwrap.dedent(
0 ignored issues
show
Bug introduced by
The Instance of Path does not seem to have a member named write_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...
207
        """\
208
        [bumpversion]
209
        current_version = 0.0.1
210
211
        [bumpversion:file:version.txt]
212
        """
213
    ))
214
215
    return str(changes_config_path)
216