Revision 76d9365a sdk/python/tests/test_stream.py

View differences:

sdk/python/tests/test_stream.py
26 26
    def test_read_block_crossing_behavior(self):
27 27
        # read() calls will be aligned on block boundaries - see #3663.
28 28
        sfile = self.make_count_reader()
29
        self.assertEqual('123', sfile.read(10))
29
        self.assertEqual(b'123', sfile.read(10))
30 30

  
31 31
    def test_small_read(self):
32 32
        sfile = self.make_count_reader()
33
        self.assertEqual('12', sfile.read(2))
33
        self.assertEqual(b'12', sfile.read(2))
34 34

  
35 35
    def test_successive_reads(self):
36 36
        sfile = self.make_count_reader()
37
        for expect in ['123', '456', '789', '']:
37
        for expect in [b'123', b'456', b'789', b'']:
38 38
            self.assertEqual(expect, sfile.read(10))
39 39

  
40 40
    def test_readfrom_spans_blocks(self):
41 41
        sfile = self.make_count_reader()
42
        self.assertEqual('6789', sfile.readfrom(5, 12))
42
        self.assertEqual(b'6789', sfile.readfrom(5, 12))
43 43

  
44 44
    def test_small_readfrom_spanning_blocks(self):
45 45
        sfile = self.make_count_reader()
46
        self.assertEqual('2345', sfile.readfrom(1, 4))
46
        self.assertEqual(b'2345', sfile.readfrom(1, 4))
47 47

  
48 48
    def test_readall(self):
49 49
        sfile = self.make_count_reader()
50
        self.assertEqual('123456789', ''.join(sfile.readall()))
50
        self.assertEqual(b'123456789', b''.join(sfile.readall()))
51 51

  
52 52
    def test_one_arg_seek(self):
53 53
        self.test_absolute_seek([])
......
55 55
    def test_absolute_seek(self, args=[os.SEEK_SET]):
56 56
        sfile = self.make_count_reader()
57 57
        sfile.seek(6, *args)
58
        self.assertEqual('78', sfile.read(2))
58
        self.assertEqual(b'78', sfile.read(2))
59 59
        sfile.seek(4, *args)
60
        self.assertEqual('56', sfile.read(2))
60
        self.assertEqual(b'56', sfile.read(2))
61 61

  
62 62
    def test_relative_seek(self, args=[os.SEEK_CUR]):
63 63
        sfile = self.make_count_reader()
64
        self.assertEqual('12', sfile.read(2))
64
        self.assertEqual(b'12', sfile.read(2))
65 65
        sfile.seek(2, *args)
66
        self.assertEqual('56', sfile.read(2))
66
        self.assertEqual(b'56', sfile.read(2))
67 67

  
68 68
    def test_end_seek(self):
69 69
        sfile = self.make_count_reader()
70 70
        sfile.seek(-6, os.SEEK_END)
71
        self.assertEqual('45', sfile.read(2))
71
        self.assertEqual(b'45', sfile.read(2))
72 72

  
73 73
    def test_seek_min_zero(self):
74 74
        sfile = self.make_count_reader()
......
101 101
    def test_context(self):
102 102
        with self.make_count_reader() as sfile:
103 103
            self.assertFalse(sfile.closed, "reader is closed inside context")
104
            self.assertEqual('12', sfile.read(2))
104
            self.assertEqual(b'12', sfile.read(2))
105 105
        self.assertTrue(sfile.closed, "reader is open after context")
106 106

  
107 107
    def make_newlines_reader(self):
......
163 163
        self.check_decompressed_name('test.log.bz2', 'test.log')
164 164

  
165 165
    def check_decompression(self, compress_ext, compress_func):
166
        test_text = 'decompression\ntest\n'
166
        test_text = b'decompression\ntest\n'
167 167
        test_data = compress_func(test_text)
168 168
        stream = tutil.MockStreamReader('.', test_data)
169 169
        reader = StreamFileReader(stream, [Range(0, 0, len(test_data))],
170 170
                                  'test.' + compress_ext)
171
        self.assertEqual(test_text, ''.join(reader.readall_decompressed()))
171
        self.assertEqual(test_text, b''.join(reader.readall_decompressed()))
172 172

  
173 173
    @staticmethod
174 174
    def gzip_compress(data):
......
197 197
        reader = self.make_newlines_reader()
198 198
        data = reader.readline()
199 199
        self.assertEqual('one\n', data)
200
        self.assertEqual(''.join(['two\n', '\n', 'three\n', 'four\n', '\n']), ''.join(reader.readall()))
200
        self.assertEqual(b''.join([b'two\n', b'\n', b'three\n', b'four\n', b'\n']), b''.join(reader.readall()))
201 201

  
202 202

  
203 203
class StreamRetryTestMixin(object):
......
291 291

  
292 292
class StreamFileReadAllTestCase(StreamFileReadTestCase):
293 293
    def read_for_test(self, reader, byte_count, **kwargs):
294
        return ''.join(reader.readall(**kwargs))
294
        return b''.join(reader.readall(**kwargs))
295 295

  
296 296

  
297 297
class StreamFileReadAllDecompressedTestCase(StreamFileReadTestCase):
298 298
    def read_for_test(self, reader, byte_count, **kwargs):
299
        return ''.join(reader.readall_decompressed(**kwargs))
299
        return b''.join(reader.readall_decompressed(**kwargs))
300 300

  
301 301

  
302 302
class StreamFileReadlinesTestCase(StreamFileReadTestCase):
303 303
    def read_for_test(self, reader, byte_count, **kwargs):
304
        return ''.join(reader.readlines(**kwargs))
304
        return b''.join(reader.readlines(**kwargs))
305 305

  
306 306
if __name__ == '__main__':
307 307
    unittest.main()

Also available in: Unified diff