예제 #1
0
def data_log_multiblock():
    # create a 43 bytes record
    record = conftest.to_bytes("""
    1b cc 27 c2 24 00 01
    01 00 00 00 00 00 00 00 01 00 00 00 01
    09 '"coolkey!"' 09 'coolvalue!!'
    """)

    #43 * 762 == 32766: add 2 padding bytes before next block begins
    return (record * 762 + conftest.to_bytes('00 00') + record * 3)
예제 #2
0
def data_ok1():
    tinydb_ok1 = """
00  00 00 00 05 "color"         00 00 00 03 "red"
00  00 00 00 04 "size"          00 00 00 08 "two feet"
00  00 00 00 0B "description"   00 00 00 1C "A nice dwarf with a long axe"
"""

    return conftest.to_bytes(tinydb_ok1)
예제 #3
0
def data_log_small():
    # Log file generated by the "level" CLI tool after putting two
    # key/value pairs
    return conftest.to_bytes("""
    1b cc 27 c2 21 00 01
    01 00 00 00 00 00 00 00 01 00 00 00 01
    09 '"coolkey"' 09 'coolvalue'
    95 c4 c2 6e 27 00 01 02
    00 00 00 00 00 00 00 01  00 00 00 01
    0c '"coolnewkey"' 0c 'coolnewvalue'
    """)
예제 #4
0
def test_span_lazy_eval_error():
    data = conftest.to_bytes(data_span_lazy_eval_error)
    board = model.Board()
    board.add_data_source('data', data)
    board.add_spec('Spec', spec_span_lazy_eval)
    board.add_expr('dtree', 'data <> Spec.Schema')

    # lazy span size evaluation should allow accessing fields that do
    # not depend on the entry size, even if the entry size is
    # incorrect (formatted size is "foo")
    assert board.eval_expr('dtree.entries[0].header.magic') == 'magic'
    with pytest.raises(model.DataError):
        print board.eval_expr('dtree.entries[0].header.size')
    assert board.eval_expr('^dtree.entries[0].header.size') == 'foo'
예제 #5
0
def test_user_filter_extern_use_spec():
    board = model.Board()
    board.add_data_source('data',
                          conftest.to_bytes(data_file_user_filter_extern))
    board.use_spec(spec_file_user_filter_extern)
    board.register_filter('godify', Godify)

    dtree = board.eval_expr('data <> Schema')
    print model.make_python_object(dtree.eval_expr('contents'))
    assert model.make_python_object(
        dtree.eval_expr('contents')) == \
        ["Do as she wants",
         "Do as He wants",
         "Do as thou want"]
예제 #6
0
def make_testcase(param):
    update_test_file(param['file_data'])

    board = model.Board()
    board.add_spec('Spec', param['spec'])
    if 'data' in param:
        # data is provided externally to the spec (other data sources
        # may be defined in the spec but not top-level)
        data = conftest.to_bytes(param['data'])
        board.add_data_source('data', data)
        param['dtree'] = board.eval_expr('data <> Spec.Schema')
        param['data'] = data
    else:
        # data is defined in the spec as "data" item
        param['dtree'] = board.eval_expr('Spec.data')

    if 'BITPUNCH_TEST_ENABLE_CLI' in os.environ:
        cli = CLI()
        cli.attach_data_tree(param['dtree'])
        cli.cmdloop()

    return param
예제 #7
0
def data_log_empty():
    return conftest.to_bytes("""
    """)