~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Shannon Weyrick
  • Date: 2011-11-04 13:40:04 UTC
  • mfrom: (6238 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6256.
  • Revision ID: weyrick@mozek.us-20111104134004-033t2wqhc3ydzm0a
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
3107
3107
    scenarios = [('location', {'matcher': config.LocationMatcher}),
3108
3108
                 ('id', {'matcher': config.NameMatcher}),]
3109
3109
 
3110
 
    def get_store(self, file_name):
3111
 
        return config.IniFileStore(self.get_readonly_transport(), file_name)
 
3110
    def setUp(self):
 
3111
        super(TestSectionMatcher, self).setUp()
 
3112
        # Any simple store is good enough
 
3113
        self.get_store = config.test_store_builder_registry.get('configobj')
3112
3114
 
3113
3115
    def test_no_matches_for_empty_stores(self):
3114
 
        store = self.get_store('foo.conf')
 
3116
        store = self.get_store(self)
3115
3117
        store._load_from_string('')
3116
3118
        matcher = self.matcher(store, '/bar')
3117
3119
        self.assertEquals([], list(matcher.get_sections()))
3118
3120
 
3119
3121
    def test_build_doesnt_load_store(self):
3120
 
        store = self.get_store('foo.conf')
 
3122
        store = self.get_store(self)
3121
3123
        matcher = self.matcher(store, '/bar')
3122
3124
        self.assertFalse(store.is_loaded())
3123
3125
 
3147
3149
 
3148
3150
class TestLocationMatcher(TestStore):
3149
3151
 
3150
 
    def get_store(self, file_name):
3151
 
        return config.IniFileStore(self.get_readonly_transport(), file_name)
 
3152
    def setUp(self):
 
3153
        super(TestLocationMatcher, self).setUp()
 
3154
        # Any simple store is good enough
 
3155
        self.get_store = config.test_store_builder_registry.get('configobj')
3152
3156
 
3153
3157
    def test_unrelated_section_excluded(self):
3154
 
        store = self.get_store('foo.conf')
 
3158
        store = self.get_store(self)
3155
3159
        store._load_from_string('''
3156
3160
[/foo]
3157
3161
section=/foo
3177
3181
                          [section.extra_path for section in sections])
3178
3182
 
3179
3183
    def test_more_specific_sections_first(self):
3180
 
        store = self.get_store('foo.conf')
 
3184
        store = self.get_store(self)
3181
3185
        store._load_from_string('''
3182
3186
[/foo]
3183
3187
section=/foo
3198
3202
    def test_appendpath_in_no_name_section(self):
3199
3203
        # It's a bit weird to allow appendpath in a no-name section, but
3200
3204
        # someone may found a use for it
3201
 
        store = self.get_store('foo.conf')
 
3205
        store = self.get_store(self)
3202
3206
        store._load_from_string('''
3203
3207
foo=bar
3204
3208
foo:policy = appendpath
3209
3213
        self.assertEquals('bar/dir/subdir', sections[0].get('foo'))
3210
3214
 
3211
3215
    def test_file_urls_are_normalized(self):
3212
 
        store = self.get_store('foo.conf')
 
3216
        store = self.get_store(self)
3213
3217
        if sys.platform == 'win32':
3214
3218
            expected_url = 'file:///C:/dir/subdir'
3215
3219
            expected_location = 'C:/dir/subdir'
3224
3228
 
3225
3229
    def setUp(self):
3226
3230
        super(TestNameMatcher, self).setUp()
3227
 
        self.store = config.IniFileStore(self.get_readonly_transport(),
3228
 
                                         'foo.conf')
3229
 
        self.store._load_from_string('''
 
3231
        self.matcher = config.NameMatcher
 
3232
        # Any simple store is good enough
 
3233
        self.get_store = config.test_store_builder_registry.get('configobj')
 
3234
 
 
3235
    def get_matching_sections(self, name):
 
3236
        store = self.get_store(self)
 
3237
        store._load_from_string('''
3230
3238
[foo]
3231
3239
option=foo
3232
3240
[foo/baz]
3234
3242
[bar]
3235
3243
option=bar
3236
3244
''')
3237
 
 
3238
 
    def get_matching_sections(self, name):
3239
 
        matcher = config.NameMatcher(self.store, name)
 
3245
        matcher = self.matcher(store, name)
3240
3246
        return list(matcher.get_sections())
3241
3247
 
3242
3248
    def test_matching(self):
3632
3638
 
3633
3639
    def test_remove_existing(self):
3634
3640
        conf = self.get_stack(self)
3635
 
        conf.store._load_from_string('foo=bar')
 
3641
        conf.set('foo', 'bar')
3636
3642
        self.assertEquals('bar', conf.get('foo'))
3637
3643
        conf.remove('foo')
3638
3644
        # Did we get it back ?
3649
3655
        config.ConfigHooks.install_named_hook('remove', hook, None)
3650
3656
        self.assertLength(0, calls)
3651
3657
        conf = self.get_stack(self)
3652
 
        conf.store._load_from_string('foo=bar')
 
3658
        conf.set('foo', 'bar')
3653
3659
        conf.remove('foo')
3654
3660
        self.assertLength(1, calls)
3655
3661
        self.assertEquals((conf, 'foo'), calls[0])