Beispiel #1
0
def test_cursor():
    bits = BitStream("01001101")
    assert bits.tell() == 0
    bits.seek(1, os.SEEK_END)
    assert bits.bits_available == 1
    assert bits.read_bit() == 1
    py.test.raises(IndexError, bits.read_bit)

    bits.seek(0)
    assert bits.bits_available == 8

    result = bits.read_bit()
    assert result == 0

    result = bits.read_bits(2)
    assert result == [True, False]

    bits.seek(1, os.SEEK_CUR)
    assert bits.bits_available == 4
    assert bits.read_bits(2) == [True, True]

    bits.seek(1, os.SEEK_END)
    assert bits.bits_available == 0

    bits.seek(0)
    result = bits.read_bits(8)
    assert str(result) == str(bits)
Beispiel #2
0
def test_skip_flush():
    bits = BitStream("111")
    bits.seek(0)
    bits.skip_flush()
    assert str(bits) == "111"
    assert bits.bits_available == 3

    bits.seek(0, os.SEEK_END)
    bits.skip_flush()
    assert str(bits) == "111"
    assert bits.bits_available == 0

    bits = BitStream("11110000 111")
    bits.skip_flush()
    assert bits.tell() == 0
    assert bits.bits_available == 11

    bits.seek(1, os.SEEK_CUR)
    bits.skip_flush()
    assert bits.tell() == 8
    assert bits.bits_available == 3

    bits.skip_flush()
    assert bits.tell() == 8
    assert bits.bits_available == 3

    bits = BitStream("11110000 11100011 101")
    bits.skip_flush()
    assert bits.tell() == 0
    assert bits.bits_available == 19

    bits.seek(1, os.SEEK_CUR)
    bits.cursor += 1
    bits.skip_flush()
    assert bits.tell() == 8
    assert bits.bits_available == 11

    bits.skip_flush()
    assert bits.tell() == 8
    assert bits.bits_available == 11

    bits.seek(1, os.SEEK_CUR)
    bits.skip_flush()
    assert bits.tell() == 16
    assert bits.bits_available == 3