~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

merge in trunk and i18n-errors

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    errors,
34
34
    osutils,
35
35
    mail_client,
36
 
    mergetools,
37
36
    ui,
38
37
    urlutils,
39
 
    registry,
40
38
    remote,
41
39
    tests,
42
40
    trace,
43
 
    transport,
44
41
    )
45
42
from bzrlib.symbol_versioning import (
46
43
    deprecated_in,
47
 
    deprecated_method,
48
44
    )
49
45
from bzrlib.transport import remote as transport_remote
50
46
from bzrlib.tests import (
1968
1964
        conf = config.TransportConfig(t, 'foo.conf')
1969
1965
        self.assertRaises(errors.ParseConfigError, conf._get_configobj)
1970
1966
 
 
1967
    def test_load_permission_denied(self):
 
1968
        """Ensure we get an empty config file if the file is inaccessible."""
 
1969
        warnings = []
 
1970
        def warning(*args):
 
1971
            warnings.append(args[0] % args[1:])
 
1972
        self.overrideAttr(trace, 'warning', warning)
 
1973
 
 
1974
        class DenyingTransport(object):
 
1975
 
 
1976
            def __init__(self, base):
 
1977
                self.base = base
 
1978
 
 
1979
            def get_bytes(self, relpath):
 
1980
                raise errors.PermissionDenied(relpath, "")
 
1981
 
 
1982
        cfg = config.TransportConfig(
 
1983
            DenyingTransport("nonexisting://"), 'control.conf')
 
1984
        self.assertIs(None, cfg.get_option('non-existant', 'SECTION'))
 
1985
        self.assertEquals(
 
1986
            warnings,
 
1987
            [u'Permission denied while trying to open configuration file '
 
1988
             u'nonexisting:///control.conf.'])
 
1989
 
1971
1990
    def test_get_value(self):
1972
1991
        """Test that retreiving a value from a section is possible"""
1973
1992
        bzrdir_config = config.TransportConfig(self.get_transport('.'),
2584
2603
        store = config.IniFileStore(t, 'foo.conf')
2585
2604
        self.assertRaises(errors.ParseConfigError, store.load)
2586
2605
 
 
2606
    def test_load_permission_denied(self):
 
2607
        """Ensure we get warned when trying to load an inaccessible file."""
 
2608
        warnings = []
 
2609
        def warning(*args):
 
2610
            warnings.append(args[0] % args[1:])
 
2611
        self.overrideAttr(trace, 'warning', warning)
 
2612
 
 
2613
        t = self.get_transport()
 
2614
 
 
2615
        def get_bytes(relpath):
 
2616
            raise errors.PermissionDenied(relpath, "")
 
2617
        t.get_bytes = get_bytes
 
2618
        store = config.IniFileStore(t, 'foo.conf')
 
2619
        self.assertRaises(errors.PermissionDenied, store.load)
 
2620
        self.assertEquals(
 
2621
            warnings,
 
2622
            [u'Permission denied while trying to load configuration store %s.'
 
2623
             % store.external_url()])
 
2624
 
2587
2625
 
2588
2626
class TestIniConfigContent(tests.TestCaseWithTransport):
2589
2627
    """Simulate loading a IniBasedConfig without content of various encodings.