Reimplement iteritems.
authorJelmer Vernooij <jelmer@samba.org>
Mon, 28 Oct 2013 12:40:27 +0000 (13:40 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Mon, 28 Oct 2013 12:40:27 +0000 (13:40 +0100)
dulwich/config.py
dulwich/tests/test_config.py

index 7d2c477f9fa35f493501cb3af317dd799de5d34e..a40059448c923cc1a3da439324a30fb08b48aa5c 100644 (file)
@@ -73,12 +73,21 @@ class Config(object):
     def set(self, section, name, value):
         """Set a configuration value.
 
+        :param section: Tuple with section name and optional subsection namee
         :param name: Name of the configuration value, including section
             and optional subsection
         :param: Value of the setting
         """
         raise NotImplementedError(self.set)
 
+    def iteritems(self, section):
+        """Iterate over the configuration pairs for a specific section.
+
+        :param section: Tuple with section name and optional subsection namee
+        :return: Iterator over (name, value) pairs
+        """
+        raise NotImplementedError(self.iteritems)
+
 
 class ConfigDict(Config, DictMixin):
     """Git configuration stored in a dictionary."""
@@ -129,6 +138,9 @@ class ConfigDict(Config, DictMixin):
             section = (section, )
         self._values.setdefault(section, OrderedDict())[name] = value
 
+    def iteritems(self, section):
+        return self._values.setdefault(section, OrderedDict()).iteritems()
+
 
 def _format_string(value):
     if (value.startswith(" ") or
index 7a492591669a822893a9430e879de2fc3cb47f65..2715b36f511479fbd0f3439e0047bdb178ad04fe 100644 (file)
@@ -187,10 +187,16 @@ class ConfigDictTests(TestCase):
         cd.set(("core", ), "foo", "bla")
         cd.set(("core2", ), "foo", "bloe")
 
-        self.assertEqual([
-            (('core',), OrderedDict([('foo', 'bla')])),
-            (('core2',), OrderedDict([('foo', 'bloe')]))],
-            list(cd.iteritems()))
+        self.assertEqual(
+            [('foo', 'bla')],
+            list(cd.iteritems(("core", ))))
+
+    def test_iteritems_nonexistant(self):
+        cd = ConfigDict()
+        cd.set(("core2", ), "foo", "bloe")
+
+        self.assertEqual([],
+            list(cd.iteritems(("core", ))))
 
 
 class StackedConfigTests(TestCase):