def test_seek(self): base = TReader(self.packets) filter = streamio.TextInputFilter(base) def f(): sofar = "" pairs = [] while True: pairs.append((sofar, filter.tell())) c = filter.read(1) if not c: break assert len(c) == 1 sofar += c all = sofar for i in range(len(pairs)): sofar, pos = pairs[i] filter.seek(pos, 0) assert filter.tell() == pos assert filter.tell() == pos bufs = [sofar] while True: data = filter.read(100) if not data: assert filter.read(100) == "" break bufs.append(data) assert "".join(bufs) == all self.interpret(f, [])
def test_read(self): base = TReader(self.packets) filter = streamio.TextInputFilter(base) def f(): for data, pos in self.expected: assert filter.read(100) == data self.interpret(f, [])
def test_newlines_attribute(self): for packets, expected in self.expected_newlines: base = TReader(packets) filter = streamio.TextInputFilter(base) def f(): for e in expected: filter.read(100) assert filter.getnewlines() == e self.interpret(f, [])
def test_read_tell(self): base = TReader(self.packets) filter = streamio.TextInputFilter(base) def f(): for data, pos in self.expected_with_tell: assert filter.read(100) == data assert filter.tell() == pos assert filter.tell() == pos # Repeat the tell() ! self.interpret(f, [])