Browse Source

Add basic test for parsing commit objects.

Jelmer Vernooij 15 years ago
parent
commit
4e50426fb7
2 changed files with 30 additions and 7 deletions
  1. 7 7
      dulwich/objects.py
  2. 23 0
      dulwich/tests/test_objects.py

+ 7 - 7
dulwich/objects.py

@@ -205,6 +205,13 @@ class ShaFile(object):
         obj.set_raw_string(string)
         return obj
 
+    @classmethod
+    def from_string(cls, string):
+        """Create a blob from a string."""
+        shafile = cls()
+        shafile.set_raw_string(string)
+        return shafile
+
     def _header(self):
         return "%s %lu\0" % (self._type, len(self.as_raw_string()))
 
@@ -267,13 +274,6 @@ class Blob(ShaFile):
             raise NotBlobError(filename)
         return blob
 
-    @classmethod
-    def from_string(cls, string):
-        """Create a blob from a string."""
-        shafile = cls()
-        shafile.set_raw_string(string)
-        return shafile
-
 
 class Tag(ShaFile):
     """A Git Tag object."""

+ 23 - 0
dulwich/tests/test_objects.py

@@ -203,6 +203,29 @@ class CommitSerializationTests(unittest.TestCase):
         self.assertTrue(" -0100\n" in c.as_raw_string())
 
 
+class CommitDeserializationTests(unittest.TestCase):
+
+    def test_simple(self):
+        c = Commit.from_string(
+                'tree d80c186a03f423a81b39df39dc87fd269736ca86\n'
+                'parent ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd\n'
+                'parent 4cffe90e0a41ad3f5190079d7c8f036bde29cbe6\n'
+                'author James Westby <jw+debian@jameswestby.net> 1174773719 +0000\n'
+                'committer James Westby <jw+debian@jameswestby.net> 1174773719 +0000\n'
+                '\n'
+                'Merge ../b\n')
+        self.assertEquals('Merge ../b\n', c.message)
+        self.assertEquals('James Westby <jw+debian@jameswestby.net>',
+            c.author)
+        self.assertEquals('James Westby <jw+debian@jameswestby.net>',
+            c.committer)
+        self.assertEquals('d80c186a03f423a81b39df39dc87fd269736ca86',
+            c.tree)
+        self.assertEquals(['ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd',
+                          '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6'],
+            c.parents)
+
+
 class TreeSerializationTests(unittest.TestCase):
 
     def test_simple(self):