瀏覽代碼

Allow overwriting id property of objects in test utils.

Dave Borowitz 14 年之前
父節點
當前提交
11a5f9001d
共有 3 個文件被更改,包括 19 次插入2 次删除
  1. 2 0
      NEWS
  2. 7 0
      dulwich/tests/test_objects.py
  3. 10 2
      dulwich/tests/utils.py

+ 2 - 0
NEWS

@@ -41,6 +41,8 @@
 
   * Refactor some of dulwich.tests.compat.server_utils. (Dave Borowitz)
 
+  * Allow overwriting id property of objects in test utils. (Dave Borowitz)
+
  API CHANGES
 
   * ObjectStore.iter_tree_contents now walks contents in depth-first, sorted

+ 7 - 0
dulwich/tests/test_objects.py

@@ -234,6 +234,13 @@ class BlobReadTests(TestCase):
         self.assertEqual(c.author_timezone, 0)
         self.assertEqual(c.message, 'Merge ../b\n')
 
+    def test_stub_sha(self):
+        sha = '5' * 40
+        c = make_commit(id=sha, message='foo')
+        self.assertTrue(isinstance(c, Commit))
+        self.assertEqual(sha, c.id)
+        self.assertNotEqual(sha, c._make_sha())
+
 
 class ShaFileCheckTests(TestCase):
 

+ 10 - 2
dulwich/tests/utils.py

@@ -26,7 +26,10 @@ import shutil
 import tempfile
 import time
 
-from dulwich.objects import Commit
+from dulwich.objects import (
+    FixedSha,
+    Commit,
+    )
 from dulwich.repo import Repo
 
 
@@ -75,7 +78,12 @@ def make_object(cls, **attrs):
 
     obj = TestObject()
     for name, value in attrs.iteritems():
-        setattr(obj, name, value)
+        if name == 'id':
+            # id property is read-only, so we overwrite sha instead.
+            sha = FixedSha(value)
+            obj.sha = lambda: sha
+        else:
+            setattr(obj, name, value)
     return obj