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))
98
90
sample_long_alias="log -r-15..-1 --line"
2185
2177
self.assertEquals(['baz', 'bar/baz'],
2186
2178
[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)
2207
2182
class TestStackGet(tests.TestCase):
2240
2215
self.assertRaises(TypeError, conf_stack.get, 'foo')
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()]
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
2257
2223
def test_simple_set(self):
2258
conf = self.get_stack(self)
2259
conf.store._load_from_string('foo=bar')
2224
store = config.IniFileStore(self.get_transport(), 'test.conf')
2225
store._load_from_string('foo=bar')
2226
conf = config.Stack([store.get_sections], store)
2260
2227
self.assertEquals('bar', conf.get('foo'))
2261
2228
conf.set('foo', 'baz')
2262
2229
# Did we get it back ?
2263
2230
self.assertEquals('baz', conf.get('foo'))
2265
2232
def test_set_creates_a_new_section(self):
2266
conf = self.get_stack(self)
2233
store = config.IniFileStore(self.get_transport(), 'test.conf')
2234
conf = config.Stack([store.get_sections], store)
2267
2235
conf.set('foo', 'baz')
2268
2236
self.assertEquals, 'baz', conf.get('foo')
2271
class TestStackRemove(TestStackWithTransport):
2239
class TestStackRemove(tests.TestCaseWithTransport):
2273
scenarios = [(key, {'get_stack': builder})
2274
for key, builder in test_stack_builder_registry.iteritems()]
2241
# FIXME: This should be parametrized for all known Stack or dedicated
2242
# paramerized tests created to avoid bloating -- vila 2011-04-06
2276
2244
def test_remove_existing(self):
2277
conf = self.get_stack(self)
2278
conf.store._load_from_string('foo=bar')
2245
store = config.IniFileStore(self.get_transport(), 'test.conf')
2246
store._load_from_string('foo=bar')
2247
conf = config.Stack([store.get_sections], store)
2279
2248
self.assertEquals('bar', conf.get('foo'))
2280
2249
conf.remove('foo')
2281
2250
# Did we get it back ?
2282
2251
self.assertEquals(None, conf.get('foo'))
2284
2253
def test_remove_unknown(self):
2285
conf = self.get_stack(self)
2254
store = config.IniFileStore(self.get_transport(), 'test.conf')
2255
conf = config.Stack([store.get_sections], store)
2286
2256
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)
2298
2259
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
2300
2261
def setUp(self):