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
Beispiel #2
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)
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_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
Beispiel #5
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_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
Beispiel #7
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()
Beispiel #8
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