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