Exemple #1
0
def test_flake8_config_param(config):
    with patch('pyls.plugins.flake8_lint.Popen') as popen_mock:
        flake8_conf = '/tmp/some.cfg'
        config.update({'plugins': {'flake8': {'config': flake8_conf}}})
        _name, doc = temp_document(DOC)
        flake8_lint.pyls_lint(config, doc)
        call_args = popen_mock.call_args.args[0]
        assert 'flake8' in call_args
        assert '--config={}'.format(flake8_conf) in call_args
def test_flake8_config_param(workspace):
    with patch('pyls.plugins.flake8_lint.Popen') as popen_mock:
        mock_instance = popen_mock.return_value
        mock_instance.communicate.return_value = [bytes(), bytes()]
        flake8_conf = '/tmp/some.cfg'
        workspace._config.update({'plugins': {'flake8': {'config': flake8_conf}}})
        _name, doc = temp_document(DOC, workspace)
        flake8_lint.pyls_lint(workspace, doc)
        call_args = popen_mock.call_args.args[0]
        assert 'flake8' in call_args
        assert '--config={}'.format(flake8_conf) in call_args
def test_flake8_executable_param(workspace):
    with patch('pyls.plugins.flake8_lint.Popen') as popen_mock:
        mock_instance = popen_mock.return_value
        mock_instance.communicate.return_value = [bytes(), bytes()]

        flake8_executable = '/tmp/flake8'
        workspace._config.update({'plugins': {'flake8': {'executable': flake8_executable}}})

        _name, doc = temp_document(DOC, workspace)
        flake8_lint.pyls_lint(workspace, doc)

        call_args = popen_mock.call_args.args[0]
        assert flake8_executable in call_args
def test_flake8_no_checked_file(config, workspace):
    # A bad uri or a non-saved file may cause the flake8 linter to do nothing.
    # In this situtation, the linter will return an empty list.

    doc = Document('', workspace, DOC)
    diags = flake8_lint.pyls_lint(config, doc)
    assert 'Error' in diags[0]['message']
Exemple #5
0
def test_flake8_no_checked_file(config):
    # A bad uri or a non-saved file may cause the flake8 linter to do nothing.
    # In this situtation, the linter will return an empty list.

    doc = Document('', DOC)
    diags = flake8_lint.pyls_lint(config, doc)
    assert diags == []
def test_flake8_unsaved(workspace):
    doc = Document('', workspace, DOC)
    diags = flake8_lint.pyls_lint(workspace, doc)
    msg = 'F841 local variable \'a\' is assigned to but never used'
    unused_var = [d for d in diags if d['message'] == msg][0]

    assert unused_var['source'] == 'flake8'
    assert unused_var['code'] == 'F841'
    assert unused_var['range']['start'] == {'line': 5, 'character': 1}
    assert unused_var['range']['end'] == {'line': 5, 'character': 11}
    assert unused_var['severity'] == lsp.DiagnosticSeverity.Warning
def test_flake8_lint(config):
    try:
        name, doc = temp_document(DOC)
        diags = flake8_lint.pyls_lint(config, doc)
        msg = 'local variable \'a\' is assigned to but never used'
        unused_var = [d for d in diags if d['message'] == msg][0]

        assert unused_var['source'] == 'flake8'
        assert unused_var['code'] == 'F841'
        assert unused_var['range']['start'] == {'line': 5, 'character': 1}
        assert unused_var['range']['end'] == {'line': 5, 'character': 11}
        assert unused_var['severity'] == lsp.DiagnosticSeverity.Warning

    finally:
        os.remove(name)