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:
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
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])
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))
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)
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])
def test_sequence_types(pkg, value, expected): assert to_yaml(value, pkg=pkg) == expected
def test_unknown_type(pkg): with pytest.raises(Exception): to_yaml(object(), pkg=pkg)
def test_time_types(pkg, value, expected): if pkg == 'ruamel.yaml': expected = expected[1:-1] + "\n..." assert to_yaml(value, pkg=pkg) == expected
def test_dict_types(pkg, value, expected): assert to_yaml(value, pkg=pkg) == expected
def execute(self, collector): issues = self.get_structure(collector) self.output(basicserial.to_yaml(issues, pretty=True))