示例#1
0
def test_load_invalid_yaml(tmpdir):
    # It's surprisingly hard to make invalid yaml!
    _write_config_file(tmpdir.strpath, 'foo: "')

    with assert_raises_with_msg(
            ConfigValidationError,
            REMatcher(
                r'^.pypi-practices-config.yaml: Invalid Yaml:\n\n'
                r'while scanning a quoted scalar\n'
                r'  in ".+\.pypi-practices-config.yaml", line 1, column 6\n'
                r'found unexpected end of stream\n'
                r'  in ".+\.pypi-practices-config.yaml", line 1, column 7'),
    ):
        load_config(tmpdir.strpath)
def test_load_invalid_yaml(tmpdir):
    # It's surprisingly hard to make invalid yaml!
    _write_config_file(tmpdir.strpath, 'foo: "')

    with assert_raises_with_msg(
        ConfigValidationError,
        REMatcher(
            r'^.pypi-practices-config.yaml: Invalid Yaml:\n\n'
            r'while scanning a quoted scalar\n'
            r'  in ".+\.pypi-practices-config.yaml", line 1, column 6\n'
            r'found unexpected end of stream\n'
            r'  in ".+\.pypi-practices-config.yaml", line 1, column 7'
        ),
    ):
        load_config(tmpdir.strpath)
示例#3
0
def test_valid_yaml_invalid_config(tmpdir):
    # autofix is a boolean
    _write_config_file(tmpdir.strpath, 'autofix: herp')

    with assert_raises_with_msg(
            ConfigValidationError,
            REMatcher(
                r"^.pypi-practices-config.yaml: File does not satisfy schema:\n\n"
                r"'herp' is not of type u?'boolean'\n\n"
                r"Failed validating u?'type' "
                r"in schema\[u?'properties'\]\[u?'autofix'\]:\n"
                r"    {u?'type': u?'boolean'}\n\n"
                r"On instance\[u?'autofix'\]:\n"
                r"    'herp'")):
        load_config(tmpdir.strpath)
示例#4
0
    def entry(argv=None):
        if argv is None:
            argv = sys.argv[1:]

        parser = argparse.ArgumentParser()
        parser.add_argument(
            '--cwd',
            default='.',
            help='Current working directory to find files at.',
        )
        parser.add_argument(
            '--fix',
            default=False,
            action='store_true',
            help='Attempt auto-fixing of rule.',
        )
        parser.add_argument(
            'filenames',
            nargs='*',
            help='(Ignored) for compatibility with pre-commit.',
        )
        args = parser.parse_args(argv)

        cwd = args.cwd
        if type(cwd) is bytes:  # pragma: no cover (PY2 only)
            cwd = cwd.decode('utf-8')

        try:
            config = load_config(cwd)
            fix = args.fix or config.get('autofix', True)
            return check_fn(cwd, fix, config)
        except ValidationError as e:
            print(five.text(e))
            return 1
def test_valid_yaml_invalid_config(tmpdir):
    # autofix is a boolean
    _write_config_file(tmpdir.strpath, 'autofix: herp')

    with assert_raises_with_msg(
        ConfigValidationError,
        REMatcher(
            r"^.pypi-practices-config.yaml: File does not satisfy schema:\n\n"
            r"'herp' is not of type u?'boolean'\n\n"
            r"Failed validating u?'type' "
            r"in schema\[u?'properties'\]\[u?'autofix'\]:\n"
            r"    {u?'type': u?'boolean'}\n\n"
            r"On instance\[u?'autofix'\]:\n"
            r"    'herp'"
        )
    ):
        load_config(tmpdir.strpath)
示例#6
0
def test_load_trivial_config(tmpdir):
    _write_config_file(
        tmpdir.strpath, 'autofix: true\n'
        'github_user: asottile\n'
        'package_name: pypi_practices\n')

    assert load_config(tmpdir.strpath) == {
        'autofix': True,
        'github_user': '******',
        'package_name': 'pypi_practices',
    }
def test_load_trivial_config(tmpdir):
    _write_config_file(
        tmpdir.strpath,
        'autofix: true\n'
        'github_user: asottile\n'
        'package_name: pypi_practices\n'
    )

    assert load_config(tmpdir.strpath) == {
        'autofix': True,
        'github_user': '******',
        'package_name': 'pypi_practices',
    }
def test_load_config_returns_empty_dict_non_existing(tmpdir):
    ret = load_config(tmpdir.strpath)
    assert ret == {}
示例#9
0
def test_load_config_returns_empty_dict_non_existing(tmpdir):
    ret = load_config(tmpdir.strpath)
    assert ret == {}