Example #1
0
def test(ts_mode, val_mode, scale, results):
    test_name = ts_mode + "_" + val_mode + "_" + scale
    filepath = "tmp/" + test_name + ".pkd.bin"
    outfile = "tmp/" + test_name + ".out"
    infile = "tmp/" + test_name + ".bin"

    N = scales[scale]
    ts = timestamp_modes[ts_mode](N)
    vals = value_modes[val_mode](N)
    d = datagen.serialize(ts, vals)

    print "Test case: " + test_name

    with open(infile, 'w') as f:
        f.write(d)

    avg_pack_time = testPack(filepath, infile)
    avg_unpack_time = testUnpack(filepath, outfile)

    with open(infile, 'r') as f:
        indata = f.read()
    with open(outfile, 'r') as f:
        output = f.read()

    if output == indata:
        print "\t" * 4 + "... CORRECT"
        filesize = os.stat(filepath).st_size
        performance = printReport(avg_pack_time, avg_unpack_time, N, len(d),
                                  filesize)
    else:
        print "\t" * 4 + "... INCORRECT"
        performance = (False, 0, 0, 0)

    results[test_name] = performance
Example #2
0
def test_pack(ts, vals, name):
    test_name = "test_"+name;
    filepath = "tmp/"+test_name+".pkd.bin"

    d = datagen.serialize(ts,vals)
    pack(d, filepath)
    output = unpack(filepath)

    assert output == d, test_name + " failed"
Example #3
0
def test_stream_in_out():
    test_name = "test_stream_in_out"

    ts = datagen.gen_random_ints(100)
    vals = datagen.gen_random_ints(100)
    d = datagen.serialize(ts,vals)

    filepath = "tmp/"+test_name+".pkd.bin"

    pack(d, filepath)
    output = unpack(filepath)

    assert output == d, test_name + " failed"
Example #4
0
def test_file_output():
    test_name = "test_file_output"

    ts = datagen.gen_random_ints(100)
    vals = datagen.gen_random_ints(100)
    d = datagen.serialize(ts,vals)

    filepath = "tmp/"+test_name+".pkd.bin"
    outfile= "tmp/"+test_name+".out"

    pack(d, filepath)
    unpackToFile(filepath, outfile)

    with open(outfile) as f:
        output = f.read()

    assert output == d, test_name + " failed"
Example #5
0
def test_file_input():
    test_name = "test_file_input"

    ts = datagen.gen_random_ints(100)
    vals = datagen.gen_random_ints(100)
    d = datagen.serialize(ts,vals)


    infile = "tmp/"+test_name+".bin"
    filepath = "tmp/"+test_name+".pkd.bin"

    with open(infile,'w') as f:
        f.write(d)

    packFromFile(infile, filepath)
    output = unpack(filepath)

    with open(infile,'r') as f:
        dfile = f.read()

    assert output == dfile, test_name + " failed"