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
Exemplo n.º 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
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
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
Exemplo n.º 7
0
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)
Exemplo n.º 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())
Exemplo n.º 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
Exemplo n.º 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())
Exemplo n.º 11
0
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
Exemplo n.º 12
0
def test_integer_lit(input, expected):
    assert Dhall.p_parse(input) == expected
Exemplo n.º 13
0
def _(input, expected):
    "dhall-lang/tests/parser/success/largeExpressionA.dhall"
    with open(input) as f:
        termA = Dhall.p_parse(f.read())
Exemplo n.º 14
0
def test_if(input, expected):
    assert Dhall.p_parse(input).eval() == expected
Exemplo n.º 15
0
def test_universe(input, expected):
    assert Dhall.p_parse(input) == expected
Exemplo n.º 16
0
def test_bool(input, expected):
    assert Dhall.p_parse(input).type() == expected
Exemplo n.º 17
0
def test_non_empty_list(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected
Exemplo n.º 18
0
def test_record_complete(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected
Exemplo n.º 19
0
def test_operator_expr(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected
Exemplo n.º 20
0
def test_lambda_expr(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected
Exemplo n.º 21
0
def test_bool_lit(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected
Exemplo n.º 22
0
def test_bindings(input, expected):
    assert Dhall.p_parse(input) == expected
Exemplo n.º 23
0
def loads(s):
    result = Dhall.p_parse(s)
    result.type()
    return result
Exemplo n.º 24
0
def test_double_lit(input, expected):
    assert Dhall.p_parse(input) == expected
Exemplo n.º 25
0
def test_natural(input, expected):
    assert Dhall.p_parse(input) == expected