/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

merge bzr.dev r4042

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
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
37
37
        pathjoin,
38
38
        pumpfile,
39
39
        pump_string_file,
 
40
        canonical_relpath,
40
41
        )
41
42
from bzrlib.tests import (
42
43
        adapt_tests,
45
46
        split_suite_by_re,
46
47
        StringIOWrapper,
47
48
        SymlinkFeature,
 
49
        CaseInsCasePresFilenameFeature,
48
50
        TestCase,
49
51
        TestCaseInTempDir,
50
52
        TestScenarioApplier,
169
171
                         (['src'], 'src'),
170
172
                         ]:
171
173
            self.assert_(is_inside_or_parent_of_any(dirs, fn))
172
 
            
 
174
 
173
175
        for dirs, fn in [(['src'], 'srccontrol'),
174
176
                         (['srccontrol/foo.c'], 'src'),
175
177
                         (['src'], 'srccontrol/foo')]:
200
202
        if osutils.has_symlinks():
201
203
            os.symlink('symlink', 'symlink')
202
204
            self.assertEquals('symlink', osutils.file_kind('symlink'))
203
 
        
 
205
 
204
206
        # TODO: jam 20060529 Test a block device
205
207
        try:
206
208
            os.lstat('/dev/null')
308
310
        self.assertEqual(bar_path, osutils.realpath('./bar'))
309
311
        os.symlink('bar', 'foo')
310
312
        self.assertEqual(bar_path, osutils.realpath('./foo'))
311
 
        
 
313
 
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()
357
359
 
358
360
 
 
361
class TestCanonicalRelPath(TestCaseInTempDir):
 
362
 
 
363
    _test_needs_features = [CaseInsCasePresFilenameFeature]
 
364
 
 
365
    def test_canonical_relpath_simple(self):
 
366
        f = file('MixedCaseName', 'w')
 
367
        f.close()
 
368
        self.failUnlessEqual(
 
369
            canonical_relpath(self.test_base_dir, 'mixedcasename'),
 
370
            'work/MixedCaseName')
 
371
 
 
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')
 
377
 
 
378
 
359
379
class TestPumpFile(TestCase):
360
380
    """Test pumpfile method."""
361
381
    def setUp(self):
466
486
            message = "Data not equal.  Expected %d bytes, received %d."
467
487
            self.fail(message % (len(response_data), self.test_data_len))
468
488
 
 
489
    def test_report_activity(self):
 
490
        activity = []
 
491
        def log_activity(length, direction):
 
492
            activity.append((length, direction))
 
493
        from_file = StringIO(self.test_data)
 
494
        to_file = StringIO()
 
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)
 
499
 
 
500
        from_file = StringIO(self.test_data)
 
501
        to_file = StringIO()
 
502
        del activity[:]
 
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)
 
507
 
 
508
        # And with a limited amount of data
 
509
        from_file = StringIO(self.test_data)
 
510
        to_file = StringIO()
 
511
        del activity[:]
 
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)
 
515
 
 
516
 
469
517
 
470
518
class TestPumpStringFile(TestCase):
471
519
 
644
692
 
645
693
class TestWin32FuncsDirs(TestCaseInTempDir):
646
694
    """Test win32 functions that create files."""
647
 
    
 
695
 
648
696
    def test_getcwd(self):
649
697
        if win32utils.winver == 'Windows 98':
650
698
            raise TestSkipped('Windows 98 cannot handle unicode filenames')
764
812
        self.assertEqual(['foo\n', 'bar\n', 'baz\n'],
765
813
                         osutils.chunks_to_lines(['foo\n', 'bar\n', 'baz\n']))
766
814
 
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
771
819
        else:
772
820
            from bzrlib._chunks_to_lines_py import chunks_to_lines
1282
1330
 
1283
1331
 
1284
1332
class TestCopyTree(TestCaseInTempDir):
1285
 
    
 
1333
 
1286
1334
    def test_copy_basic_tree(self):
1287
1335
        self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
1288
1336
        osutils.copy_tree('source', 'target')
1367
1415
 
1368
1416
    def test_unicode(self):
1369
1417
        """Environment can only contain plain strings
1370
 
        
 
1418
 
1371
1419
        So Unicode strings must be encoded.
1372
1420
        """
1373
1421
        uni_val, env_val = probe_unicode_in_user_encoding()
1423
1471
        self.assertEqual(expected_sha, osutils.sha_file_by_name('foo'))
1424
1472
 
1425
1473
 
1426
 
_debug_text = \
1427
 
r'''# Copyright (C) 2005, 2006 Canonical Ltd
1428
 
#
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.
1433
 
#
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.
1438
 
#
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
1442
 
 
1443
 
 
1444
 
# NOTE: If update these, please also update the help for global-options in
1445
 
#       bzrlib/help_topics/__init__.py
1446
 
 
1447
 
debug_flags = set()
1448
 
"""Set of flags that enable different debug behaviour.
1449
 
 
1450
 
These are set with eg ``-Dlock`` on the bzr command line.
1451
 
 
1452
 
Options include:
1453
 
 
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
1468
 
 
1469
 
"""
1470
 
'''
1471
 
 
1472
 
 
1473
1474
class TestResourceLoading(TestCaseInTempDir):
1474
1475
 
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")