/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

  • Committer: Jelmer Vernooij
  • Date: 2009-03-22 00:24:37 UTC
  • mfrom: (4180 +trunk)
  • mto: (3920.2.35 dpush)
  • mto: This revision was merged to the branch mainline in revision 4281.
  • Revision ID: jelmer@samba.org-20090322002437-0vlyqnz29isqeozo
Merge bzr.dev.

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
40
40
        canonical_relpath,
41
41
        )
42
42
from bzrlib.tests import (
43
 
        adapt_tests,
44
43
        Feature,
45
44
        probe_unicode_in_user_encoding,
46
 
        split_suite_by_re,
47
45
        StringIOWrapper,
48
46
        SymlinkFeature,
49
47
        CaseInsCasePresFilenameFeature,
50
48
        TestCase,
51
49
        TestCaseInTempDir,
52
 
        TestScenarioApplier,
53
50
        TestSkipped,
54
51
        )
55
52
from bzrlib.tests.file_utils import (
171
168
                         (['src'], 'src'),
172
169
                         ]:
173
170
            self.assert_(is_inside_or_parent_of_any(dirs, fn))
174
 
            
 
171
 
175
172
        for dirs, fn in [(['src'], 'srccontrol'),
176
173
                         (['srccontrol/foo.c'], 'src'),
177
174
                         (['src'], 'srccontrol/foo')]:
202
199
        if osutils.has_symlinks():
203
200
            os.symlink('symlink', 'symlink')
204
201
            self.assertEquals('symlink', osutils.file_kind('symlink'))
205
 
        
 
202
 
206
203
        # TODO: jam 20060529 Test a block device
207
204
        try:
208
205
            os.lstat('/dev/null')
310
307
        self.assertEqual(bar_path, osutils.realpath('./bar'))
311
308
        os.symlink('bar', 'foo')
312
309
        self.assertEqual(bar_path, osutils.realpath('./foo'))
313
 
        
 
310
 
314
311
        # Does not dereference terminal symlinks
315
312
        foo_path = osutils.pathjoin(cwd, 'foo')
316
313
        self.assertEqual(foo_path, osutils.dereference_path('./foo'))
379
376
class TestPumpFile(TestCase):
380
377
    """Test pumpfile method."""
381
378
    def setUp(self):
 
379
        TestCase.setUp(self)
382
380
        # create a test datablock
383
381
        self.block_size = 512
384
382
        pattern = '0123456789ABCDEF'
692
690
 
693
691
class TestWin32FuncsDirs(TestCaseInTempDir):
694
692
    """Test win32 functions that create files."""
695
 
    
 
693
 
696
694
    def test_getcwd(self):
697
695
        if win32utils.winver == 'Windows 98':
698
696
            raise TestSkipped('Windows 98 cannot handle unicode filenames')
882
880
        self.assertEqual(expected_dirblocks[1:],
883
881
            [(dirinfo, [line[0:3] for line in block]) for dirinfo, block in result])
884
882
 
 
883
    def test_walkdirs_os_error(self):
 
884
        # <https://bugs.edge.launchpad.net/bzr/+bug/338653>
 
885
        # Pyrex readdir didn't raise useful messages if it had an error
 
886
        # reading the directory
 
887
        if sys.platform == 'win32':
 
888
            raise tests.TestNotApplicable(
 
889
                "readdir IOError not tested on win32")
 
890
        os.mkdir("test-unreadable")
 
891
        os.chmod("test-unreadable", 0000)
 
892
        # must chmod it back so that it can be removed
 
893
        self.addCleanup(lambda: os.chmod("test-unreadable", 0700))
 
894
        # The error is not raised until the generator is actually evaluated.
 
895
        # (It would be ok if it happened earlier but at the moment it
 
896
        # doesn't.)
 
897
        e = self.assertRaises(OSError, list, osutils._walkdirs_utf8("."))
 
898
        self.assertEquals('./test-unreadable', e.filename)
 
899
        self.assertEquals(errno.EACCES, e.errno)
 
900
        # Ensure the message contains the file name
 
901
        self.assertContainsRe(str(e), "\./test-unreadable")
 
902
 
885
903
    def test__walkdirs_utf8(self):
886
904
        tree = [
887
905
            '.bzr',
1330
1348
 
1331
1349
 
1332
1350
class TestCopyTree(TestCaseInTempDir):
1333
 
    
 
1351
 
1334
1352
    def test_copy_basic_tree(self):
1335
1353
        self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
1336
1354
        osutils.copy_tree('source', 'target')
1415
1433
 
1416
1434
    def test_unicode(self):
1417
1435
        """Environment can only contain plain strings
1418
 
        
 
1436
 
1419
1437
        So Unicode strings must be encoded.
1420
1438
        """
1421
1439
        uni_val, env_val = probe_unicode_in_user_encoding()
1457
1475
        self.assertTrue(-eighteen_hours < offset < eighteen_hours)
1458
1476
 
1459
1477
 
 
1478
class TestSizeShaFile(TestCaseInTempDir):
 
1479
 
 
1480
    def test_sha_empty(self):
 
1481
        self.build_tree_contents([('foo', '')])
 
1482
        expected_sha = osutils.sha_string('')
 
1483
        f = open('foo')
 
1484
        self.addCleanup(f.close)
 
1485
        size, sha = osutils.size_sha_file(f)
 
1486
        self.assertEqual(0, size)
 
1487
        self.assertEqual(expected_sha, sha)
 
1488
 
 
1489
    def test_sha_mixed_endings(self):
 
1490
        text = 'test\r\nwith\nall\rpossible line endings\r\n'
 
1491
        self.build_tree_contents([('foo', text)])
 
1492
        expected_sha = osutils.sha_string(text)
 
1493
        f = open('foo')
 
1494
        self.addCleanup(f.close)
 
1495
        size, sha = osutils.size_sha_file(f)
 
1496
        self.assertEqual(38, size)
 
1497
        self.assertEqual(expected_sha, sha)
 
1498
 
 
1499
 
1460
1500
class TestShaFileByName(TestCaseInTempDir):
1461
1501
 
1462
1502
    def test_sha_empty(self):
1471
1511
        self.assertEqual(expected_sha, osutils.sha_file_by_name('foo'))
1472
1512
 
1473
1513
 
1474
 
_debug_text = \
1475
 
r'''# Copyright (C) 2005, 2006 Canonical Ltd
1476
 
#
1477
 
# This program is free software; you can redistribute it and/or modify
1478
 
# it under the terms of the GNU General Public License as published by
1479
 
# the Free Software Foundation; either version 2 of the License, or
1480
 
# (at your option) any later version.
1481
 
#
1482
 
# This program is distributed in the hope that it will be useful,
1483
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1484
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1485
 
# GNU General Public License for more details.
1486
 
#
1487
 
# You should have received a copy of the GNU General Public License
1488
 
# along with this program; if not, write to the Free Software
1489
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1490
 
 
1491
 
 
1492
 
# NOTE: If update these, please also update the help for global-options in
1493
 
#       bzrlib/help_topics/__init__.py
1494
 
 
1495
 
debug_flags = set()
1496
 
"""Set of flags that enable different debug behaviour.
1497
 
 
1498
 
These are set with eg ``-Dlock`` on the bzr command line.
1499
 
 
1500
 
Options include:
1501
 
 
1502
 
 * auth - show authentication sections used
1503
 
 * error - show stack traces for all top level exceptions
1504
 
 * evil - capture call sites that do expensive or badly-scaling operations.
1505
 
 * fetch - trace history copying between repositories
1506
 
 * graph - trace graph traversal information
1507
 
 * hashcache - log every time a working file is read to determine its hash
1508
 
 * hooks - trace hook execution
1509
 
 * hpss - trace smart protocol requests and responses
1510
 
 * http - trace http connections, requests and responses
1511
 
 * index - trace major index operations
1512
 
 * knit - trace knit operations
1513
 
 * lock - trace when lockdir locks are taken or released
1514
 
 * merge - emit information for debugging merges
1515
 
 * pack - emit information about pack operations
1516
 
 
1517
 
"""
1518
 
'''
1519
 
 
1520
 
 
1521
1514
class TestResourceLoading(TestCaseInTempDir):
1522
1515
 
1523
1516
    def test_resource_string(self):
1524
1517
        # test resource in bzrlib
1525
1518
        text = osutils.resource_string('bzrlib', 'debug.py')
1526
 
        self.assertEquals(_debug_text, text)
 
1519
        self.assertContainsRe(text, "debug_flags = set()")
1527
1520
        # test resource under bzrlib
1528
1521
        text = osutils.resource_string('bzrlib.ui', 'text.py')
1529
1522
        self.assertContainsRe(text, "class TextUIFactory")