Completed
Push — pyup-update-attrs-17.2.0-to-17... ( 07ef42 )
by Michael
09:58 queued 09:54
created

git_repo()   B

Complexity

Conditions 3

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
c 3
b 0
f 0
dl 0
loc 29
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
44
AUTH_TOKEN_ENVVAR = 'GITHUB_AUTH_TOKEN'
45
46
ISSUE_URL = 'https://api.github.com/repos/michaeljoseph/test_app/issues/{}'
47
PULL_REQUEST_JSON = {
48
    'number': 111,
49
    'title': 'The title of the pull request',
50
    'body': 'An optional, longer description.',
51
    'user': {
52
        'login': 'someone'
53
    },
54
    'labels': [
55
        {'id': 1, 'name': 'bug'}
56
    ],
57
}
58
59
LABEL_URL = 'https://api.github.com/repos/michaeljoseph/test_app/labels'
60
BUG_LABEL_JSON = [
61
    {
62
        'id': 52048163,
63
        'url': 'https://api.github.com/repos/michaeljoseph/test_app/labels/bug',
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...
64
        'name': 'bug',
65
        'color': 'fc2929',
66
        'default': True
67
    }
68
]
69
70
RELEASES_URL = 'https://api.github.com/repos/michaeljoseph/test_app/releases'
71
72
@pytest.fixture
73
def git_repo(tmpdir):
74
    with CliRunner().isolated_filesystem() as repo_dir:
75
        readme_path = 'README.md'
76
        open(readme_path, 'w').write(
77
            '\n'.join(README_MARKDOWN)
78
        )
79
        version_path = 'version.txt'
80
        open(version_path, 'w').write('0.0.1')
81
82
        files_to_add = [
83
           readme_path,
84
           version_path,
85
        ]
86
87
        git('init')
88
        git(shlex.split('config --local user.email "[email protected]"'))
89
        git(shlex.split('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 (91/79).

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

Loading history...
90
91
        tmp_push_repo = Path(str(tmpdir))
92
        git('init', '--bare', str(tmp_push_repo))
93
        git(shlex.split('remote set-url --push origin {}'.format(tmp_push_repo.as_uri())))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (90/79).

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

Loading history...
94
95
        for file_to_add in files_to_add:
96
            git('add', file_to_add)
97
        git('commit', '-m', 'Initial commit')
98
        git(shlex.split('tag 0.0.1'))
99
100
        yield repo_dir
101
102
103
@pytest.fixture
104
def python_module(git_repo):
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 73).

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...
105
    os.mkdir(PYTHON_MODULE)
106
107
    for file_path, content in FILE_CONTENT.items():
108
        open(file_path, 'w').write(
109
            '\n'.join(content)
110
        )
111
112
    git('add', [file for file in FILE_CONTENT.keys()])
113
114
    yield
115
116
117
def github_merge_commit(pull_request_number):
118
    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...
119
120
    branch_name = Haikunator().haikunate()
121
    commands = [
122
        'checkout -b {}'.format(branch_name),
123
        'commit --allow-empty -m "Test branch commit message"',
124
        'checkout master',
125
        'merge --no-ff {}'.format(branch_name),
126
127
        'commit --allow-empty --amend -m '
128
        '"Merge pull request #{} from test_app/{}"'.format(
129
            pull_request_number,
130
            branch_name,
131
        )
132
    ]
133
    for command in commands:
134
        git(shlex.split(command))
135
136
137
@pytest.fixture
138
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...
139
    prompt = mocker.patch(
140
        'changes.config.click.prompt',
141
        autospec=True
142
    )
143
    prompt.side_effect = [
144
        # release_directory
145
        'docs/releases',
146
        # bumpversion files
147
        'version.txt',
148
        # quit prompt
149
        '.',
150
        # label descriptions
151
        # 'Features',
152
        # 'Bug Fixes'
153
    ]
154
155
    prompt = mocker.patch(
156
        'changes.config.choose_labels',
157
        autospec=True
158
    )
159
    prompt.return_value = ['bug']
160
161
162
@pytest.fixture
163
def with_auth_token_prompt(mocker):
164
    _ = mocker.patch('changes.config.click.launch')
165
166
    prompt = mocker.patch('changes.config.click.prompt')
167
    prompt.return_value = 'foo'
168
169
    saved_token = None
170
    if os.environ.get(AUTH_TOKEN_ENVVAR):
171
        saved_token = os.environ[AUTH_TOKEN_ENVVAR]
172
        del os.environ[AUTH_TOKEN_ENVVAR]
173
174
    yield
175
176
    if saved_token:
177
        os.environ[AUTH_TOKEN_ENVVAR] = saved_token
178
179
180
@pytest.fixture
181
def with_auth_token_envvar():
182
    saved_token = None
183
    if os.environ.get(AUTH_TOKEN_ENVVAR):
184
        saved_token = os.environ[AUTH_TOKEN_ENVVAR]
185
186
    os.environ[AUTH_TOKEN_ENVVAR] = 'foo'
187
188
    yield
189
190
    if saved_token:
191
        os.environ[AUTH_TOKEN_ENVVAR] = saved_token
192
    else:
193
        del os.environ[AUTH_TOKEN_ENVVAR]
194
195
196
@pytest.fixture
197
def changes_config_in_tmpdir(monkeypatch, tmpdir):
198
    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...
199
200
    changes_config_file = Path(str(tmpdir.join('.changes')))
201
    monkeypatch.setattr(
202
        changes.config,
203
        'expandvars' if IS_WINDOWS else 'expanduser',
204
        lambda x: str(changes_config_file)
205
    )
206
    assert not changes_config_file.exists()
207
    return changes_config_file
208
209
210
@pytest.fixture
211
def configured(git_repo, changes_config_in_tmpdir):
0 ignored issues
show
Comprehensibility Bug introduced by
changes_config_in_tmpdir is re-defining a name which is already available in the outer-scope (previously defined on line 197).

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...
Comprehensibility Bug introduced by
git_repo is re-defining a name which is already available in the outer-scope (previously defined on line 73).

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...
212
    changes_config_in_tmpdir.write_text(textwrap.dedent(
213
        """\
214
        [changes]
215
        auth_token = "foo"
216
        """
217
    ))
218
219
    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...
220
        """\
221
        [changes]
222
        releases_directory = "docs/releases"
223
224
        [changes.labels.bug]
225
        default = true
226
        id = 208045946
227
        url = "https://api.github.com/repos/michaeljoseph/test_app/labels/bug"
228
        name = "bug"
229
        description = "Bug"
230
        color = "f29513"
231
        """
232
    ))
233
234
    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...
235
        """\
236
        [bumpversion]
237
        current_version = 0.0.1
238
239
        [bumpversion:file:version.txt]
240
        """
241
    ))
242
243
    for file_to_add in ['.changes.toml', '.bumpversion.cfg']:
244
        git('add', file_to_add)
245
    git('commit', '-m', 'Add changes configuration files')
246
247
    return str(changes_config_in_tmpdir)
248