~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

Merge bzr.dev 5887, to get the update_basis_by_delta changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
test_store_builder_registry.register(
86
86
    'branch', lambda test: config.BranchStore(test.branch))
87
87
 
 
88
# FIXME: Same remark as above for the following registry -- vila 20110503
 
89
test_stack_builder_registry = registry.Registry()
 
90
test_stack_builder_registry.register(
 
91
    'bazaar', lambda test: config.GlobalStack())
 
92
test_stack_builder_registry.register(
 
93
    'location', lambda test: config.LocationStack('.'))
 
94
test_stack_builder_registry.register(
 
95
    'branch', lambda test: config.BranchStack(test.branch))
88
96
 
89
97
 
90
98
sample_long_alias="log -r-15..-1 --line"
2177
2185
        self.assertEquals(['baz', 'bar/baz'],
2178
2186
                          [section.extra_path for section in sections])
2179
2187
 
 
2188
    def test_appendpath_in_no_name_section(self):
 
2189
        # It's a bit weird to allow appendpath in a no-name section, but
 
2190
        # someone may found a use for it
 
2191
        store = self.get_store('foo.conf')
 
2192
        store._load_from_string('''
 
2193
foo=bar
 
2194
foo:policy = appendpath
 
2195
''')
 
2196
        matcher = config.LocationMatcher(store, 'dir/subdir')
 
2197
        sections = list(matcher.get_sections())
 
2198
        self.assertLength(1, sections)
 
2199
        self.assertEquals('bar/dir/subdir', sections[0].get('foo'))
 
2200
 
 
2201
    def test_file_urls_are_normalized(self):
 
2202
        store = self.get_store('foo.conf')
 
2203
        matcher = config.LocationMatcher(store, 'file:///dir/subdir')
 
2204
        self.assertEquals('/dir/subdir', matcher.location)
2180
2205
 
2181
2206
 
2182
2207
class TestStackGet(tests.TestCase):
2215
2240
        self.assertRaises(TypeError, conf_stack.get, 'foo')
2216
2241
 
2217
2242
 
2218
 
class TestStackSet(tests.TestCaseWithTransport):
2219
 
 
2220
 
    # FIXME: This should be parametrized for all known Stack or dedicated
2221
 
    # paramerized tests created to avoid bloating -- vila 2011-04-05
 
2243
class TestStackWithTransport(tests.TestCaseWithTransport):
 
2244
 
 
2245
    def setUp(self):
 
2246
        super(TestStackWithTransport, self).setUp()
 
2247
        # FIXME: A more elaborate builder for the stack would avoid building a
 
2248
        # branch even for tests that don't need it.
 
2249
        self.branch = self.make_branch('branch')
 
2250
 
 
2251
 
 
2252
class TestStackSet(TestStackWithTransport):
 
2253
 
 
2254
    scenarios = [(key, {'get_stack': builder})
 
2255
                 for key, builder in test_stack_builder_registry.iteritems()]
2222
2256
 
2223
2257
    def test_simple_set(self):
2224
 
        store = config.IniFileStore(self.get_transport(), 'test.conf')
2225
 
        store._load_from_string('foo=bar')
2226
 
        conf = config.Stack([store.get_sections], store)
 
2258
        conf = self.get_stack(self)
 
2259
        conf.store._load_from_string('foo=bar')
2227
2260
        self.assertEquals('bar', conf.get('foo'))
2228
2261
        conf.set('foo', 'baz')
2229
2262
        # Did we get it back ?
2230
2263
        self.assertEquals('baz', conf.get('foo'))
2231
2264
 
2232
2265
    def test_set_creates_a_new_section(self):
2233
 
        store = config.IniFileStore(self.get_transport(), 'test.conf')
2234
 
        conf = config.Stack([store.get_sections], store)
 
2266
        conf = self.get_stack(self)
2235
2267
        conf.set('foo', 'baz')
2236
2268
        self.assertEquals, 'baz', conf.get('foo')
2237
2269
 
2238
2270
 
2239
 
class TestStackRemove(tests.TestCaseWithTransport):
 
2271
class TestStackRemove(TestStackWithTransport):
2240
2272
 
2241
 
    # FIXME: This should be parametrized for all known Stack or dedicated
2242
 
    # paramerized tests created to avoid bloating -- vila 2011-04-06
 
2273
    scenarios = [(key, {'get_stack': builder})
 
2274
                 for key, builder in test_stack_builder_registry.iteritems()]
2243
2275
 
2244
2276
    def test_remove_existing(self):
2245
 
        store = config.IniFileStore(self.get_transport(), 'test.conf')
2246
 
        store._load_from_string('foo=bar')
2247
 
        conf = config.Stack([store.get_sections], store)
 
2277
        conf = self.get_stack(self)
 
2278
        conf.store._load_from_string('foo=bar')
2248
2279
        self.assertEquals('bar', conf.get('foo'))
2249
2280
        conf.remove('foo')
2250
2281
        # Did we get it back ?
2251
2282
        self.assertEquals(None, conf.get('foo'))
2252
2283
 
2253
2284
    def test_remove_unknown(self):
2254
 
        store = config.IniFileStore(self.get_transport(), 'test.conf')
2255
 
        conf = config.Stack([store.get_sections], store)
 
2285
        conf = self.get_stack(self)
2256
2286
        self.assertRaises(KeyError, conf.remove, 'I_do_not_exist')
2257
2287
 
2258
2288
 
 
2289
class TestConcreteStacks(TestStackWithTransport):
 
2290
 
 
2291
    scenarios = [(key, {'get_stack': builder})
 
2292
                 for key, builder in test_stack_builder_registry.iteritems()]
 
2293
 
 
2294
    def test_build_stack(self):
 
2295
        stack = self.get_stack(self)
 
2296
 
 
2297
 
2259
2298
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
2260
2299
 
2261
2300
    def setUp(self):