summaryrefslogtreecommitdiff
path: root/test/test_reflog.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-11-23 15:49:29 +0100
committerSebastian Thiel <byronimo@gmail.com>2010-11-23 15:49:29 +0100
commita93eb7e8484e5bb40f9b8d11ac64a1621cf4c9cd (patch)
tree45b2b930b650980877c6eab970281045916c9c4a /test/test_reflog.py
parent6e5aae2fc8c3832bdae1cd5e0a269405fb059231 (diff)
downloadgitpython-a93eb7e8484e5bb40f9b8d11ac64a1621cf4c9cd.tar.gz
Implemented reflog reading and writing
Diffstat (limited to 'test/test_reflog.py')
-rw-r--r--test/test_reflog.py46
1 files changed, 44 insertions, 2 deletions
diff --git a/test/test_reflog.py b/test/test_reflog.py
index efcc7f33..a017106e 100644
--- a/test/test_reflog.py
+++ b/test/test_reflog.py
@@ -2,6 +2,10 @@ from git.test.lib import *
from git.objects import IndexObject, Actor
from git.refs import *
+import tempfile
+import shutil
+import os
+
class TestRefLog(TestBase):
def test_reflogentry(self):
@@ -24,9 +28,47 @@ class TestRefLog(TestBase):
assert repr(e).startswith(nullhexsha)
def test_base(self):
- pass
+ rlp_head = fixture_path('reflog_HEAD')
+ rlp_master = fixture_path('reflog_master')
+ tdir = tempfile.mktemp(suffix="test_reflogs")
+ os.mkdir(tdir)
+
+ # verify we have a ref - with the creation of a new ref, the reflog
+ # will be created as well
+ rlp_master_ro = RefLog.path(self.rorepo.heads.master)
+ assert os.path.isfile(rlp_master_ro)
+
+ # simple read
+ reflog = RefLog.from_file(rlp_master_ro)
+ assert isinstance(reflog, RefLog)
+ assert len(reflog)
+
+ # iter_entries works with path and with stream
+ assert len(list(RefLog.iter_entries(open(rlp_master))))
+ assert len(list(RefLog.iter_entries(rlp_master)))
+
# raise on invalid revlog
# TODO: Try multiple corrupted ones !
-
+ pp = 'reflog_invalid_'
+ for suffix in ('oldsha', 'newsha', 'email', 'date', 'sep'):
+ self.failUnlessRaises(ValueError, RefLog.from_file, fixture_path(pp+suffix))
+ #END for each invalid file
+
# test serialize and deserialize - results must match exactly
+ for rlp in (rlp_head, rlp_master):
+ reflog = RefLog.from_file(rlp)
+ tfile = os.path.join(tdir, os.path.basename(rlp))
+ reflog.to_file(tfile)
+
+ # parsed result must match ...
+ treflog = RefLog.from_file(tfile)
+ assert treflog == reflog
+
+ # ... as well as each bytes of the written stream
+ assert open(tfile).read() == open(rlp).read()
+ # END for each reflog
+
+
+ # finally remove our temporary data
+ shutil.rmtree(tdir)