85
85
test_store_builder_registry.register(
86
86
'branch', lambda test: config.BranchStore(test.branch))
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))
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])
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('''
2194
foo:policy = appendpath
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'))
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)
2182
2207
class TestStackGet(tests.TestCase):
2215
2240
self.assertRaises(TypeError, conf_stack.get, 'foo')
2218
class TestStackSet(tests.TestCaseWithTransport):
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):
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')
2252
class TestStackSet(TestStackWithTransport):
2254
scenarios = [(key, {'get_stack': builder})
2255
for key, builder in test_stack_builder_registry.iteritems()]
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'))
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')
2239
class TestStackRemove(tests.TestCaseWithTransport):
2271
class TestStackRemove(TestStackWithTransport):
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()]
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'))
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')
2289
class TestConcreteStacks(TestStackWithTransport):
2291
scenarios = [(key, {'get_stack': builder})
2292
for key, builder in test_stack_builder_registry.iteritems()]
2294
def test_build_stack(self):
2295
stack = self.get_stack(self)
2259
2298
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
2261
2300
def setUp(self):