Exemplo n.º 1
0
 def make_file_checker_manager(self) -> None:
     """Initialize our FileChecker Manager."""
     self.file_checker_manager = checker.Manager(
         style_guide=self.guide,
         arguments=self.args,
         checker_plugins=self.check_plugins,
     )
Exemplo n.º 2
0
def test_oserrors_cause_serial_fall_back():
    """Verify that OSErrors will cause the Manager to fallback to serial."""
    err = OSError(errno.ENOSPC, 'Ominous message about spaceeeeee')
    style_guide = style_guide_mock()
    with mock.patch('multiprocessing.Queue', side_effect=err):
        manager = checker.Manager(style_guide, [], [])
    assert manager.using_multiprocessing is False
Exemplo n.º 3
0
def test_report_order(results, expected_order):
    """
    Test in which order the results will be reported.

    It gets a list of reports from the file checkers and verifies that the
    result will be ordered independent from the original report.
    """
    def count_side_effect(name, sorted_results):
        """Side effect for the result handler to tell all are reported."""
        return len(sorted_results)

    # To simplify the parameters (and prevent copy & pasting) reuse report
    # tuples to create the expected result lists from the indexes
    expected_results = [results[index] for index in expected_order]

    file_checker = mock.Mock(spec=['results', 'display_name'])
    file_checker.results = results
    file_checker.display_name = 'placeholder'

    style_guide = mock.Mock(spec=['options'])
    style_guide.processing_file = mock.MagicMock()

    # Create a placeholder manager without arguments or plugins
    # Just add one custom file checker which just provides the results
    manager = checker.Manager(style_guide, [], [])
    manager.checkers = [file_checker]

    # _handle_results is the first place which gets the sorted result
    # Should something non-private be mocked instead?
    handler = mock.Mock()
    handler.side_effect = count_side_effect
    manager._handle_results = handler

    assert manager.report() == (len(results), len(results))
    handler.assert_called_once_with('placeholder', expected_results)
Exemplo n.º 4
0
def test_oserrors_are_reraised():
    """Verify that OSErrors will cause the Manager to fallback to serial."""
    err = OSError(errno.EAGAIN, 'Ominous message')
    style_guide = style_guide_mock()
    with mock.patch('multiprocessing.Queue', side_effect=err):
        with pytest.raises(OSError):
            checker.Manager(style_guide, [], [])
Exemplo n.º 5
0
def _parallel_checker_manager():
    """Call Manager.run() and return the number of calls to `run_serial`."""
    style_guide = style_guide_mock()
    manager = checker.Manager(style_guide, [], [])
    # multiple checkers is needed for parallel mode
    manager.checkers = [mock.Mock(), mock.Mock()]
    return manager
Exemplo n.º 6
0
 def make_file_checker_manager(self):
     # type: () -> NoneType
     """Initialize our FileChecker Manager."""
     if self.file_checker_manager is None:
         self.file_checker_manager = checker.Manager(
             style_guide=self.guide,
             arguments=self.args,
             checker_plugins=self.check_plugins,
         )
Exemplo n.º 7
0
def test_oserrors_are_reraised(is_windows):
    """Verify that unexpected OSErrors will cause the Manager to reraise."""
    err = OSError(errno.EAGAIN, 'Ominous message')
    style_guide = style_guide_mock()
    with mock.patch('_multiprocessing.SemLock', side_effect=err):
        with pytest.raises(OSError):
            manager = checker.Manager(style_guide, [], [])
            with mock.patch.object(manager, 'run_serial') as serial:
                manager.run()
    assert serial.call_count == 0
Exemplo n.º 8
0
def test_oserrors_cause_serial_fall_back():
    """Verify that OSErrors will cause the Manager to fallback to serial."""
    err = OSError(errno.ENOSPC, 'Ominous message about spaceeeeee')
    style_guide = style_guide_mock()
    with mock.patch('_multiprocessing.SemLock', side_effect=err):
        manager = checker.Manager(style_guide, [], [])
        with mock.patch.object(manager, 'run_serial') as serial:
            manager.run()
    assert serial.call_count == 1
    assert manager.using_multiprocessing is False
Exemplo n.º 9
0
def test_make_checkers():
    """Verify that we create a list of FileChecker instances."""
    style_guide = style_guide_mock()
    files = ['file1', 'file2']
    with mock.patch('flake8.checker.multiprocessing', None):
        manager = checker.Manager(style_guide, files, [])

    with mock.patch('flake8.utils.filenames_from') as filenames_from:
        filenames_from.side_effect = [['file1'], ['file2']]
        with mock.patch('flake8.utils.fnmatch', return_value=True):
            with mock.patch('flake8.processor.FileProcessor'):
                manager.make_checkers()

    for file_checker in manager.checkers:
        assert file_checker.filename in files
Exemplo n.º 10
0
def test_make_checkers():
    """Verify that we create a list of FileChecker instances."""
    style_guide = style_guide_mock()
    files = ['file1', 'file2']
    checkplugins = mock.Mock()
    checkplugins.to_dictionary.return_value = {
        'ast_plugins': [],
        'logical_line_plugins': [],
        'physical_line_plugins': [],
    }
    with mock.patch('flake8.checker.multiprocessing', None):
        manager = checker.Manager(style_guide, files, checkplugins)

    with mock.patch('flake8.utils.filenames_from') as filenames_from:
        filenames_from.side_effect = [['file1'], ['file2']]
        with mock.patch('flake8.utils.fnmatch', return_value=True):
            with mock.patch('flake8.processor.FileProcessor'):
                manager.make_checkers()

    for file_checker in manager.checkers:
        assert file_checker.filename in files
Exemplo n.º 11
0
def test_make_checkers():
    """Verify that we create a list of FileChecker instances."""
    style_guide = style_guide_mock()
    files = ["file1", "file2"]
    checkplugins = mock.Mock()
    checkplugins.to_dictionary.return_value = {
        "ast_plugins": [],
        "logical_line_plugins": [],
        "physical_line_plugins": [],
    }
    with mock.patch("flake8.checker.multiprocessing", None):
        manager = checker.Manager(style_guide, files, checkplugins)

    with mock.patch("flake8.utils.filenames_from") as filenames_from:
        filenames_from.side_effect = [["file1"], ["file2"]]
        with mock.patch("flake8.utils.fnmatch", return_value=True):
            with mock.patch("flake8.processor.FileProcessor"):
                manager.make_checkers()

    assert manager._all_checkers
    for file_checker in manager._all_checkers:
        assert file_checker.filename in files
    assert not manager.checkers  # the files don't exist
Exemplo n.º 12
0
def test_multiprocessing_is_disabled():
    """Verify not being able to import multiprocessing forces jobs to 0."""
    style_guide = style_guide_mock()
    with mock.patch('flake8.checker.multiprocessing', None):
        manager = checker.Manager(style_guide, [], [])
        assert manager.jobs == 0