318
322
self.assertEqual("@", osutils.kind_marker("symlink"))
319
323
self.assertRaises(errors.BzrError, osutils.kind_marker, "unknown")
325
def test_host_os_dereferences_symlinks(self):
326
osutils.host_os_dereferences_symlinks()
329
class TestPumpFile(TestCase):
330
"""Test pumpfile method."""
332
# create a test datablock
333
self.block_size = 512
334
pattern = '0123456789ABCDEF'
335
self.test_data = pattern * (3 * self.block_size / len(pattern))
336
self.test_data_len = len(self.test_data)
338
def test_bracket_block_size(self):
339
"""Read data in blocks with the requested read size bracketing the
341
# make sure test data is larger than max read size
342
self.assertTrue(self.test_data_len > self.block_size)
344
from_file = FakeReadFile(self.test_data)
347
# read (max / 2) bytes and verify read size wasn't affected
348
num_bytes_to_read = self.block_size / 2
349
pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
350
self.assertEqual(from_file.get_max_read_size(), num_bytes_to_read)
351
self.assertEqual(from_file.get_read_count(), 1)
353
# read (max) bytes and verify read size wasn't affected
354
num_bytes_to_read = self.block_size
355
from_file.reset_read_count()
356
pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
357
self.assertEqual(from_file.get_max_read_size(), num_bytes_to_read)
358
self.assertEqual(from_file.get_read_count(), 1)
360
# read (max + 1) bytes and verify read size was limited
361
num_bytes_to_read = self.block_size + 1
362
from_file.reset_read_count()
363
pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
364
self.assertEqual(from_file.get_max_read_size(), self.block_size)
365
self.assertEqual(from_file.get_read_count(), 2)
367
# finish reading the rest of the data
368
num_bytes_to_read = self.test_data_len - to_file.tell()
369
pumpfile(from_file, to_file, num_bytes_to_read, self.block_size)
371
# report error if the data wasn't equal (we only report the size due
372
# to the length of the data)
373
response_data = to_file.getvalue()
374
if response_data != self.test_data:
375
message = "Data not equal. Expected %d bytes, received %d."
376
self.fail(message % (len(response_data), self.test_data_len))
378
def test_specified_size(self):
379
"""Request a transfer larger than the maximum block size and verify
380
that the maximum read doesn't exceed the block_size."""
381
# make sure test data is larger than max read size
382
self.assertTrue(self.test_data_len > self.block_size)
384
# retrieve data in blocks
385
from_file = FakeReadFile(self.test_data)
387
pumpfile(from_file, to_file, self.test_data_len, self.block_size)
389
# verify read size was equal to the maximum read size
390
self.assertTrue(from_file.get_max_read_size() > 0)
391
self.assertEqual(from_file.get_max_read_size(), self.block_size)
392
self.assertEqual(from_file.get_read_count(), 3)
394
# report error if the data wasn't equal (we only report the size due
395
# to the length of the data)
396
response_data = to_file.getvalue()
397
if response_data != self.test_data:
398
message = "Data not equal. Expected %d bytes, received %d."
399
self.fail(message % (len(response_data), self.test_data_len))
401
def test_to_eof(self):
402
"""Read to end-of-file and verify that the reads are not larger than
403
the maximum read size."""
404
# make sure test data is larger than max read size
405
self.assertTrue(self.test_data_len > self.block_size)
407
# retrieve data to EOF
408
from_file = FakeReadFile(self.test_data)
410
pumpfile(from_file, to_file, -1, self.block_size)
412
# verify read size was equal to the maximum read size
413
self.assertEqual(from_file.get_max_read_size(), self.block_size)
414
self.assertEqual(from_file.get_read_count(), 4)
416
# report error if the data wasn't equal (we only report the size due
417
# to the length of the data)
418
response_data = to_file.getvalue()
419
if response_data != self.test_data:
420
message = "Data not equal. Expected %d bytes, received %d."
421
self.fail(message % (len(response_data), self.test_data_len))
423
def test_defaults(self):
424
"""Verifies that the default arguments will read to EOF -- this
425
test verifies that any existing usages of pumpfile will not be broken
426
with this new version."""
427
# retrieve data using default (old) pumpfile method
428
from_file = FakeReadFile(self.test_data)
430
pumpfile(from_file, to_file)
432
# report error if the data wasn't equal (we only report the size due
433
# to the length of the data)
434
response_data = to_file.getvalue()
435
if response_data != self.test_data:
436
message = "Data not equal. Expected %d bytes, received %d."
437
self.fail(message % (len(response_data), self.test_data_len))
322
439
class TestSafeUnicode(TestCase):