Exemple #1
0
def test_pycodestyle_config():
    """ Test that we load config files properly.

    Config files are loaded in the following order:
        tox.ini pep8.cfg setup.cfg pycodestyle.cfg

    Each overriding the values in the last.

    These files are first looked for in the current document's
    directory and then each parent directory until any one is found
    terminating at the workspace root.

    If any section called 'pycodestyle' exists that will be solely used
    and any config in a 'pep8' section will be ignored
    """
    # Create a workspace in tmp
    tmp = tempfile.mkdtemp()
    workspace = Workspace(tmp)
    doc_uri = 'file://' + tmp + '/' + 'test.py'

    provider = PyCodeStyleLinter(workspace)
    workspace.put_document(doc_uri, DOC)

    # Make sure we get a warning for 'indentation contains tabs'
    diags = provider.run(doc_uri)
    assert len([d for d in diags if d['code'] == 'W191']) > 0

    content = {
        'setup.cfg': ('[pycodestyle]\nignore = W191', True),
        'pep8.cfg': ('[pep8]\nignore = W191', True),
        'tox.ini': ('', False)
    }

    for conf_file, (content, working) in list(content.items()):
        # Now we'll add config file to ignore it
        with open(os.path.join(tmp, conf_file), 'w+') as f:
            f.write(content)

        # And make sure we don't get any warnings
        diags = provider.run(doc_uri)
        assert len([d for d in diags
                    if d['code'] == 'W191']) == 0 if working else 1

        os.unlink(os.path.join(tmp, conf_file))

    shutil.rmtree(tmp)
Exemple #2
0
def tmp_workspace():
    tmp = tempfile.mkdtemp()
    workspace = Workspace(tmp)

    def create_file(name, content):
        fn = os.path.join(tmp, name)
        with open(fn, 'w') as f:
            f.write(content)
        workspace.put_document('file://' + fn, content)

    create_file(DOC1_NAME, DOC1)
    create_file(DOC2_NAME, DOC2)

    yield workspace
    shutil.rmtree(tmp)
Exemple #3
0
def workspace_other_root_path(tmpdir):
    """Return a workspace with a root_path other than tmpdir."""
    ws_path = str(tmpdir.mkdir('test123').mkdir('test456'))
    ws = Workspace(uris.from_fs_path(ws_path), Mock())
    ws._config = Config(ws.root_uri, {}, 0, {})
    return ws
Exemple #4
0
def workspace(tmpdir):
    """Return a workspace."""
    ws = Workspace(uris.from_fs_path(str(tmpdir)), Mock())
    ws._config = Config(ws.root_uri, {}, 0, {})
    return ws
Exemple #5
0
def workspace(tmpdir):
    """Return a workspace."""
    return Workspace(uris.from_fs_path(str(tmpdir)))
Exemple #6
0
def workspace():
    """ Return a workspace """
    return Workspace(os.path.dirname(__file__))
Exemple #7
0
def workspace(tmpdir):
    """Return a workspace."""
    rootUri = uris.from_fs_path(str(tmpdir))
    config = Config(rootUri, {})
    return Workspace(rootUri, Mock(), config)
def workspace(tmpdir, config):
    ws = Workspace(uris.from_fs_path(str(tmpdir)), Mock())
    ws._config = config
    return ws