Exemplo n.º 1
0
    def test_remove_exception(self, mock_glob):
        # Non existent file
        mock_glob.return_value = ['non_existent_file']
        with retrieve_stderr() as stderr:
            retval = coala_delete_orig.main(section=self.section)
            output = stderr.getvalue()
            self.assertEqual(retval, 0)
            self.assertIn("Couldn't delete", output)

        # Directory instead of file
        with tempfile.TemporaryDirectory() as filename:
            with retrieve_stderr() as stderr:
                mock_glob.return_value = [filename]
                retval = coala_delete_orig.main(section=self.section)
                output = stderr.getvalue()
                self.assertEqual(retval, 0)
                self.assertIn("Couldn't delete", output)
Exemplo n.º 2
0
    def test_remove_exception(self, mock_glob):
        # Non existent file
        mock_glob.return_value = ['non_existent_file']
        with retrieve_stderr() as stderr:
            retval = coala_delete_orig.main(section=self.section)
            output = stderr.getvalue()
            self.assertEqual(retval, 0)
            self.assertIn("Couldn't delete", output)

        # Directory instead of file
        with tempfile.TemporaryDirectory() as filename, \
                retrieve_stderr() as stderr:
            mock_glob.return_value = [filename]
            retval = coala_delete_orig.main(section=self.section)
            output = stderr.getvalue()
            self.assertEqual(retval, 0)
            self.assertIn("Couldn't delete", output)
Exemplo n.º 3
0
 def test_timeout_deprecation_warning(self):
     with retrieve_stderr() as stderr:
         verify_local_bear(TestBear,
                           valid_files=(),
                           invalid_files=files,
                           timeout=50)
         self.assertIn(
             'timeout is ignored as the timeout set in the repo '
             'configuration will be sufficient', stderr.getvalue())
Exemplo n.º 4
0
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 as first element,
                        a stdout output as second element and a stderr output
                        as third element if stdout_only is False.
    """
    sys.argv = [binary] + list(args)
    with retrieve_stdout() as stdout:
        with retrieve_stderr() as stderr:
            retval = func()
            return (retval, stdout.getvalue(), stderr.getvalue())
Exemplo n.º 5
0
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 as first element,
                        a stdout output as second element and a stderr output
                        as third element if stdout_only is False.
    """
    sys.argv = [binary] + list(args)
    with retrieve_stdout() as stdout:
        with retrieve_stderr() as stderr:
            retval = func()
            return (retval, stdout.getvalue(), stderr.getvalue())
Exemplo n.º 6
0
def execute_coala(func, binary, *args, stdout_only=False):
    """
    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
    :param stdout_only: Get the stdout output only, discard stderr
    :return:            A tuple holding a return value first and
                        a stdout output as second element.
    """
    sys.argv = [binary] + list(args)
    with retrieve_stdout() as stdout:
        with retrieve_stderr() as stderr:
            retval = func()
            return (retval,
                    stdout.getvalue() if stdout_only else stdout.getvalue() +
                    '\n' + stderr.getvalue())
Exemplo n.º 7
0
def execute_coala(func, binary, *args, stdout_only=False):
    """
    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
    :param stdout_only: Get the stdout output only, discard stderr
    :return:            A tuple holding a return value first and
                        a stdout output as second element.
    """
    sys.argv = [binary] + list(args)
    with retrieve_stdout() as stdout:
        with retrieve_stderr() as stderr:
            retval = func()
            return (retval,
                    stdout.getvalue() if stdout_only else
                    stdout.getvalue() + '\n' + stderr.getvalue())
Exemplo n.º 8
0
 def test_retrieve_stderr(self):
     with retrieve_stderr() as sio:
         print("test", file=sys.stderr)
         self.assertEqual(sio.getvalue(), "test\n")
Exemplo n.º 9
0
 def test_retrieve_stderr(self):
     with retrieve_stderr() as sio:
         print('test', file=sys.stderr)
         self.assertEqual(sio.getvalue(), 'test\n')