示例#1
0
def test_core(kind, expected, capsys):
    data = [['title', 'result'], ['somethingelse', 0.420]]
    with factory.create(kind) as cls:
        for row in data:
            cls.result(*row)

    captured = capsys.readouterr()
    assert captured.out == expected
示例#2
0
def main(parser, args, normalizer=None):
    logging.getLogger()
    prev_title = Logger.title
    Logger.title = 'Reference'
    ref = list(
        file_to_iterable(args.reference,
                         args.reference_type,
                         normalizer=normalizer))
    Logger.title = 'Hypothesis'
    hyp = list(
        file_to_iterable(args.hypothesis,
                         args.hypothesis_type,
                         normalizer=normalizer))
    Logger.title = prev_title

    if 'metrics' not in args or not len(args.metrics):
        parser.error("need at least one metric")

    with output_factory.create(args.output_format) as out:
        for item in args.metrics:
            metric_name = item.pop(0).replace('-', '.')
            cls = factory[metric_name]
            kwargs = dict()

            # somewhat hacky default diff formats for metrics
            sig = signature(cls.__init__).parameters
            sigkeys = list(sig)

            if 'dialect' in sigkeys:
                idx = sigkeys.index('dialect') - 1
                sig = sig['dialect']
                if sig.kind in (Parameter.POSITIONAL_OR_KEYWORD,
                                Parameter.POSITIONAL_ONLY):
                    if len(item) <= idx:
                        if args.output_format == 'json':
                            kwargs['dialect'] = 'list'
                            if 'diff_formatter_dialect' in sigkeys:
                                kwargs['diff_formatter_dialect'] = 'dict'
                        else:
                            kwargs['dialect'] = 'cli'

            metric = cls(*item, **kwargs)
            result = metric.compare(ref, hyp)
            out.result(metric_name, result)
示例#3
0
def test_already_open(cls):
    with pytest.raises(ValueError) as exc:
        with factory.create(cls) as instance:
            with instance as test:
                raise NotImplementedError("Shouldnt get here")
    assert 'Already open' in str(exc)