示例#1
0
def test_execute_tools(capsys):
    cfg = get_default_config()
    cfg['pycodestyle']['use'] = False

    expected_tools = sorted(get_tools())
    expected_tools.remove('pycodestyle')

    progress = QuietProgress()
    collector = execute_tools(cfg, 'test/project1', progress=progress)
    assert isinstance(collector, Collector)
    assert [] == sorted(progress.current_tools)
    assert expected_tools == sorted(progress.completed_tools)

    out, err = capsys.readouterr()
    assert out == ''
    assert err == ''

    for tool in get_tools():
        cfg[tool]['use'] = False

    progress = QuietProgress()
    collector = execute_tools(cfg, 'test/project1', progress=progress)
    assert isinstance(collector, Collector)
    assert [] == sorted(progress.current_tools)
    assert [] == sorted(progress.completed_tools)
    assert collector.issue_count() == 0
    assert collector.issue_count(include_unclean=True) == 0

    out, err = capsys.readouterr()
    assert out == ''
    assert err == ''
示例#2
0
def test_get_tools():
    expected = sorted([
        'bandit',
        'dlint',
        'eradicate',
        'jsonlint',
        'manifest',
        'polint',
        'pycodestyle',
        'pydiatra',
        'pydocstyle',
        'pyflakes',
        'pylint',
        'pyroma',
        'mccabe',
        'rstlint',
        'secrets',
        'vulture',
        'yamllint',
    ])

    actual = get_tools()
    assert expected == sorted(actual.keys())

    actual2 = get_tools()
    assert expected == sorted(actual2.keys())
    assert id(actual) == id(actual2)
示例#3
0
def test_console_progress(capsys):
    cfg = get_default_config()
    for tool in get_tools():
        cfg[tool]['use'] = tool in ('pylint', 'pycodestyle')

    progress = ConsoleProgress(cfg)
    progress.on_start()

    progress.on_tool_start('pylint')
    assert progress.current_tools == ['pylint']
    assert progress.completed_tools == []
    assert progress.currently_executing == '[pylint]'

    progress.on_tool_start('pycodestyle')
    assert progress.current_tools == ['pylint', 'pycodestyle']
    assert progress.completed_tools == []
    assert progress.currently_executing == '[pylint, pycodestyle]'

    progress.on_tool_finish('pycodestyle')
    progress.on_tool_finish('pycodestyle')
    assert progress.current_tools == ['pylint']
    assert progress.completed_tools == ['pycodestyle']
    assert progress.currently_executing == '[pylint]'

    progress.on_tool_finish('pylint')
    assert progress.current_tools == []
    assert progress.completed_tools == ['pycodestyle', 'pylint']
    assert progress.currently_executing == ''

    progress.on_finish()
示例#4
0
def test_quiet_progress(capsys):
    cfg = get_default_config()
    for tool in get_tools():
        cfg[tool]['use'] = tool in ('pylint', 'pycodestyle')

    progress = QuietProgress()
    progress.on_start()

    progress.on_tool_start('pylint')
    assert progress.current_tools == ['pylint']
    assert progress.completed_tools == []

    progress.on_tool_start('pycodestyle')
    assert progress.current_tools == ['pylint', 'pycodestyle']
    assert progress.completed_tools == []

    progress.on_tool_finish('pycodestyle')
    assert progress.current_tools == ['pylint']
    assert progress.completed_tools == ['pycodestyle']

    progress.on_tool_finish('pylint')
    assert progress.current_tools == []
    assert progress.completed_tools == ['pycodestyle', 'pylint']

    progress.on_finish()
    out, err = capsys.readouterr()
    assert out == ''
    assert err == ''
示例#5
0
def test_get_default_config():
    actual = get_default_config()
    assert actual['exclude'] == []
    assert actual['merge-issues'] == True
    assert isinstance(actual['workers'], int)
    assert actual['workers'] >= 1
    assert actual['workers'] <= 4
    assert actual['disabled'] == []
    assert actual['noqa'] == True
    assert actual['extends'] == []
    assert actual['ignore-missing-extends'] == False

    for tool in get_tools().keys():
        assert tool in actual