Rev 5765: Some minimal SectionMatcher implementation to setup the test infrastucture. in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Apr 7 10:30:46 UTC 2011


At file:///home/vila/src/bzr/experimental/config/

------------------------------------------------------------
revno: 5765
revision-id: v.ladeuil+lp at free.fr-20110407103046-2uaz8veqtsjptzof
parent: v.ladeuil+lp at free.fr-20110407092847-j0w8u1lce2forpt5
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-section-matchers
timestamp: Thu 2011-04-07 12:30:46 +0200
message:
  Some minimal SectionMatcher implementation to setup the test infrastucture.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-04-07 07:44:53 +0000
+++ b/bzrlib/config.py	2011-04-07 10:30:46 +0000
@@ -2296,6 +2296,37 @@
         super(BranchStore, self).__init__(branch.control_transport,
                                           'branch.conf')
 
+class SectionMatcher(object):
+    """Select sections into a given Store.
+
+    This intended to be used to postpone getting an iterable of sections from a
+    store.
+    """
+
+    def __init__(self, store):
+        self.store = store
+
+    def get_sections(self):
+        # This is where we requires loading the store so we can see all defined
+        # sections.
+        sections = self.store.get_sections()
+        for s in sections:
+            if self.match(s):
+                yield s
+
+    def match(self, secion):
+        raise NotImplementedError(self.match)
+
+
+class LocationMatcher(SectionMatcher):
+
+    def __init__(self, store, location=None):
+        super(LocationMatcher, self).__init__(store)
+        self.location = location
+
+    def match(self):
+        return True
+
 
 class cmd_config(commands.Command):
     __doc__ = """Display, set or remove a configuration option.

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-04-07 09:28:46 +0000
+++ b/bzrlib/tests/test_config.py	2011-04-07 10:30:46 +0000
@@ -2098,6 +2098,21 @@
         b = self.make_branch('.')
         store = config.BranchStore(b)
 
+
+class TestSectionMatcher(TestStore):
+
+    scenarios = [('location', {'matcher': config.LocationMatcher})]
+
+    def get_store(self, file_name, content=None):
+        return get_ConfigObjStore(
+            self.get_readonly_transport(), file_name, content=content)
+
+    def test_no_matches_for_empty_stores(self):
+        store = self.get_store('foo.conf', '')
+        matcher = self.matcher(store)
+        self.assertEquals([], list(matcher.get_sections()))
+
+
 class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
 
     def setUp(self):



More information about the bazaar-commits mailing list