Add Tree.__iter__.
authorJelmer Vernooij <jelmer@samba.org>
Thu, 8 Apr 2010 20:01:45 +0000 (22:01 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 8 Apr 2010 20:01:45 +0000 (22:01 +0200)
dulwich/objects.py
dulwich/tests/test_objects.py

index 41b49056e7b81cafdbb11d0fedb0132283729d50..7b46777599a3dbc0f0d65f0c769c682d6acb9605 100644 (file)
@@ -600,6 +600,10 @@ class Tree(ShaFile):
         self._ensure_parsed()
         return len(self._entries)
 
+    def __iter__(self):
+        self._ensure_parsed()
+        return iter(self._entries)
+
     def add(self, mode, name, hexsha):
         assert type(mode) == int
         assert type(name) == str
index 667be3d1e436406328b39be729ca308d344894fd..50cd1b9b4473e97735fce6e661eff13e6058ce19 100644 (file)
@@ -387,6 +387,11 @@ class TreeTests(ShaFileCheckTests):
         self.assertCheckFails(t, '100644 a\0%s\n100755 a\0%s' % (sha, sha2))
         self.assertCheckFails(t, '100644 b\0%s\n100644 a\0%s' % (sha2, sha))
 
+    def test_iter(self):
+        t = Tree()
+        t["foo"] = (0100644, a_sha)
+        self.assertEquals(set(["foo"]), set(t))
+
 
 class TagSerializeTests(unittest.TestCase):