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
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.º 3
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()
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 test_line_comment():
    p = Dhall("-- hello\nlet foo = 1 in foo")
    result = p.LineComment()
    assert result == LineComment(" hello")
    p = Dhall("--\nlet foo = 1 in foo")
    result = p.LineComment()
    assert result == LineComment("")
Exemplo n.º 10
0
def test_var():
    p = Dhall("myvar")
    result = p.Variable()
    assert result == Var("myvar", 0)
    p = Dhall("_@2")
    result = p.Variable()
    assert result == Var("_", 2)
Exemplo n.º 11
0
def test_url():
    p = Dhall("http://example.com/")
    result = p.HttpRaw()
    assert result == urlparse("http://example.com/")
    p = Dhall("https://*****:*****@example.com/package.dhall?stuff=21&b=32")
    result = p.HttpRaw()
    assert result == urlparse(
        "https://*****:*****@example.com/package.dhall?stuff=21&b=32")
Exemplo n.º 12
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.º 13
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.º 14
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.º 15
0
def test_if(input, expected):
    assert Dhall.p_parse(input).eval() == expected
Exemplo n.º 16
0
def test_integer_lit(input, expected):
    assert Dhall.p_parse(input) == expected
Exemplo n.º 17
0
def test_double_quote_text():
    p = Dhall('"a string"')
    result = p.DoubleQuoteLiteral()
    assert result == TextLit(chunks=[], suffix='a string')
Exemplo n.º 18
0
def test_bindings(input, expected):
    assert Dhall.p_parse(input) == expected
Exemplo n.º 19
0
def test_label_fail(input):
    p = Dhall(input)
    result = p.Label()
    assert result is p.NoMatch
Exemplo n.º 20
0
def test_label(input, expected):
    p = Dhall(input)
    result = p.Label()
    assert p.p_flatten(result) == expected
Exemplo n.º 21
0
def test_non_empty_list(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected
Exemplo n.º 22
0
def test_block_comment():
    p = Dhall("{- hop -}")
    result = p.BlockComment()
    assert result == BlockComment("{- hop -}")
Exemplo n.º 23
0
def test_looong_comment():
    "Long comments used to fail on recursion error"
    cmt = "{-" + (" " * 5000) + "-}"
    p = Dhall(cmt)
    result = p.BlockComment()
    assert result == BlockComment(cmt)
Exemplo n.º 24
0
def test_bool_lit(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected
Exemplo n.º 25
0
def test_pydhall_schema():
    p = Dhall("pydhall+schema:my.module::MyClass")
    result = p.PydhallSchema()
    assert result[1] == "my.module"
    assert result[2] == "MyClass"
Exemplo n.º 26
0
def test_char_classes():
    p = Dhall("Ā1")
    result = p.ValidNonAscii()
    assert result == "Ā"
Exemplo n.º 27
0
def test_operator_expr(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected
Exemplo n.º 28
0
def test_universe(input, expected):
    assert Dhall.p_parse(input) == expected
Exemplo n.º 29
0
def test_record_complete(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected
Exemplo n.º 30
0
def test_lambda_expr(input, expected):
    result = Dhall.p_parse(input)
    assert result == expected