Completed
Pull Request — master (#121)
by
unknown
291:44 queued 281:46
created

git_repo_with_merge_commit()   A

Complexity

Conditions 1

Size

Total Lines 5

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