Completed
Push — publish ( 2881fa )
by Michael
05:30
created

changes_config_in_tmpdir()   A

Complexity

Conditions 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
c 0
b 0
f 0
dl 0
loc 12
rs 9.2
1
import os
2
import shlex
3
from pathlib import Path
4
5
import pytest
6
import sys
7
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...
8
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...
9
10
import changes
11
12
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...
13
14
# TODO: textwrap.dedent.heredoc
15
INIT_CONTENT = [
16
    '"""A test app"""',
17
    '',
18
    "__version__ = '0.0.1'",
19
    "__url__ = 'https://github.com/someuser/test_app'",
20
    "__author__ = 'Some User'",
21
    "__email__ = '[email protected]'"
22
]
23
SETUP_PY = [
24
    'from setuptools import setup',
25
    "setup(name='test_app'",
26
]
27
README_MARKDOWN = [
28
    '# Test App',
29
    '',
30
    'This is the test application.'
31
]
32
33
PYTHON_MODULE = 'test_app'
34
35
FILE_CONTENT = {
36
    '%s/__init__.py' % PYTHON_MODULE: INIT_CONTENT,
37
    'setup.py': SETUP_PY,
38
    'requirements.txt': ['pytest'],
39
    'README.md': README_MARKDOWN,
40
    'CHANGELOG.md': [''],
41
}
42
ISSUE_URL = 'https://api.github.com/repos/michaeljoseph/test_app/issues/{}'
43
LABEL_URL = 'https://api.github.com/repos/michaeljoseph/test_app/labels'
44
AUTH_TOKEN_ENVVAR = 'GITHUB_AUTH_TOKEN'
45
46
47
@pytest.fixture
48
def python_module():
49
    with CliRunner().isolated_filesystem():
50
        os.mkdir(PYTHON_MODULE)
51
52
        for file_path, content in FILE_CONTENT.items():
53
            open(file_path, 'w').write(
54
                '\n'.join(content)
55
            )
56
57
        git_init(FILE_CONTENT.keys())
58
59
        yield
60
61
62
@pytest.fixture
63
def git_repo():
64
    with CliRunner().isolated_filesystem():
65
        readme_path = 'README.md'
66
        open(readme_path, 'w').write(
67
            '\n'.join(README_MARKDOWN)
68
        )
69
        version_path = 'version.txt'
70
        open(version_path, 'w').write('0.0.1')
71
72
        git_init([readme_path, version_path])
73
74
        yield
75
76
77
def git_init(files_to_add):
78
    git('init')
79
    git(shlex.split('config --local user.email "[email protected]"'))
80
    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...
81
    for file_to_add in files_to_add:
82
        git('add', file_to_add)
83
    git('commit', '-m', 'Initial commit')
84
    git(shlex.split('tag 0.0.1'))
85
86
87
def github_merge_commit(pull_request_number):
88
    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...
89
90
    branch_name = Haikunator().haikunate()
91
    commands = [
92
        'checkout -b {}'.format(branch_name),
93
        'commit --allow-empty -m "Test branch commit message"',
94
        'checkout master',
95
        'merge --no-ff {}'.format(branch_name),
96
97
        'commit --allow-empty --amend -m '
98
        '"Merge pull request #{} from test_app/{}"'.format(
99
            pull_request_number,
100
            branch_name,
101
        )
102
    ]
103
    for command in commands:
104
        git(shlex.split(command))
105
106
107
@pytest.fixture
108
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...
109
    prompt = mocker.patch(
110
        'changes.config.click.prompt',
111
        autospec=True
112
    )
113
    prompt.side_effect = [
114
        # release_directory
115
        'docs/releases',
116
        # bumpversion files
117
        'version.txt',
118
        # quit prompt
119
        '.',
120
        # label descriptions
121
        # 'Features',
122
        # 'Bug Fixes'
123
    ]
124
125
    prompt = mocker.patch(
126
        'changes.config.read_user_choices',
127
        autospec=True
128
    )
129
    prompt.return_value = ['bug']
130
131
132
@pytest.fixture
133
def with_auth_token_prompt(mocker):
134
    _ = mocker.patch('changes.config.click.launch')
135
136
    prompt = mocker.patch('changes.config.click.prompt')
137
    prompt.return_value = 'foo'
138
139
    saved_token = None
140
    if os.environ.get(AUTH_TOKEN_ENVVAR):
141
        saved_token = os.environ[AUTH_TOKEN_ENVVAR]
142
        del os.environ[AUTH_TOKEN_ENVVAR]
143
144
    yield
145
146
    if saved_token:
147
        os.environ[AUTH_TOKEN_ENVVAR] = saved_token
148
149
150
@pytest.fixture
151
def with_auth_token_envvar():
152
    saved_token = None
153
    if os.environ.get(AUTH_TOKEN_ENVVAR):
154
        saved_token = os.environ[AUTH_TOKEN_ENVVAR]
155
156
    os.environ[AUTH_TOKEN_ENVVAR] = 'foo'
157
158
    yield
159
160
    if saved_token:
161
        os.environ[AUTH_TOKEN_ENVVAR] = saved_token
162
163
import changes
0 ignored issues
show
Unused Code introduced by
The import changes was already done on line 10. You should be able to
remove this line.
Loading history...
164
@pytest.fixture
165
def changes_config_in_tmpdir(monkeypatch, tmpdir):
166
    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...
167
168
    changes_config_file = Path(str(tmpdir.join('.changes')))
169
    monkeypatch.setattr(
170
        changes.config,
171
        'expandvars' if IS_WINDOWS else 'expanduser',
172
        lambda x: str(changes_config_file)
173
    )
174
    assert not changes_config_file.exists()
175
    return changes_config_file
176