예제 #1
0
def test_calls_filtered_walk_with_paths_configured(p_filtered_walk: Mock):
    files = types.FilesCollection.from_config({
        'paths': ['path1', 'path2'],
    })

    fs.collect_files(files)

    assert p_filtered_walk.call_count == 2

    args, _ = p_filtered_walk.call_args_list[0]
    expected = (conf.proj_path('path1'), files.whitelist(), files.blacklist())
    assert tuple(args) == expected

    args, _ = p_filtered_walk.call_args_list[1]
    expected = (conf.proj_path('path2'), files.whitelist(), files.blacklist())
    assert tuple(args) == expected
예제 #2
0
def build_template_context(script, options):
    """ Build command template context.

    This will collect all the values like current configuration, command line
    options, runtime context etc. and pass it to the script template.
    """
    template_ctx = {
        'opts':
        dict(verbose=RunContext().get('verbose'),
             pretend=RunContext().get('pretend'),
             **options),
        'script':
        attr.asdict(script),
        'conf':
        conf.as_dict(),
        'ctx':
        RunContext().values,
        'proj_path':
        conf.proj_path,
    }

    if script.files:
        template_ctx['files'] = fs.collect_files(script.files)

    return template_ctx
예제 #3
0
def test_return_empty_list_if_none_of_the_whitelisted_files_are_staged():
    """
    GIVEN files collection has a non-empty whitelist and only_staged == True
     WHEN no staged files match the whitelist
     THEN return empty list.
    """
    files = types.FilesCollection.from_config({
        'paths': ['path1'],
        'include': ['*.py'],
        'only_staged': True,
    })

    assert fs.collect_files(files) == []
예제 #4
0
def test_prints_debug_info_if_verbose_lvl_ge_3(p_cprint):
    # type: (Mock) -> None
    files = types.FilesCollection.from_config({
        'paths': ['path1', 'path2'],
    })

    context.RunContext().set('verbose', 3)
    fs.collect_files(files)
    context.RunContext().set('verbose', 0)

    assert next(
        (True for x in p_cprint.call_args_list if 'only_staged: ' in x[0][0]),
        False)
    assert next(
        (True for x in p_cprint.call_args_list if 'untracked: ' in x[0][0]),
        False)
    assert next(
        (True for x in p_cprint.call_args_list if 'whitelist: ' in x[0][0]),
        False)
    assert next(
        (True for x in p_cprint.call_args_list if 'blacklist: ' in x[0][0]),
        False)
예제 #5
0
def check(paths, include, exclude, only_staged, untracked):
    # type: (str, Sequence[str], Sequence[str], bool, bool) -> None
    """ Run mypy and pylint against the current directory."""

    files = types.FilesCollection(
        paths=paths,
        include=['*.py'] + list(include),  # We only want to lint python files.
        exclude=exclude,
        only_staged=only_staged,
        untracked=untracked,
    )

    paths = fs.collect_files(files)
    wrapped_paths = fs.wrap_paths(paths)

    log.info("Paths:            <33>{}", paths)
    log.info("Wrapped paths:    <33>{}", wrapped_paths)

    log.info("Running <35>mypy")
    shell.run('mypy --ignore-missing-imports {}'.format(wrapped_paths))

    log.info("Running <35>pylint")
    shell.run('pylint {}'.format(wrapped_paths))