示例#1
0
def test_pretty(pkg):
    assert to_yaml([1, 2, 3], pretty=True, pkg=pkg) == """- 1
- 2
- 3"""

    assert to_yaml({
        'foo': 'bar',
        'baz': [1, 2]
    }, pretty=True, pkg=pkg) == """baz:
示例#2
0
def test_set_types(pkg):
    out = to_yaml(set([123, 'foo', True]), pkg=pkg)
    assert out.startswith('[')
    assert out.endswith(']')
    assert '123' in out
    assert 'true' in out
    assert 'foo' in out

    out = to_yaml(frozenset([123, 'foo', True]), pkg=pkg)
    assert out.startswith('[')
    assert out.endswith(']')
    assert '123' in out
    assert 'true' in out
    assert 'foo' in out
示例#3
0
def extensions(fmt):
    ext = OrderedDict()

    ext['tools'] = OrderedDict()
    for name, tool in sorted(get_tools().items()):
        ext['tools'][name] = getdoc(tool)

    ext['reports'] = OrderedDict()
    for name, report in sorted(get_reports().items()):
        ext['reports'][name] = getdoc(report)

    ext['extenders'] = OrderedDict()
    for name, extender in sorted(get_extenders().items()):
        ext['extenders'][name] = getdoc(extender)

    if fmt == 'toml':
        click.echo(basicserial.to_toml(ext, pretty=True))
    elif fmt == 'json':
        click.echo(basicserial.to_json(ext, pretty=True))
    elif fmt == 'yaml':
        click.echo(basicserial.to_yaml(ext, pretty=True))
    elif fmt == 'csv':
        writer = csv.writer(click.get_text_stream('stdout'))
        writer.writerow(['type', 'name', 'description'])
        for type_ in ext:
            for name, description in ext[type_].items():
                writer.writerow([type_, name, description])
示例#4
0
    def make_config(self):
        cfg = {
            'extends': 'default',
            'rules': {},
        }

        rules = [rule for rule, _ in self.get_all_codes() if rule != 'syntax']
        for rule in rules:
            if rule in self.config['disabled']:
                cfg['rules'][rule] = 'disable'
            elif rule in self.config['options']:
                cfg['rules'][rule] = self.config['options'][rule]

        return YamlLintConfig(basicserial.to_yaml(cfg))
示例#5
0
    def make_config(self):
        cfg = 'extends: default\n'

        rules = [rule for rule, _ in self.get_all_codes() if rule != 'syntax']
        rule_parts = []
        for rule in rules:
            if rule in self.config['disabled']:
                rule_parts.append('  %s: disable' % (rule, ))
            elif rule in self.config['options']:
                rule_parts.append('  %s: %s' % (
                    rule,
                    basicserial.to_yaml(self.config['options'][rule]),
                ))

        if rule_parts:
            cfg += 'rules:\n%s' % ('\n'.join(rule_parts), )

        return YamlLintConfig(cfg)
示例#6
0
def list_codes(tools, fmt):
    all_tools = get_tools()
    tools = tools or sorted(all_tools.keys())
    codes = OrderedDict()

    for tool in tools:
        codes[tool] = dict(all_tools[tool].get_all_codes())

    if fmt == 'toml':
        click.echo(basicserial.to_toml(codes, pretty=True))
    elif fmt == 'json':
        click.echo(basicserial.to_json(codes, pretty=True))
    elif fmt == 'yaml':
        click.echo(basicserial.to_yaml(codes, pretty=True))
    elif fmt == 'csv':
        writer = csv.writer(click.get_text_stream('stdout'))
        writer.writerow(['tool', 'code', 'message'])
        for tool in codes:
            for code, message in codes[tool].items():
                writer.writerow([tool, code, message])
示例#7
0
def test_sequence_types(pkg, value, expected):
    assert to_yaml(value, pkg=pkg) == expected
示例#8
0
def test_unknown_type(pkg):
    with pytest.raises(Exception):
        to_yaml(object(), pkg=pkg)
示例#9
0
def test_time_types(pkg, value, expected):
    if pkg == 'ruamel.yaml':
        expected = expected[1:-1] + "\n..."
    assert to_yaml(value, pkg=pkg) == expected
示例#10
0
def test_dict_types(pkg, value, expected):
    assert to_yaml(value, pkg=pkg) == expected
示例#11
0
 def execute(self, collector):
     issues = self.get_structure(collector)
     self.output(basicserial.to_yaml(issues, pretty=True))