~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    errors,
30
30
    osutils,
31
31
    tests,
 
32
    trace,
32
33
    win32utils,
33
34
    )
34
35
from bzrlib.tests import (
446
447
    def test_canonical_relpath_simple(self):
447
448
        f = file('MixedCaseName', 'w')
448
449
        f.close()
449
 
        # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
450
 
        real_base_dir = osutils.realpath(self.test_base_dir)
451
 
        actual = osutils.canonical_relpath(real_base_dir, 'mixedcasename')
 
450
        actual = osutils.canonical_relpath(self.test_base_dir, 'mixedcasename')
452
451
        self.failUnlessEqual('work/MixedCaseName', actual)
453
452
 
454
453
    def test_canonical_relpath_missing_tail(self):
455
454
        os.mkdir('MixedCaseParent')
456
 
        # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
457
 
        real_base_dir = osutils.realpath(self.test_base_dir)
458
 
        actual = osutils.canonical_relpath(real_base_dir,
 
455
        actual = osutils.canonical_relpath(self.test_base_dir,
459
456
                                           'mixedcaseparent/nochild')
460
457
        self.failUnlessEqual('work/MixedCaseParent/nochild', actual)
461
458
 
462
459
 
 
460
class Test_CICPCanonicalRelpath(tests.TestCaseWithTransport):
 
461
 
 
462
    def assertRelpath(self, expected, base, path):
 
463
        actual = osutils._cicp_canonical_relpath(base, path)
 
464
        self.assertEqual(expected, actual)
 
465
 
 
466
    def test_simple(self):
 
467
        self.build_tree(['MixedCaseName'])
 
468
        base = osutils.realpath(self.get_transport('.').local_abspath('.'))
 
469
        self.assertRelpath('MixedCaseName', base, 'mixedcAsename')
 
470
 
 
471
    def test_subdir_missing_tail(self):
 
472
        self.build_tree(['MixedCaseParent/', 'MixedCaseParent/a_child'])
 
473
        base = osutils.realpath(self.get_transport('.').local_abspath('.'))
 
474
        self.assertRelpath('MixedCaseParent/a_child', base,
 
475
                           'MixedCaseParent/a_child')
 
476
        self.assertRelpath('MixedCaseParent/a_child', base,
 
477
                           'MixedCaseParent/A_Child')
 
478
        self.assertRelpath('MixedCaseParent/not_child', base,
 
479
                           'MixedCaseParent/not_child')
 
480
 
 
481
    def test_at_root_slash(self):
 
482
        # We can't test this on Windows, because it has a 'MIN_ABS_PATHLENGTH'
 
483
        # check...
 
484
        if osutils.MIN_ABS_PATHLENGTH > 1:
 
485
            raise tests.TestSkipped('relpath requires %d chars'
 
486
                                    % osutils.MIN_ABS_PATHLENGTH)
 
487
        self.assertRelpath('foo', '/', '/foo')
 
488
 
 
489
    def test_at_root_drive(self):
 
490
        if sys.platform != 'win32':
 
491
            raise tests.TestNotApplicable('we can only test drive-letter relative'
 
492
                                          ' paths on Windows where we have drive'
 
493
                                          ' letters.')
 
494
        # see bug #322807
 
495
        # The specific issue is that when at the root of a drive, 'abspath'
 
496
        # returns "C:/" or just "/". However, the code assumes that abspath
 
497
        # always returns something like "C:/foo" or "/foo" (no trailing slash).
 
498
        self.assertRelpath('foo', 'C:/', 'C:/foo')
 
499
        self.assertRelpath('foo', 'X:/', 'X:/foo')
 
500
        self.assertRelpath('foo', 'X:/', 'X://foo')
 
501
 
 
502
 
463
503
class TestPumpFile(tests.TestCase):
464
504
    """Test pumpfile method."""
465
505
 
1798
1838
    def test_local_concurrency(self):
1799
1839
        concurrency = osutils.local_concurrency()
1800
1840
        self.assertIsInstance(concurrency, int)
 
1841
 
 
1842
 
 
1843
class TestFailedToLoadExtension(tests.TestCase):
 
1844
 
 
1845
    def _try_loading(self):
 
1846
        try:
 
1847
            import bzrlib._fictional_extension_py
 
1848
        except ImportError, e:
 
1849
            osutils.failed_to_load_extension(e)
 
1850
            return True
 
1851
 
 
1852
    def setUp(self):
 
1853
        super(TestFailedToLoadExtension, self).setUp()
 
1854
        self.saved_failures = osutils._extension_load_failures[:]
 
1855
        del osutils._extension_load_failures[:]
 
1856
        self.addCleanup(self.restore_failures)
 
1857
 
 
1858
    def restore_failures(self):
 
1859
        osutils._extension_load_failures = self.saved_failures
 
1860
 
 
1861
    def test_failure_to_load(self):
 
1862
        self._try_loading()
 
1863
        self.assertLength(1, osutils._extension_load_failures)
 
1864
        self.assertEquals(osutils._extension_load_failures[0],
 
1865
            "No module named _fictional_extension_py")
 
1866
 
 
1867
    def test_report_extension_load_failures_no_warning(self):
 
1868
        self.assertTrue(self._try_loading())
 
1869
        warnings, result = self.callCatchWarnings(osutils.report_extension_load_failures)
 
1870
        # it used to give a Python warning; it no longer does
 
1871
        self.assertLength(0, warnings)
 
1872
 
 
1873
    def test_report_extension_load_failures_message(self):
 
1874
        log = StringIO()
 
1875
        trace.push_log_file(log)
 
1876
        self.assertTrue(self._try_loading())
 
1877
        osutils.report_extension_load_failures()
 
1878
        self.assertContainsRe(
 
1879
            log.getvalue(),
 
1880
            r"bzr: warning: some compiled extensions could not be loaded; "
 
1881
            "see <https://answers\.launchpad\.net/bzr/\+faq/703>\n"
 
1882
            )