Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork966
Expand file tree
/
Copy pathtest_reflog.py
More file actions
101 lines (79 loc) · 3.48 KB
/
test_reflog.py
File metadata and controls
101 lines (79 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
importos.pathasosp
importtempfile
fromgit.objectsimportIndexObject
fromgit.refsimportRefLog,RefLogEntry
fromgit.utilimportActor,hex_to_bin,rmtree
fromtest.libimportTestBase,fixture_path
classTestRefLog(TestBase):
deftest_reflogentry(self):
nullhexsha=IndexObject.NULL_HEX_SHA
hexsha="F"*40
actor=Actor("name","email")
msg="message"
self.assertRaises(ValueError,RefLogEntry.new,nullhexsha,hexsha,"noactor",0,0,"")
e=RefLogEntry.new(nullhexsha,hexsha,actor,0,1,msg)
asserte.oldhexsha==nullhexsha
asserte.newhexsha==hexsha
asserte.actor==actor
asserte.time[0]==0
asserte.time[1]==1
asserte.message==msg
# Check representation (roughly).
assertrepr(e).startswith(nullhexsha)
deftest_base(self):
rlp_head=fixture_path("reflog_HEAD")
rlp_master=fixture_path("reflog_master")
tdir=tempfile.mkdtemp(suffix="test_reflogs")
rlp_master_ro=RefLog.path(self.rorepo.head)
assertosp.isfile(rlp_master_ro)
# Simple read.
reflog=RefLog.from_file(rlp_master_ro)
assertreflog._pathisnotNone
assertisinstance(reflog,RefLog)
assertlen(reflog)
# iter_entries works with path and with stream.
assertlen(list(RefLog.iter_entries(open(rlp_master,"rb"))))
assertlen(list(RefLog.iter_entries(rlp_master)))
# Raise on invalid revlog.
# TODO: Try multiple corrupted ones!
pp="reflog_invalid_"
forsuffixin ("oldsha","newsha","email","date","sep"):
self.assertRaises(ValueError,RefLog.from_file,fixture_path(pp+suffix))
# END for each invalid file
# Cannot write an uninitialized reflog.
self.assertRaises(ValueError,RefLog().write)
# Test serialize and deserialize - results must match exactly.
binsha=hex_to_bin(("f"*40).encode("ascii"))
msg="my reflog message"
cr=self.rorepo.config_reader()
forrlpin (rlp_head,rlp_master):
reflog=RefLog.from_file(rlp)
tfile=osp.join(tdir,osp.basename(rlp))
reflog.to_file(tfile)
assertreflog.write()isreflog
# Parsed result must match...
treflog=RefLog.from_file(tfile)
asserttreflog==reflog
# ...as well as each bytes of the written stream.
assertopen(tfile).read()==open(rlp).read()
# Append an entry.
entry=RefLog.append_entry(cr,tfile,IndexObject.NULL_BIN_SHA,binsha,msg)
assertentry.oldhexsha==IndexObject.NULL_HEX_SHA
assertentry.newhexsha=="f"*40
assertentry.message==msg
assertRefLog.from_file(tfile)[-1]==entry
# Index entry.
# Raises on invalid index.
self.assertRaises(IndexError,RefLog.entry_at,rlp,10000)
# Indices can be positive...
assertisinstance(RefLog.entry_at(rlp,0),RefLogEntry)
RefLog.entry_at(rlp,23)
# ...and negative.
foridxin (-1,-24):
RefLog.entry_at(rlp,idx)
# END for each index to read
# END for each reflog
# Finally remove our temporary data.
rmtree(tdir)