How to use the testfixtures.OutputCapture function in testfixtures

To help you get started, we’ve selected a few testfixtures examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Simplistix / picky-conda / tests / test_main.py View on Github external
def run(argv, expected_output=''):
    with Replacer() as r:
        r.replace('sys.argv', ['x']+argv)
        r.replace('picky.main.conda_env_export',
                  mock_conda_env_export)
        with OutputCapture() as output:
            rc = main()
    output.compare(expected_output)
    return rc
github gforcada / flake8-isort / run_tests.py View on Github external
def check_if_config_file_is_used(self, method_to_write_config):
        (file_path, lines) = self.write_python_file(
            'import os\n'
            'from sys import path\n',
        )
        method_to_write_config('lines_between_types=1')

        with OutputCapture():
            checker = Flake8Isort(None, file_path, lines)
            ret = list(checker.run())
            self.assertEqual(len(ret), 1)
            self.assertEqual(ret[0][0], 2)
            self.assertEqual(ret[0][1], 0)
            self.assertTrue(ret[0][2].startswith('I003 '))
github Simplistix / picky-conda / tests / test_env.py View on Github external
def test_same(self):
        with OutputCapture() as output:
            result = diff(sample_env, sample_env)
        assert result == 0
        output.compare('')
github gforcada / flake8-isort / run_tests.py View on Github external
def test_imports_unexpected_blank_line(self):
        (file_path, lines) = self.write_python_file(
            'from __future__ import division\n'
            '\n'
            'import threading\n'
            '\n'
            'from sys import pid\n',
        )
        with OutputCapture():
            checker = Flake8Isort(None, file_path, lines)
            ret = list(checker.run())
            self.assertEqual(len(ret), 1)
            self.assertEqual(ret[0][0], 4)
            self.assertEqual(ret[0][1], 0)
            self.assertTrue(ret[0][2].startswith('I004 '))
github gforcada / flake8-isort / run_tests.py View on Github external
def test_file_skipped_with_comment(self):
        # Note: files skipped in this way are not marked as
        # "skipped" by isort <= 4.2.15, so we handle them in a
        # different code path and test to ensure they also work.
        (file_path, lines) = self.write_python_file(
            '# isort:skip_file',
        )
        with OutputCapture():
            checker = Flake8Isort(None, file_path, lines)
            ret = list(checker.run())
            self.assertEqual(ret, [])
github gforcada / flake8-isort / run_tests.py View on Github external
def test_with_eof_blank_lines(self):
        """Pass with eof blank line as flake8 will flag them"""
        (file_path, lines) = self.write_python_file(
            'import os\n'
            'from sys import path\n'
            '\n'
            '\n'
            '   \n',
        )
        with OutputCapture():
            checker = Flake8Isort(None, file_path, lines)
            ret = list(checker.run())
            self.assertEqual(ret, [])
github gforcada / flake8-isort / flake8_isort.py View on Github external
def run(self):
        if self.filename is not self.stdin_display_name:
            file_path = self.filename
        else:
            file_path = None
        with OutputCapture() as buffer:
            sort_result = SortImports(
                file_path=file_path,
                file_contents=''.join(self.lines),
                check=True,
                show_diff=True,
            )
        traceback = self._format_isort_output(buffer)

        for line_num, message in self.sortimports_linenum_msg(sort_result):
            if self.show_traceback:
                message += traceback
            yield line_num, 0, message, type(self)