dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00175
[PATCH 01/10] Allow overwriting id property of objects in test utils.
From: Dave Borowitz <dborowitz@xxxxxxxxxx>
Change-Id: I1f2da810b6466575bf82c0cbadaf3f844a0244cc
---
NEWS | 2 ++
dulwich/tests/test_objects.py | 7 +++++++
dulwich/tests/utils.py | 12 ++++++++++--
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index 603d8da..14e067c 100644
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,8 @@
* New tests in test_web with better coverage and fewer ad-hoc mocks.
(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
diff --git a/dulwich/tests/test_objects.py b/dulwich/tests/test_objects.py
index 839e097..a152166 100644
--- a/dulwich/tests/test_objects.py
+++ b/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):
diff --git a/dulwich/tests/utils.py b/dulwich/tests/utils.py
index f581a12..8df2a83 100644
--- a/dulwich/tests/utils.py
+++ b/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
--
1.7.1
Follow ups
References