Example #1
0
def test_get_hex():
    """ test hex conversion"""
    filename = file1()
    fh = parts.sorfile(filename)
    assert fh != None

    hstr = parts.get_hex(fh, 8)
    assert hstr == "64 00 94 00 00 00 0A 00 "
    fh.close()

    return
Example #2
0
def test_get_string():
    """ test get_string """
    filename = file2()
    fh = parts.sorfile(filename)
    assert fh != None

    mystr = parts.get_string(fh)
    assert mystr == "Map"

    assert fh.tell() == 4
    fh.close()

    return
Example #3
0
def test_get_uint():
    """ test get_unsigned int (2 or 4) """
    filename = file1()
    fh = parts.sorfile(filename)
    assert fh != None

    val = parts.get_uint(fh, nbytes=2)
    assert val == 100
    assert fh.tell() == 2

    val = parts.get_uint(fh, nbytes=4)
    assert val == 148
    assert fh.tell() == 6

    fh.close()

    return
Example #4
0
def test_map():
    filename = cdir + "/../data/demo_ab.sor"
    fh = parts.sorfile(filename)
    assert fh != None
    fh.close()

    status, results, trace = sorparse(filename)

    assert status == "ok"

    # map block
    ref = results["blocks"]
    assert ref["Cksum"]["pos"] == 25706
    assert ref["Cksum"]["version"] == "1.00"

    assert ref["DataPts"]["pos"] == 328
    assert ref["DataPts"]["size"] == 23564

    return
Example #5
0
def _compare_(sor_filename):

    filename = cdir + "/../data/" + sor_filename
    fh = parts.sorfile(filename)
    assert fh != None
    fh.close()

    status, results, tracedata = sorparse(filename)

    assert status == "ok"

    # load and compare JSON file
    fn_strip, ext = os.path.splitext(os.path.basename(filename))
    datafile = fn_strip + "-dump.json"

    jsonfile = cdir + "/../data/" + datafile

    with open(jsonfile) as jsf:
        jold = dict(json.load(jsf))

    jnew = json.dumps(results, sort_keys=True)
    jnew = json.loads(jnew)

    jold = ordered(jold)
    jnew = ordered(jnew)

    assert jold == jnew

    # load and compare trace data
    tfile = fn_strip + "-trace.dat"
    tfile = cdir + "/../data/" + tfile

    with open(tfile) as jsf:
        count = 0
        for line in jsf:
            assert line.strip("\n") == tracedata[count].strip("\n")
            count += 1

    return
Example #6
0
def test_get_signed():
    """ test signed integer conversion"""
    filename = file2()
    fh = parts.sorfile(filename)
    assert fh != None

    fh.seek(461)
    fstr = parts.get_signed(fh, 2)
    assert fstr == 343

    fstr = parts.get_signed(fh, 2)
    assert fstr == 22820

    fstr = parts.get_signed(fh, 4)
    assert fstr == -38395

    fstr = parts.get_signed(fh, 8)
    assert fstr == 6002235321314002225

    fh.close()

    return