1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
169
171
(['src'], 'src'),
171
173
self.assert_(is_inside_or_parent_of_any(dirs, fn))
173
175
for dirs, fn in [(['src'], 'srccontrol'),
174
176
(['srccontrol/foo.c'], 'src'),
175
177
(['src'], 'srccontrol/foo')]:
308
310
self.assertEqual(bar_path, osutils.realpath('./bar'))
309
311
os.symlink('bar', 'foo')
310
312
self.assertEqual(bar_path, osutils.realpath('./foo'))
312
314
# Does not dereference terminal symlinks
313
315
foo_path = osutils.pathjoin(cwd, 'foo')
314
316
self.assertEqual(foo_path, osutils.dereference_path('./foo'))
356
358
osutils.host_os_dereferences_symlinks()
361
class TestCanonicalRelPath(TestCaseInTempDir):
363
_test_needs_features = [CaseInsCasePresFilenameFeature]
365
def test_canonical_relpath_simple(self):
366
f = file('MixedCaseName', 'w')
368
self.failUnlessEqual(
369
canonical_relpath(self.test_base_dir, 'mixedcasename'),
370
'work/MixedCaseName')
372
def test_canonical_relpath_missing_tail(self):
373
os.mkdir('MixedCaseParent')
374
self.failUnlessEqual(
375
canonical_relpath(self.test_base_dir, 'mixedcaseparent/nochild'),
376
'work/MixedCaseParent/nochild')
359
379
class TestPumpFile(TestCase):
360
380
"""Test pumpfile method."""
466
486
message = "Data not equal. Expected %d bytes, received %d."
467
487
self.fail(message % (len(response_data), self.test_data_len))
489
def test_report_activity(self):
491
def log_activity(length, direction):
492
activity.append((length, direction))
493
from_file = StringIO(self.test_data)
495
pumpfile(from_file, to_file, buff_size=500,
496
report_activity=log_activity, direction='read')
497
self.assertEqual([(500, 'read'), (500, 'read'), (500, 'read'),
498
(36, 'read')], activity)
500
from_file = StringIO(self.test_data)
503
pumpfile(from_file, to_file, buff_size=500,
504
report_activity=log_activity, direction='write')
505
self.assertEqual([(500, 'write'), (500, 'write'), (500, 'write'),
506
(36, 'write')], activity)
508
# And with a limited amount of data
509
from_file = StringIO(self.test_data)
512
pumpfile(from_file, to_file, buff_size=500, read_length=1028,
513
report_activity=log_activity, direction='read')
514
self.assertEqual([(500, 'read'), (500, 'read'), (28, 'read')], activity)
470
518
class TestPumpStringFile(TestCase):
764
812
self.assertEqual(['foo\n', 'bar\n', 'baz\n'],
765
813
osutils.chunks_to_lines(['foo\n', 'bar\n', 'baz\n']))
767
def test_is_compiled(self):
768
from bzrlib.tests.test__chunks_to_lines import CompiledChunksToLinesFeature
769
if CompiledChunksToLinesFeature:
815
def test_osutils_binding(self):
816
from bzrlib.tests import test__chunks_to_lines
817
if test__chunks_to_lines.CompiledChunksToLinesFeature.available():
770
818
from bzrlib._chunks_to_lines_pyx import chunks_to_lines
772
820
from bzrlib._chunks_to_lines_py import chunks_to_lines
1423
1471
self.assertEqual(expected_sha, osutils.sha_file_by_name('foo'))
1427
r'''# Copyright (C) 2005, 2006 Canonical Ltd
1429
# This program is free software; you can redistribute it and/or modify
1430
# it under the terms of the GNU General Public License as published by
1431
# the Free Software Foundation; either version 2 of the License, or
1432
# (at your option) any later version.
1434
# This program is distributed in the hope that it will be useful,
1435
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1436
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1437
# GNU General Public License for more details.
1439
# You should have received a copy of the GNU General Public License
1440
# along with this program; if not, write to the Free Software
1441
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1444
# NOTE: If update these, please also update the help for global-options in
1445
# bzrlib/help_topics/__init__.py
1448
"""Set of flags that enable different debug behaviour.
1450
These are set with eg ``-Dlock`` on the bzr command line.
1454
* auth - show authentication sections used
1455
* error - show stack traces for all top level exceptions
1456
* evil - capture call sites that do expensive or badly-scaling operations.
1457
* fetch - trace history copying between repositories
1458
* graph - trace graph traversal information
1459
* hashcache - log every time a working file is read to determine its hash
1460
* hooks - trace hook execution
1461
* hpss - trace smart protocol requests and responses
1462
* http - trace http connections, requests and responses
1463
* index - trace major index operations
1464
* knit - trace knit operations
1465
* lock - trace when lockdir locks are taken or released
1466
* merge - emit information for debugging merges
1467
* pack - emit information about pack operations
1473
1474
class TestResourceLoading(TestCaseInTempDir):
1475
1476
def test_resource_string(self):
1476
1477
# test resource in bzrlib
1477
1478
text = osutils.resource_string('bzrlib', 'debug.py')
1478
self.assertEquals(_debug_text, text)
1479
self.assertContainsRe(text, "debug_flags = set()")
1479
1480
# test resource under bzrlib
1480
1481
text = osutils.resource_string('bzrlib.ui', 'text.py')
1481
1482
self.assertContainsRe(text, "class TextUIFactory")