def test_type_inference_success(input, expected):
    set_cache_class(InMemoryCache)
    with open(input) as f:
        termA = Dhall.p_parse(f.read())
    with open(expected) as f:
        termB = Dhall.p_parse(f.read())

    assert termA.resolve(input).type().quote() == termB
Exemple #2
0
def test_bnorm(input, expected):
    set_cache_class(InMemoryCache)
    with open(input) as f:
        termA = Dhall.p_parse(f.read())
    with open(expected) as f:
        termB = Dhall.p_parse(f.read())

    assert termA.resolve(input).eval().quote() == termB.resolve(
        expected).eval().quote()
def test_alpha_normalization_unit(input, expected):
    set_cache_class(InMemoryCache)
    with open(input) as f:
        termA = Dhall.p_parse(f.read())
    with open(expected) as f:
        termB = Dhall.p_parse(f.read())

    termA = termA.eval().quote(normalize=True)
    assert termA == termB
def test_import(input, expected):
    set_cache_class(TestFSCache)
    try:
        print(input)
        with open(input) as f:
            termA = Dhall.p_parse(f.read())
        with open(expected) as f:
            termB = Dhall.p_parse(f.read())

        term = termA.resolve(LocalFile(input, None, 0)).eval().quote()
        assert term == termB
    finally:
        import_.CACHE.reset()
def test_bin_decode(input, expected):
    set_cache_class(InMemoryCache)
    with open(input, "rb") as f:
        binA = f.read()
    with open(expected) as f:
        termB = Dhall.p_parse(f.read())

    termA = Term.from_cbor(binA)
    assert termA == termB
def test_type_inference_failure(input):
    set_cache_class(InMemoryCache)
    with open(input) as f:
        with pytest.raises(Exception) as info:
            term = Dhall.p_parse(f.read())
            term.resolve(input).type()
        if info.type not in (DhallTypeError, ParserError):
            print(info.traceback)
            assert False, info.value
def test_parse_failure(input):
    set_cache_class(InMemoryCache)
    with open(input) as f:
        try:
            src = f.read()
        except UnicodeDecodeError:
            return
        with pytest.raises(ParserError) as exc:
            term = Dhall.p_parse(src)
Exemple #8
0
def hash(args):
    if not args.file:
        src = sys.stdin.read()
        module = Dhall.p_parse(src)
        origin = LocalFile(Path(os.getcwd()).joinpath("<stdin>"), None, 0)
    else:
        with open(args.file) as f:
            src = f.read()
        origin = LocalFile(Path(args.file), None, 0)
    module = Dhall.p_parse(src)
    module = module.resolve(origin)
    try:
        module.type()
    except DhallTypeError as e:
        raise
        sys.stderr.write("Error: ")
        sys.stderr.write(str(e))
        sys.stderr.write("\n")
        sys.exit(1)
    print(module.eval().quote(normalize=True).sha256())
Exemple #9
0
def benchit(src, filename):
    NUMBER = 1
    REPEAT = 5
    gc.collect()
    total_seconds = min(repeat(lambda: Dhall.p_parse(src),
                               lambda: gc.enable(),
                               repeat=REPEAT,
                               number=NUMBER))
    seconds_each = total_seconds / NUMBER

    kb = len(src) / 1024.0

    print('%s: Took %.3fs to parse %.1fKB: %.0fKB/s' % (
        filename, seconds_each, kb, kb / seconds_each))
    return seconds_each
Exemple #10
0
def normalize(args):
    if not args.file:
        src = sys.stdin.read()
        module = Dhall.p_parse(src)
    else:
        with open(src) as f:
            src = f.read()
    try:
        module.type()
    except DhallTypeError as e:
        raise
        sys.stderr.write("Error: ")
        sys.stderr.write(str(e))
        sys.stderr.write("\n")
        sys.exit(1)
    print(module.eval().quote(normalize=True).dhall())
def test_parse_success(input, expected):
    set_cache_class(InMemoryCache)
    with open(input) as f:
        termA = Dhall.p_parse(f.read())
    with open(expected, "rb") as f:
        assert isinstance(termA, Term)
        bin = termA.cbor()
        termB_bin = f.read()
        try:
            assert termA.cbor() == termB_bin
        except AssertionError:
            # print("")
            # print(input)
            # print(repr(termA))
            # print(termA.cbor_values())
            # with open(str(expected).replace(".dhallb", ".diag")) as f:
            #     print(f.read())
            raise
def test_integer_lit(input, expected):
    assert Dhall.p_parse(input) == expected
Exemple #13
0
def _(input, expected):
    "dhall-lang/tests/parser/success/largeExpressionA.dhall"
    with open(input) as f:
        termA = Dhall.p_parse(f.read())
Exemple #14
0
def test_if(input, expected):
    assert Dhall.p_parse(input).eval() == expected
def test_universe(input, expected):
    assert Dhall.p_parse(input) == expected
Exemple #16
0
def test_bool(input, expected):
    assert Dhall.p_parse(input).type() == expected
def test_non_empty_list(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected
def test_record_complete(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected
def test_operator_expr(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected
def test_lambda_expr(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected
def test_bool_lit(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected
def test_bindings(input, expected):
    assert Dhall.p_parse(input) == expected
Exemple #23
0
def loads(s):
    result = Dhall.p_parse(s)
    result.type()
    return result
def test_double_lit(input, expected):
    assert Dhall.p_parse(input) == expected
def test_natural(input, expected):
    assert Dhall.p_parse(input) == expected