Failed Conditions
Pull Request — master (#2076)
by Abdeali
02:11
created

raise_error()   A

Complexity

Conditions 1

Size

Total Lines 2

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 2
rs 10
1
from contextlib import contextmanager
2
import os
3
import sys
4
import unittest.mock
5
6
from coalib.misc.ContextManagers import retrieve_stdout
7
8
9
def execute_coala(func, binary, *args):
10
    """
11
    Executes the main function with the given argument string from given module.
12
13
    :param function: A main function from coala_json, coala_ci module etc.
14
    :param binary:   A binary to execute coala test
15
    :return:         A tuple holding a return value first and
16
                     a stdout output as second element.
17
    """
18
    sys.argv = [binary] + list(args)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable args does not seem to be defined.
Loading history...
19
    with retrieve_stdout() as stdout:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable stdout does not seem to be defined.
Loading history...
20
        retval = func()
21
        return retval, stdout.getvalue()
22
23
24
@contextmanager
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable contextmanager does not seem to be defined.
Loading history...
25
def bear_test_module():
26
    """
27
    This function mocks the ``pkg_resources.iter_entry_points()``
28
    to use the testing bear module we have. Hence, it doesn't test
29
    the collection of entry points.
30
    """
31
    bears_test_module = os.path.join(os.path.dirname(__file__),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable __file__ does not seem to be defined.
Loading history...
32
                                     "test_bears", "__init__.py")
33
34
    class EntryPoint:
35
36
        @staticmethod
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable staticmethod does not seem to be defined.
Loading history...
37
        def load():
38
            class PseudoPlugin:
39
                __file__ = bears_test_module
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable bears_test_module does not seem to be defined.
Loading history...
40
            return PseudoPlugin()
41
42
    with unittest.mock.patch("pkg_resources.iter_entry_points",
43
                             return_value=[EntryPoint()]) as mocked:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable mocked does not seem to be defined.
Loading history...
44
        yield
45
46
47
def raise_error(error, *args, **kwargs):
48
    raise error(*args, **kwargs)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable kwargs does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable args does not seem to be defined.
Loading history...
49