Completed
Push — init-test ( 3e12e7 )
by Michael
07:46 queued 07:14
created

git_repo_with_merge_commit()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
1
import os
2
3
import pytest
4
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...
5
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...
6
7
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...
8
9
# TODO: textwrap.dedent.heredoc
10
INIT_CONTENT = [
11
    '"""A test app"""',
12
    '',
13
    "__version__ = '0.0.1'",
14
    "__url__ = 'https://github.com/someuser/test_app'",
15
    "__author__ = 'Some User'",
16
    "__email__ = '[email protected]'"
17
]
18
SETUP_PY = [
19
    'from setuptools import setup',
20
    "setup(name='test_app'",
21
]
22
README_MARKDOWN = [
23
    '# Test App',
24
    '',
25
    'This is the test application.'
26
]
27
28
PYTHON_MODULE = 'test_app'
29
30
FILE_CONTENT = {
31
    '%s/__init__.py' % PYTHON_MODULE: INIT_CONTENT,
32
    'setup.py': SETUP_PY,
33
    'requirements.txt': ['pytest'],
34
    'README.md': README_MARKDOWN,
35
    'CHANGELOG.md': [''],
36
}
37
38
39
def git_init(files_to_add):
40
    git('init')
41
    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...
42
    for file_to_add in files_to_add:
43
        git('add', file_to_add)
44
    git('commit', '-m', 'Initial commit')
45
46
47
def github_merge_commit():
48
    github = 'Merge pull request #111 from test_app/test-branch'
49
    git('checkout', '-b', 'test-branch')
50
    git('commit', '--allow-empty', '-m', 'Test branch commit message')
51
    git('checkout', 'master')
52
    git('merge', '--no-ff', 'test-branch')
53
    git('commit', '--allow-empty', '--amend', '-m', github)
54
55
56
@pytest.fixture
57
def git_repo():
58
    with CliRunner().isolated_filesystem():
59
        readme_path = 'README.md'
60
        open(readme_path, 'w').write(
61
            '\n'.join(README_MARKDOWN)
62
        )
63
        git_init([readme_path])
64
65
        yield
66
67
68
@pytest.fixture
69
def git_repo_with_merge_commit(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 57).

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...
70
    github_merge_commit()
71
72
73
@pytest.fixture
74
def python_module():
75
    with CliRunner().isolated_filesystem():
76
        os.mkdir(PYTHON_MODULE)
77
78
        for file_path, content in FILE_CONTENT.items():
79
            open(file_path, 'w').write(
80
                '\n'.join(content)
81
            )
82
83
        git_init(FILE_CONTENT.keys())
84
85
        yield
86