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

patch_user_home_to_tmpdir_path()   A

Complexity

Conditions 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
c 2
b 0
f 0
dl 0
loc 12
rs 9.2
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/changes/labels/bug',
64
        'name': 'bug',
65
        'color': 'fc2929',
66
        'default': True
67
    }
68
]
69
70
71
@pytest.fixture
72
def git_repo():
73
    with CliRunner().isolated_filesystem() as tempdir:
74
        readme_path = 'README.md'
75
        open(readme_path, 'w').write(
76
            '\n'.join(README_MARKDOWN)
77
        )
78
        version_path = 'version.txt'
79
        open(version_path, 'w').write('0.0.1')
80
81
        git_init([readme_path, version_path])
82
83
        yield tempdir
84
85
86
@pytest.fixture
87
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 72).

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...
88
    os.mkdir(PYTHON_MODULE)
89
90
    for file_path, content in FILE_CONTENT.items():
91
        open(file_path, 'w').write(
92
            '\n'.join(content)
93
        )
94
95
    git('add', [file for file in FILE_CONTENT.keys()])
96
97
    yield
98
99
100
def git_init(files_to_add):
101
    git('init')
102
    git(shlex.split('config --local user.email "[email protected]"'))
103
    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...
104
    for file_to_add in files_to_add:
105
        git('add', file_to_add)
106
    git('commit', '-m', 'Initial commit')
107
    git(shlex.split('tag 0.0.1'))
108
109
110
def github_merge_commit(pull_request_number):
111
    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...
112
113
    branch_name = Haikunator().haikunate()
114
    commands = [
115
        'checkout -b {}'.format(branch_name),
116
        'commit --allow-empty -m "Test branch commit message"',
117
        'checkout master',
118
        'merge --no-ff {}'.format(branch_name),
119
120
        'commit --allow-empty --amend -m '
121
        '"Merge pull request #{} from test_app/{}"'.format(
122
            pull_request_number,
123
            branch_name,
124
        )
125
    ]
126
    for command in commands:
127
        git(shlex.split(command))
128
129
130
@pytest.fixture
131
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...
132
    prompt = mocker.patch(
133
        'changes.config.click.prompt',
134
        autospec=True
135
    )
136
    prompt.side_effect = [
137
        # release_directory
138
        'docs/releases',
139
        # bumpversion files
140
        'version.txt',
141
        # quit prompt
142
        '.',
143
        # label descriptions
144
        # 'Features',
145
        # 'Bug Fixes'
146
    ]
147
148
    prompt = mocker.patch(
149
        'changes.config.choose_labels',
150
        autospec=True
151
    )
152
    prompt.return_value = ['bug']
153
154
155
@pytest.fixture
156
def with_auth_token_prompt(mocker):
157
    _ = mocker.patch('changes.config.click.launch')
158
159
    prompt = mocker.patch('changes.config.click.prompt')
160
    prompt.return_value = 'foo'
161
162
    saved_token = None
163
    if os.environ.get(AUTH_TOKEN_ENVVAR):
164
        saved_token = os.environ[AUTH_TOKEN_ENVVAR]
165
        del os.environ[AUTH_TOKEN_ENVVAR]
166
167
    yield
168
169
    if saved_token:
170
        os.environ[AUTH_TOKEN_ENVVAR] = saved_token
171
172
173
@pytest.fixture
174
def with_auth_token_envvar():
175
    saved_token = None
176
    if os.environ.get(AUTH_TOKEN_ENVVAR):
177
        saved_token = os.environ[AUTH_TOKEN_ENVVAR]
178
179
    os.environ[AUTH_TOKEN_ENVVAR] = 'foo'
180
181
    yield
182
183
    if saved_token:
184
        os.environ[AUTH_TOKEN_ENVVAR] = saved_token
185
    else:
186
        del os.environ[AUTH_TOKEN_ENVVAR]
187
188
189
@pytest.fixture
190
def changes_config_in_tmpdir(monkeypatch, tmpdir):
191
    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...
192
193
    changes_config_file = Path(str(tmpdir.join('.changes')))
194
    monkeypatch.setattr(
195
        changes.config,
196
        'expandvars' if IS_WINDOWS else 'expanduser',
197
        lambda x: str(changes_config_file)
198
    )
199
    assert not changes_config_file.exists()
200
    return changes_config_file
201
202
203
@pytest.fixture
204
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 190).

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 72).

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...
205
    changes_config_in_tmpdir.write_text(textwrap.dedent(
206
        """\
207
        [changes]
208
        auth_token = "foo"
209
        """
210
    ))
211
212
    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...
213
        """\
214
        [changes]
215
        releases_directory = "docs/releases"
216
217
        [changes.labels.bug]
218
        default = true
219
        id = 208045946
220
        url = "https://api.github.com/repos/michaeljoseph/test_app/labels/bug"
221
        name = "bug"
222
        description = "Bug"
223
        color = "f29513"
224
        """
225
    ))
226
227
    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...
228
        """\
229
        [bumpversion]
230
        current_version = 0.0.1
231
232
        [bumpversion:file:version.txt]
233
        """
234
    ))
235
236
    return str(changes_config_in_tmpdir)
237