Example #1
0
    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, [])
Example #2
0
 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, [])
Example #3
0
 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, [])
Example #4
0
 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, [])