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
![]() |
|||
19 | with retrieve_stdout() as stdout: |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
20 | retval = func() |
||
21 | return retval, stdout.getvalue() |
||
22 | |||
23 | |||
24 | @contextmanager |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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
|
|||
32 | "test_bears", "__init__.py") |
||
33 | |||
34 | class EntryPoint: |
||
35 | |||
36 | @staticmethod |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
37 | def load(): |
||
38 | class PseudoPlugin: |
||
39 | __file__ = bears_test_module |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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
|
|||
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
Comprehensibility
Best Practice
introduced
by
|
|||
49 |