Exemplo n.º 1
0
def main():
    ''' Unit test for neubot/utils_random.py '''

    assert (len(RANDOMBLOCKS.get_block()) == RANDOMBLOCKS.blocksiz)
    assert (RANDOMBLOCKS.get_block() != RANDOMBLOCKS.get_block())

    filep, total = RandomBody(RANDOMBLOCKS.blocksiz + 789), 0
    while True:
        block = filep.read(128)
        if not block:
            break
        total += len(block)
    assert (total == RANDOMBLOCKS.blocksiz + 789)

    filep = RandomBody(RANDOMBLOCKS.blocksiz + 789)
    assert (len(filep.read()) == RANDOMBLOCKS.blocksiz)
    assert (filep.tell() == 789)
    assert (len(filep.read()) == 789)
    filep.seek(7)

    begin, total = utils.ticks(), 0
    while total < 1073741824:
        total += len(RANDOMBLOCKS.get_block())
    elapsed = utils.ticks() - begin

    print('Elapsed: %s' % utils.time_formatter(elapsed))
    print('Speed: %s' % utils.speed_formatter(total / elapsed))
Exemplo n.º 2
0
def main():

    ''' Unit test for neubot/utils_random.py '''

    assert(len(RANDOMBLOCKS.get_block()) == RANDOMBLOCKS.blocksiz)
    assert(RANDOMBLOCKS.get_block() != RANDOMBLOCKS.get_block())

    filep, total = RandomBody(RANDOMBLOCKS.blocksiz + 789), 0
    while True:
        block = filep.read(128)
        if not block:
            break
        total += len(block)
    assert(total == RANDOMBLOCKS.blocksiz + 789)

    filep = RandomBody(RANDOMBLOCKS.blocksiz + 789)
    assert(len(filep.read()) == RANDOMBLOCKS.blocksiz)
    assert(filep.tell() == 789)
    assert(len(filep.read()) == 789)
    filep.seek(7)

    begin, total = utils.ticks(), 0
    while total < 1073741824:
        total += len(RANDOMBLOCKS.get_block())
    elapsed = utils.ticks() - begin

    print('Elapsed: %s' % utils.time_formatter(elapsed))
    print('Speed: %s' % utils.speed_formatter(total/elapsed))