for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
from contextlib import contextmanager
import os
import sys
import unittest.mock
from coalib.misc.ContextManagers import retrieve_stdout
def execute_coala(func, binary, *args):
"""
Executes the main function with the given argument string from given module.
:param function: A main function from coala_json, coala_ci module etc.
:param binary: A binary to execute coala test
:return: A tuple holding a return value first and
a stdout output as second element.
sys.argv = [binary] + list(args)
args
with retrieve_stdout() as stdout:
stdout
retval = func()
return retval, stdout.getvalue()
@contextmanager
contextmanager
def bear_test_module():
This function mocks the ``pkg_resources.iter_entry_points()``
to use the testing bear module we have. Hence, it doesn't test
the collection of entry points.
bears_test_module = os.path.join(os.path.dirname(__file__),
__file__
"test_bears", "__init__.py")
class EntryPoint:
@staticmethod
staticmethod
def load():
class PseudoPlugin:
__file__ = bears_test_module
bears_test_module
return PseudoPlugin()
with unittest.mock.patch("pkg_resources.iter_entry_points",
return_value=[EntryPoint()]) as mocked:
mocked
yield
def raise_error(error, *args, **kwargs):
raise error(*args, **kwargs)
kwargs