Beispiel #1
0
    def test_tell_and_seek_from_end_unbounded_substream(self):
        s = Substream(io.BytesIO(b"0123456789"), 3, None)

        self.assertEqual(0, s.tell())
        self.assertEqual(5, s.seek(-2, io.SEEK_END))
        self.assertEqual(5, s.tell())
        self.assertEqual(b"89", s.read(2))
Beispiel #2
0
    def test_tell_and_seek_from_end(self):
        s = Substream(io.BytesIO(b"0123456789"), 3, 6)

        self.assertEqual(0, s.tell())
        self.assertEqual(2, s.seek(-1, io.SEEK_END))
        self.assertEqual(2, s.tell())
        self.assertEqual(b"5", s.read(2))
Beispiel #3
0
    def test_tell_and_seek_from_cur(self):
        s = Substream(io.BytesIO(b"0123456789"), 3, 6)

        self.assertEqual(0, s.tell())
        self.assertEqual(b"34", s.read(2))
        self.assertEqual(1, s.seek(-1, io.SEEK_CUR))
        self.assertEqual(1, s.tell())
        self.assertEqual(b"45", s.read(2))
Beispiel #4
0
    def test_tell_and_seek_set(self):
        s = Substream(io.BytesIO(b"0123456789"), 3, 6)

        self.assertEqual(0, s.tell())
        self.assertEqual(1, s.seek(1))
        self.assertEqual(b"4", s.read(1))
        self.assertEqual(2, s.tell())
        self.assertEqual(b"5", s.read(2))
        self.assertEqual(b"", s.read(2))
Beispiel #5
0
    def test_tell_and_seek_set_unseekable(self):
        s = Substream(UnseekableStream(io.BytesIO(b"012")), 3, 6)

        self.assertEqual(0, s.tell())
        with self.assertRaises(OSError):
            self.assertEqual(1, s.seek(1))
        self.assertEqual(b"0", s.read(1))
        self.assertEqual(1, s.tell())
        self.assertEqual(b"12", s.read(2))
        self.assertEqual(b"", s.read(2))
Beispiel #6
0
 def test_start_unseekable(self):
     with self.subTest(wrapper=TellableStream):
         with self.assertRaises(OSError):
             Substream(TellableStream(io.BytesIO(b"0123456789")), 3, 6)
     with self.subTest(wrapper=UnseekableStream):
         s = Substream(UnseekableStream(io.BytesIO(b"0123456789")), 3, 6)
         self.assertEqual(3, s.start)
         self.assertEqual(0, s.tell())