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

View differences:

sdk/python/tests/test_arvfile.py
68 68

  
69 69

  
70 70
    def test_truncate(self):
71
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": "0123456789"})
72
        api = ArvadosFileWriterTestCase.MockApi({"name":"test_truncate",
73
                                                 "manifest_text":". 781e5e245d69b566979b86e28d23f2c7+10 0:8:count.txt\n",
74
                                                 "replication_desired":None},
75
                                                {"uuid":"zzzzz-4zz18-mockcollection0",
76
                                                 "manifest_text":". 781e5e245d69b566979b86e28d23f2c7+10 0:8:count.txt\n",
77
                                                 "portable_data_hash":"7fcd0eaac3aad4c31a6a0e756475da92+52"})
71
        keep = ArvadosFileWriterTestCase.MockKeep({
72
            "781e5e245d69b566979b86e28d23f2c7+10": b"0123456789",
73
        })
74
        api = ArvadosFileWriterTestCase.MockApi({
75
            "name": "test_truncate",
76
            "manifest_text": ". 781e5e245d69b566979b86e28d23f2c7+10 0:8:count.txt\n",
77
            "replication_desired": None,
78
        }, {
79
            "uuid": "zzzzz-4zz18-mockcollection0",
80
            "manifest_text": ". 781e5e245d69b566979b86e28d23f2c7+10 0:8:count.txt\n",
81
            "portable_data_hash":"7fcd0eaac3aad4c31a6a0e756475da92+52",
82
        })
78 83
        with Collection('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt\n',
79 84
                             api_client=api, keep_client=keep) as c:
80 85
            writer = c.open("count.txt", "r+")
81 86
            self.assertEqual(writer.size(), 10)
82
            self.assertEqual("0123456789", writer.read(12))
87
            self.assertEqual(b"0123456789", writer.read(12))
83 88

  
84 89
            writer.truncate(8)
85 90

  
86 91
            # Make sure reading off the end doesn't break
87
            self.assertEqual("", writer.read(12))
92
            self.assertEqual(b"", writer.read(12))
88 93

  
89 94
            self.assertEqual(writer.size(), 8)
90 95
            writer.seek(0, os.SEEK_SET)
91
            self.assertEqual("01234567", writer.read(12))
96
            self.assertEqual(b"01234567", writer.read(12))
92 97

  
93 98
            self.assertIsNone(c.manifest_locator())
94 99
            self.assertTrue(c.modified())
......
97 102
            self.assertFalse(c.modified())
98 103

  
99 104
    def test_write_to_end(self):
100
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": "0123456789"})
101
        api = ArvadosFileWriterTestCase.MockApi({"name":"test_append",
102
                                                 "manifest_text": ". 781e5e245d69b566979b86e28d23f2c7+10 acbd18db4cc2f85cedef654fccc4a4d8+3 0:13:count.txt\n",
103
                                                 "replication_desired":None},
104
                                                {"uuid":"zzzzz-4zz18-mockcollection0",
105
                                                 "manifest_text": ". 781e5e245d69b566979b86e28d23f2c7+10 acbd18db4cc2f85cedef654fccc4a4d8+3 0:13:count.txt\n",
106
                                                 "portable_data_hash":"c5c3af76565c8efb6a806546bcf073f3+88"})
105
        keep = ArvadosFileWriterTestCase.MockKeep({
106
            "781e5e245d69b566979b86e28d23f2c7+10": b"0123456789",
107
        })
108
        api = ArvadosFileWriterTestCase.MockApi({
109
            "name": "test_append",
110
            "manifest_text": ". 781e5e245d69b566979b86e28d23f2c7+10 acbd18db4cc2f85cedef654fccc4a4d8+3 0:13:count.txt\n",
111
            "replication_desired": None,
112
        }, {
113
            "uuid": "zzzzz-4zz18-mockcollection0",
114
            "manifest_text": ". 781e5e245d69b566979b86e28d23f2c7+10 acbd18db4cc2f85cedef654fccc4a4d8+3 0:13:count.txt\n",
115
            "portable_data_hash": "c5c3af76565c8efb6a806546bcf073f3+88",
116
        })
107 117
        with Collection('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt\n',
108 118
                             api_client=api, keep_client=keep) as c:
109 119
            writer = c.open("count.txt", "r+")
110 120
            self.assertEqual(writer.size(), 10)
111 121

  
112 122
            writer.seek(5, os.SEEK_SET)
113
            self.assertEqual("56789", writer.read(8))
123
            self.assertEqual(b"56789", writer.read(8))
114 124

  
115 125
            writer.seek(10, os.SEEK_SET)
116 126
            writer.write("foo")
117 127
            self.assertEqual(writer.size(), 13)
118 128

  
119 129
            writer.seek(5, os.SEEK_SET)
120
            self.assertEqual("56789foo", writer.read(8))
130
            self.assertEqual(b"56789foo", writer.read(8))
121 131

  
122 132
            self.assertIsNone(c.manifest_locator())
123 133
            self.assertTrue(c.modified())
......
126 136
            c.save_new("test_append")
127 137
            self.assertEqual("zzzzz-4zz18-mockcollection0", c.manifest_locator())
128 138
            self.assertFalse(c.modified())
129
            self.assertEqual("foo", keep.get("acbd18db4cc2f85cedef654fccc4a4d8+3"))
139
            self.assertEqual(b"foo", keep.get("acbd18db4cc2f85cedef654fccc4a4d8+3"))
130 140

  
131 141

  
132 142
    def test_append(self):
133
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": "0123456789"})
143
        keep = ArvadosFileWriterTestCase.MockKeep({
144
            "781e5e245d69b566979b86e28d23f2c7+10": b"0123456789",
145
        })
134 146
        c = Collection('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt\n', keep_client=keep)
135 147
        writer = c.open("count.txt", "a+")
136
        self.assertEqual(writer.read(20), "0123456789")
148
        self.assertEqual(writer.read(20), b"0123456789")
137 149
        writer.seek(0, os.SEEK_SET)
138 150

  
139 151
        writer.write("hello")
140
        self.assertEqual(writer.read(20), "0123456789hello")
152
        self.assertEqual(writer.read(20), b"0123456789hello")
141 153
        writer.seek(0, os.SEEK_SET)
142 154

  
143 155
        writer.write("world")
144
        self.assertEqual(writer.read(20), "0123456789helloworld")
156
        self.assertEqual(writer.read(20), b"0123456789helloworld")
145 157

  
146 158
        self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 fc5e038d38a57032085441e7fe7010b0+10 0:20:count.txt\n", c.portable_manifest_text())
147 159

  
148 160
    def test_write_at_beginning(self):
149
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": "0123456789"})
161
        keep = ArvadosFileWriterTestCase.MockKeep({
162
            "781e5e245d69b566979b86e28d23f2c7+10": b"0123456789",
163
        })
150 164
        with Collection('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt\n',
151 165
                             keep_client=keep) as c:
152 166
            writer = c.open("count.txt", "r+")
153
            self.assertEqual("0123456789", writer.readfrom(0, 13))
167
            self.assertEqual(b"0123456789", writer.readfrom(0, 13))
154 168
            writer.seek(0, os.SEEK_SET)
155 169
            writer.write("foo")
156 170
            self.assertEqual(writer.size(), 10)
157
            self.assertEqual("foo3456789", writer.readfrom(0, 13))
171
            self.assertEqual(b"foo3456789", writer.readfrom(0, 13))
158 172
            self.assertEqual(". acbd18db4cc2f85cedef654fccc4a4d8+3 781e5e245d69b566979b86e28d23f2c7+10 0:3:count.txt 6:7:count.txt\n", c.portable_manifest_text())
159 173

  
160 174
    def test_write_empty(self):
......
168 182
        keep = ArvadosFileWriterTestCase.MockKeep({})
169 183
        with Collection(keep_client=keep) as c:
170 184
            writer = c.open("count.txt", "w")
171
            writer.write("0123456789")
185
            writer.write(b"0123456789")
172 186
            self.assertEqual('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt\n', c.portable_manifest_text())
173 187
            self.assertNotIn('781e5e245d69b566979b86e28d23f2c7+10', keep.blocks)
174 188

  
......
187 201

  
188 202

  
189 203
    def test_write_in_middle(self):
190
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": "0123456789"})
204
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": b"0123456789"})
191 205
        with Collection('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt\n',
192 206
                             keep_client=keep) as c:
193 207
            writer = c.open("count.txt", "r+")
194
            self.assertEqual("0123456789", writer.readfrom(0, 13))
208
            self.assertEqual(b"0123456789", writer.readfrom(0, 13))
195 209
            writer.seek(3, os.SEEK_SET)
196 210
            writer.write("foo")
197 211
            self.assertEqual(writer.size(), 10)
198
            self.assertEqual("012foo6789", writer.readfrom(0, 13))
212
            self.assertEqual(b"012foo6789", writer.readfrom(0, 13))
199 213
            self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:count.txt 10:3:count.txt 6:4:count.txt\n", c.portable_manifest_text())
200 214

  
201 215
    def test_write_at_end(self):
202
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": "0123456789"})
216
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": b"0123456789"})
203 217
        with Collection('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt\n',
204 218
                             keep_client=keep) as c:
205 219
            writer = c.open("count.txt", "r+")
206
            self.assertEqual("0123456789", writer.readfrom(0, 13))
220
            self.assertEqual(b"0123456789", writer.readfrom(0, 13))
207 221
            writer.seek(7, os.SEEK_SET)
208 222
            writer.write("foo")
209 223
            self.assertEqual(writer.size(), 10)
210
            self.assertEqual("0123456foo", writer.readfrom(0, 13))
224
            self.assertEqual(b"0123456foo", writer.readfrom(0, 13))
211 225
            self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 acbd18db4cc2f85cedef654fccc4a4d8+3 0:7:count.txt 10:3:count.txt\n", c.portable_manifest_text())
212 226

  
213 227
    def test_write_across_segment_boundary(self):
214
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": "0123456789"})
228
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": b"0123456789"})
215 229
        with Collection('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt 0:10:count.txt\n',
216 230
                             keep_client=keep) as c:
217 231
            writer = c.open("count.txt", "r+")
218
            self.assertEqual("012345678901234", writer.readfrom(0, 15))
232
            self.assertEqual(b"012345678901234", writer.readfrom(0, 15))
219 233
            writer.seek(7, os.SEEK_SET)
220 234
            writer.write("foobar")
221 235
            self.assertEqual(writer.size(), 20)
222
            self.assertEqual("0123456foobar34", writer.readfrom(0, 15))
236
            self.assertEqual(b"0123456foobar34", writer.readfrom(0, 15))
223 237
            self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 3858f62230ac3c915f300c664312c63f+6 0:7:count.txt 10:6:count.txt 3:7:count.txt\n", c.portable_manifest_text())
224 238

  
225 239
    def test_write_across_several_segments(self):
226
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": "0123456789"})
240
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": b"0123456789"})
227 241
        with Collection('. 781e5e245d69b566979b86e28d23f2c7+10 0:4:count.txt 0:4:count.txt 0:4:count.txt',
228 242
                             keep_client=keep) as c:
229 243
            writer = c.open("count.txt", "r+")
230
            self.assertEqual("012301230123", writer.readfrom(0, 15))
244
            self.assertEqual(b"012301230123", writer.readfrom(0, 15))
231 245
            writer.seek(2, os.SEEK_SET)
232 246
            writer.write("abcdefg")
233 247
            self.assertEqual(writer.size(), 12)
234
            self.assertEqual("01abcdefg123", writer.readfrom(0, 15))
248
            self.assertEqual(b"01abcdefg123", writer.readfrom(0, 15))
235 249
            self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 7ac66c0f148de9519b8bd264312c4d64+7 0:2:count.txt 10:7:count.txt 1:3:count.txt\n", c.portable_manifest_text())
236 250

  
237 251
    def test_write_large(self):
......
283 297
                writer.write("0123456789")
284 298

  
285 299
            self.assertEqual(writer.size(), 10)
286
            self.assertEqual("0123456789", writer.readfrom(0, 20))
300
            self.assertEqual(b"0123456789", writer.readfrom(0, 20))
287 301
            self.assertEqual(". 7a08b07e84641703e5f2c836aa59a170+100 90:10:count.txt\n", c.portable_manifest_text())
288 302
            writer.flush()
289 303
            self.assertEqual(writer.size(), 10)
290
            self.assertEqual("0123456789", writer.readfrom(0, 20))
304
            self.assertEqual(b"0123456789", writer.readfrom(0, 20))
291 305
            self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt\n", c.portable_manifest_text())
292 306

  
293 307
    def test_rewrite_append_existing_file(self):
294
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": "0123456789"})
308
        keep = ArvadosFileWriterTestCase.MockKeep({
309
            "781e5e245d69b566979b86e28d23f2c7+10": b"0123456789",
310
        })
295 311
        with Collection('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt',
296 312
                             keep_client=keep) as c:
297 313
            writer = c.open("count.txt", "r+")
......
300 316
                writer.write("abcdefghij")
301 317

  
302 318
            self.assertEqual(writer.size(), 20)
303
            self.assertEqual("0123456789abcdefghij", writer.readfrom(0, 20))
319
            self.assertEqual(b"0123456789abcdefghij", writer.readfrom(0, 20))
304 320
            self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 ae5f43bab79cf0be33f025fa97ae7398+100 0:10:count.txt 100:10:count.txt\n", c.portable_manifest_text())
305 321

  
306 322
            writer.arvadosfile.flush()
307 323
            self.assertEqual(writer.size(), 20)
308
            self.assertEqual("0123456789abcdefghij", writer.readfrom(0, 20))
324
            self.assertEqual(b"0123456789abcdefghij", writer.readfrom(0, 20))
309 325
            self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 a925576942e94b2ef57a066101b48876+10 0:20:count.txt\n", c.portable_manifest_text())
310 326

  
311 327
    def test_rewrite_over_existing_file(self):
312
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": "0123456789"})
328
        keep = ArvadosFileWriterTestCase.MockKeep({
329
            "781e5e245d69b566979b86e28d23f2c7+10": b"0123456789",
330
        })
313 331
        with Collection('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt',
314 332
                             keep_client=keep) as c:
315 333
            writer = c.open("count.txt", "r+")
......
318 336
                writer.write("abcdefghij")
319 337

  
320 338
            self.assertEqual(writer.size(), 15)
321
            self.assertEqual("01234abcdefghij", writer.readfrom(0, 20))
339
            self.assertEqual(b"01234abcdefghij", writer.readfrom(0, 20))
322 340
            self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 ae5f43bab79cf0be33f025fa97ae7398+100 0:5:count.txt 100:10:count.txt\n", c.portable_manifest_text())
323 341

  
324 342
            writer.arvadosfile.flush()
325 343

  
326 344
            self.assertEqual(writer.size(), 15)
327
            self.assertEqual("01234abcdefghij", writer.readfrom(0, 20))
345
            self.assertEqual(b"01234abcdefghij", writer.readfrom(0, 20))
328 346
            self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 a925576942e94b2ef57a066101b48876+10 0:5:count.txt 10:10:count.txt\n", c.portable_manifest_text())
329 347

  
330 348
    def test_write_large_rewrite(self):
......
338 356
        with Collection('. ' + arvados.config.EMPTY_BLOCK_LOCATOR + ' 0:0:count.txt',
339 357
                             api_client=api, keep_client=keep) as c:
340 358
            writer = c.open("count.txt", "r+")
341
            text = ''.join(["0123456789" for a in range(0, 100)])
359
            text = b''.join([b"0123456789" for a in range(0, 100)])
342 360
            for b in range(0, 100000):
343 361
                writer.write(text)
344 362
            writer.seek(0, os.SEEK_SET)
......
353 371

  
354 372
    def test_create(self):
355 373
        keep = ArvadosFileWriterTestCase.MockKeep({})
356
        api = ArvadosFileWriterTestCase.MockApi({"name":"test_create",
357
                                                 "manifest_text":". 2e9ec317e197819358fbc43afca7d837+8 0:8:count.txt\n",
358
                                                 "replication_desired":None},
359
                                                {"uuid":"zzzzz-4zz18-mockcollection0",
360
                                                 "manifest_text":". 2e9ec317e197819358fbc43afca7d837+8 0:8:count.txt\n",
361
                                                 "portable_data_hash":"7a461a8c58601798f690f8b368ac4423+51"})
374
        api = ArvadosFileWriterTestCase.MockApi({
375
            "name":"test_create",
376
            "manifest_text":". 2e9ec317e197819358fbc43afca7d837+8 0:8:count.txt\n",
377
            "replication_desired":None,
378
        }, {
379
            "uuid":"zzzzz-4zz18-mockcollection0",
380
            "manifest_text":". 2e9ec317e197819358fbc43afca7d837+8 0:8:count.txt\n",
381
            "portable_data_hash":"7a461a8c58601798f690f8b368ac4423+51",
382
        })
362 383
        with Collection(api_client=api, keep_client=keep) as c:
363 384
            writer = c.open("count.txt", "w+")
364 385
            self.assertEqual(writer.size(), 0)
......
371 392
            c.save_new("test_create")
372 393
            self.assertEqual("zzzzz-4zz18-mockcollection0", c.manifest_locator())
373 394
            self.assertFalse(c.modified())
374
            self.assertEqual("01234567", keep.get("2e9ec317e197819358fbc43afca7d837+8"))
395
            self.assertEqual(b"01234567", keep.get("2e9ec317e197819358fbc43afca7d837+8"))
375 396

  
376 397

  
377 398
    def test_create_subdir(self):
......
444 465
            c.save_new("test_create_multiple")
445 466
            self.assertEqual("zzzzz-4zz18-mockcollection0", c.manifest_locator())
446 467
            self.assertFalse(c.modified())
447
            self.assertEqual("01234567", keep.get("2e9ec317e197819358fbc43afca7d837+8"))
468
            self.assertEqual(b"01234567", keep.get("2e9ec317e197819358fbc43afca7d837+8"))
448 469

  
449 470

  
450 471
class ArvadosFileReaderTestCase(StreamFileReaderTestCase):
......
478 499
        stream = []
479 500
        n = 0
480 501
        blocks = {}
481
        for d in ['01234', '34567', '67890']:
502
        for d in [b'01234', b'34567', b'67890']:
482 503
            loc = tutil.str_keep_locator(d)
483 504
            blocks[loc] = d
484 505
            stream.append(Range(loc, n, len(d)))
......
490 511
        # read() needs to return all the data requested if possible, even if it
491 512
        # crosses uncached blocks: https://arvados.org/issues/5856
492 513
        sfile = self.make_count_reader(nocache=True)
493
        self.assertEqual('12345678', sfile.read(8))
514
        self.assertEqual(b'12345678', sfile.read(8))
494 515

  
495 516
    def test_successive_reads(self):
496 517
        # Override StreamFileReaderTestCase.test_successive_reads
497 518
        sfile = self.make_count_reader(nocache=True)
498
        self.assertEqual('1234', sfile.read(4))
499
        self.assertEqual('5678', sfile.read(4))
500
        self.assertEqual('9', sfile.read(4))
501
        self.assertEqual('', sfile.read(4))
519
        self.assertEqual(b'1234', sfile.read(4))
520
        self.assertEqual(b'5678', sfile.read(4))
521
        self.assertEqual(b'9', sfile.read(4))
522
        self.assertEqual(b'', sfile.read(4))
502 523

  
503 524
    def test_tell_after_block_read(self):
504 525
        # Override StreamFileReaderTestCase.test_tell_after_block_read
505 526
        sfile = self.make_count_reader(nocache=True)
506
        self.assertEqual('12345678', sfile.read(8))
527
        self.assertEqual(b'12345678', sfile.read(8))
507 528
        self.assertEqual(8, sfile.tell())
508 529

  
509 530
    def test_prefetch(self):
510
        keep = ArvadosFileWriterTestCase.MockKeep({"2e9ec317e197819358fbc43afca7d837+8": "01234567", "e8dc4081b13434b45189a720b77b6818+8": "abcdefgh"})
531
        keep = ArvadosFileWriterTestCase.MockKeep({
532
            "2e9ec317e197819358fbc43afca7d837+8": b"01234567",
533
            "e8dc4081b13434b45189a720b77b6818+8": b"abcdefgh",
534
        })
511 535
        with Collection(". 2e9ec317e197819358fbc43afca7d837+8 e8dc4081b13434b45189a720b77b6818+8 0:16:count.txt\n", keep_client=keep) as c:
512 536
            r = c.open("count.txt", "r")
513
            self.assertEqual("0123", r.read(4))
537
            self.assertEqual(b"0123", r.read(4))
514 538
        self.assertIn("2e9ec317e197819358fbc43afca7d837+8", keep.requests)
515 539
        self.assertIn("e8dc4081b13434b45189a720b77b6818+8", keep.requests)
516 540

  
......
572 596

  
573 597
class ArvadosFileReadAllTestCase(ArvadosFileReadTestCase):
574 598
    def read_for_test(self, reader, byte_count, **kwargs):
575
        return ''.join(reader.readall(**kwargs))
599
        return b''.join(reader.readall(**kwargs))
576 600

  
577 601

  
578 602
class ArvadosFileReadAllDecompressedTestCase(ArvadosFileReadTestCase):
579 603
    def read_for_test(self, reader, byte_count, **kwargs):
580
        return ''.join(reader.readall_decompressed(**kwargs))
604
        return b''.join(reader.readall_decompressed(**kwargs))
581 605

  
582 606

  
583 607
class ArvadosFileReadlinesTestCase(ArvadosFileReadTestCase):
......
612 636
            bufferblock.append("foo")
613 637

  
614 638
            self.assertEqual(bufferblock.size(), 3)
615
            self.assertEqual(bufferblock.buffer_view[0:3], "foo")
639
            self.assertEqual(bufferblock.buffer_view[0:3], b"foo")
616 640
            self.assertEqual(bufferblock.locator(), "acbd18db4cc2f85cedef654fccc4a4d8+3")
617 641

  
618 642
            bufferblock.append("bar")
619 643

  
620 644
            self.assertEqual(bufferblock.size(), 6)
621
            self.assertEqual(bufferblock.buffer_view[0:6], "foobar")
645
            self.assertEqual(bufferblock.buffer_view[0:6], b"foobar")
622 646
            self.assertEqual(bufferblock.locator(), "3858f62230ac3c915f300c664312c63f+6")
623 647

  
624 648
            bufferblock.set_state(arvados.arvfile._BufferBlock.PENDING)
......
632 656
            bufferblock.append("foo")
633 657

  
634 658
            self.assertEqual(bufferblock.size(), 3)
635
            self.assertEqual(bufferblock.buffer_view[0:3], "foo")
659
            self.assertEqual(bufferblock.buffer_view[0:3], b"foo")
636 660
            self.assertEqual(bufferblock.locator(), "acbd18db4cc2f85cedef654fccc4a4d8+3")
637 661
            bufferblock.set_state(arvados.arvfile._BufferBlock.PENDING)
638 662

  
......
642 666
            bufferblock2.append("bar")
643 667

  
644 668
            self.assertEqual(bufferblock2.size(), 6)
645
            self.assertEqual(bufferblock2.buffer_view[0:6], "foobar")
669
            self.assertEqual(bufferblock2.buffer_view[0:6], b"foobar")
646 670
            self.assertEqual(bufferblock2.locator(), "3858f62230ac3c915f300c664312c63f+6")
647 671

  
648 672
            self.assertEqual(bufferblock.size(), 3)
649
            self.assertEqual(bufferblock.buffer_view[0:3], "foo")
673
            self.assertEqual(bufferblock.buffer_view[0:3], b"foo")
650 674
            self.assertEqual(bufferblock.locator(), "acbd18db4cc2f85cedef654fccc4a4d8+3")
651 675

  
652 676
    def test_bufferblock_get(self):
653
        keep = ArvadosFileWriterTestCase.MockKeep({"781e5e245d69b566979b86e28d23f2c7+10": "0123456789"})
677
        keep = ArvadosFileWriterTestCase.MockKeep({
678
            "781e5e245d69b566979b86e28d23f2c7+10": b"0123456789",
679
        })
654 680
        with arvados.arvfile._BlockManager(keep) as blockmanager:
655 681
            bufferblock = blockmanager.alloc_bufferblock()
656 682
            bufferblock.append("foo")
657 683

  
658
            self.assertEqual(blockmanager.get_block_contents("781e5e245d69b566979b86e28d23f2c7+10", 1), "0123456789")
659
            self.assertEqual(blockmanager.get_block_contents(bufferblock.blockid, 1), "foo")
684
            self.assertEqual(blockmanager.get_block_contents("781e5e245d69b566979b86e28d23f2c7+10", 1), b"0123456789")
685
            self.assertEqual(blockmanager.get_block_contents(bufferblock.blockid, 1), b"foo")
660 686

  
661 687
    def test_bufferblock_commit(self):
662 688
        mockkeep = mock.MagicMock()

Also available in: Unified diff