Rev 5773: Parametrize the generic tests against the concrete stores. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Apr 12 11:21:07 UTC 2011
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5773
revision-id: v.ladeuil+lp at free.fr-20110412112107-8b1m8nlhjjep7xet
parent: v.ladeuil+lp at free.fr-20110412085920-pg10igf3pwkr0tl8
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-concrete-stores
timestamp: Tue 2011-04-12 13:21:07 +0200
message:
Parametrize the generic tests against the concrete stores.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-04-12 08:59:20 +0000
+++ b/bzrlib/config.py 2011-04-12 11:21:07 +0000
@@ -2162,6 +2162,9 @@
def save(self):
raise NotImplementedError(self.save)
+ def external_url(self):
+ raise NotImplementedError(self.external_url)
+
def get_sections(self):
"""Returns an ordered iterable of existing sections.
@@ -2219,14 +2222,7 @@
self._config_obj = ConfigObj(co_input, encoding='utf-8')
except configobj.ConfigObjError, e:
self._config_obj = None
- # FIXME: external_url should really accepts an optional relpath
- # parameter (bug #750169) :-/ -- vila 2011-04-04
- # The following will do in the interim but maybe we don't want to
- # expose a path here but rather a config ID and its associated
- # object </hand wawe>.
- file_path = os.path.join(self.transport.external_url(),
- self.file_name)
- raise errors.ParseConfigError(e.errors, file_path)
+ raise errors.ParseConfigError(e.errors, self.external_url())
def save(self):
if not self.loaded:
@@ -2236,6 +2232,14 @@
self._config_obj.write(out)
self.transport.put_bytes(self.file_name, out.getvalue())
+ def external_url(self):
+ # FIXME: external_url should really accepts an optional relpath
+ # parameter (bug #750169) :-/ -- vila 2011-04-04
+ # The following will do in the interim but maybe we don't want to
+ # expose a path here but rather a config ID and its associated
+ # object </hand wawe>.
+ return os.path.join(self.transport.external_url(), self.file_name)
+
def get_sections(self):
"""Get the configobj section in the file order.
@@ -2323,7 +2327,7 @@
def __init__(self, possible_transports=None):
t = transport.get_transport(config_dir(),
possible_transports=possible_transports)
- super(LocationStore, self).__init__(transport, 'locations.conf')
+ super(LocationStore, self).__init__(t, 'locations.conf')
class BranchStore(ConfigObjStore):
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-04-12 08:59:20 +0000
+++ b/bzrlib/tests/test_config.py 2011-04-12 11:21:07 +0000
@@ -36,6 +36,7 @@
mergetools,
ui,
urlutils,
+ registry,
tests,
trace,
transport,
@@ -62,6 +63,23 @@
load_tests = scenarios.load_tests_apply_scenarios
+# We need adpaters that can build a config store in a test context. Test
+# classes, based on TestCaseWithTransport, can use the registry to parametrize
+# themselves. The builder will receive a test instance and should return a
+# ready-to-use store. Plugins that defines new stores can also register
+# themselves here to be tested against the tests defined below.
+test_store_builder_registry = registry.Registry()
+test_store_builder_registry.register(
+ 'configobj', lambda test: config.ConfigObjStore(test.get_transport(),
+ 'configobj.conf'))
+test_store_builder_registry.register(
+ 'bazaar', lambda test: config.GlobalStore())
+test_store_builder_registry.register(
+ 'location', lambda test: config.LocationStore())
+test_store_builder_registry.register(
+ 'branch', lambda test: config.BranchStore(test.branch))
+
+
sample_long_alias="log -r-15..-1 --line"
sample_config_text = u"""
@@ -1921,101 +1939,120 @@
class TestReadonlyStore(TestStore):
- scenarios = [('configobj', {'_get_store': get_ConfigObjStore})]
-
- def get_store(self, file_name, content=None):
- return self._get_store(
- self.get_readonly_transport(), file_name, content=content)
-
- def test_delayed_load(self):
- self.build_tree_contents([('foo.conf', '')])
- store = self.get_store('foo.conf')
+ scenarios = [(key, {'get_store': builder})
+ for key, builder in test_store_builder_registry.iteritems()]
+
+ def setUp(self):
+ super(TestReadonlyStore, self).setUp()
+ self.branch = self.make_branch('branch')
+
+ def test_building_delays_load(self):
+ store = self.get_store(self)
self.assertEquals(False, store.loaded)
- store.load()
+ store._load_from_string('')
self.assertEquals(True, store.loaded)
def test_get_no_sections_for_empty(self):
- store = self.get_store('foo.conf', '')
- store.load()
+ store = self.get_store(self)
+ store._load_from_string('')
self.assertEquals([], list(store.get_sections()))
def test_get_default_section(self):
- store = self.get_store('foo.conf', 'foo=bar')
+ store = self.get_store(self)
+ store._load_from_string('foo=bar')
sections = list(store.get_sections())
self.assertLength(1, sections)
self.assertSectionContent((None, {'foo': 'bar'}), sections[0])
def test_get_named_section(self):
- store = self.get_store('foo.conf', '[baz]\nfoo=bar')
+ store = self.get_store(self)
+ store._load_from_string('[baz]\nfoo=bar')
sections = list(store.get_sections())
self.assertLength(1, sections)
self.assertSectionContent(('baz', {'foo': 'bar'}), sections[0])
def test_load_from_string_fails_for_non_empty_store(self):
- store = self.get_store('foo.conf', 'foo=bar')
+ store = self.get_store(self)
+ store._load_from_string('foo=bar')
self.assertRaises(AssertionError, store._load_from_string, 'bar=baz')
class TestMutableStore(TestStore):
- scenarios = [('configobj', {'_get_store': get_ConfigObjStore})]
-
- def get_store(self, file_name, content=None):
- return self._get_store(
- self.get_transport(), file_name, content=content)
+ scenarios = [(key, {'store_id': key, 'get_store': builder})
+ for key, builder in test_store_builder_registry.iteritems()]
+
+ def setUp(self):
+ super(TestMutableStore, self).setUp()
+ self.transport = self.get_transport()
+ self.branch = self.make_branch('branch')
+
+ def has_store(self, store):
+ store_basename = urlutils.relative_url(self.transport.external_url(),
+ store.external_url())
+ return self.transport.has(store_basename)
def test_save_empty_creates_no_file(self):
- store = self.get_store('foo.conf')
+ if self.store_id == 'branch':
+ raise tests.TestNotApplicable(
+ 'branch.conf is *always* created when a branch is initialized')
+ store = self.get_store(self)
store.save()
- self.assertEquals(False, self.get_transport().has('foo.conf'))
+ self.assertEquals(False, self.has_store(store))
def test_save_emptied_succeeds(self):
- store = self.get_store('foo.conf', 'foo=bar\n')
+ store = self.get_store(self)
+ store._load_from_string('foo=bar\n')
section = store.get_mutable_section(None)
section.remove('foo')
store.save()
- self.assertEquals(True, self.get_transport().has('foo.conf'))
- modified_store = self.get_store('foo.conf')
+ self.assertEquals(True, self.has_store(store))
+ modified_store = self.get_store(self)
sections = list(modified_store.get_sections())
self.assertLength(0, sections)
def test_save_with_content_succeeds(self):
- store = self.get_store('foo.conf', 'foo=bar\n')
- store.load()
- self.assertEquals(False, self.get_transport().has('foo.conf'))
+ if self.store_id == 'branch':
+ raise tests.TestNotApplicable(
+ 'branch.conf is *always* created when a branch is initialized')
+ store = self.get_store(self)
+ store._load_from_string('foo=bar\n')
+ self.assertEquals(False, self.has_store(store))
store.save()
- self.assertEquals(True, self.get_transport().has('foo.conf'))
- modified_store = self.get_store('foo.conf')
+ self.assertEquals(True, self.has_store(store))
+ modified_store = self.get_store(self)
sections = list(modified_store.get_sections())
self.assertLength(1, sections)
self.assertSectionContent((None, {'foo': 'bar'}), sections[0])
def test_set_option_in_empty_store(self):
- store = self.get_store('foo.conf')
+ store = self.get_store(self)
section = store.get_mutable_section(None)
section.set('foo', 'bar')
store.save()
- modified_store = self.get_store('foo.conf')
+ modified_store = self.get_store(self)
sections = list(modified_store.get_sections())
self.assertLength(1, sections)
self.assertSectionContent((None, {'foo': 'bar'}), sections[0])
def test_set_option_in_default_section(self):
- store = self.get_store('foo.conf', '')
+ store = self.get_store(self)
+ store._load_from_string('')
section = store.get_mutable_section(None)
section.set('foo', 'bar')
store.save()
- modified_store = self.get_store('foo.conf')
+ modified_store = self.get_store(self)
sections = list(modified_store.get_sections())
self.assertLength(1, sections)
self.assertSectionContent((None, {'foo': 'bar'}), sections[0])
def test_set_option_in_named_section(self):
- store = self.get_store('foo.conf', '')
+ store = self.get_store(self)
+ store._load_from_string('')
section = store.get_mutable_section('baz')
section.set('foo', 'bar')
store.save()
- modified_store = self.get_store('foo.conf')
+ modified_store = self.get_store(self)
sections = list(modified_store.get_sections())
self.assertLength(1, sections)
self.assertSectionContent(('baz', {'foo': 'bar'}), sections[0])
More information about the bazaar-commits
mailing list