]> arthur.barton.de Git - bup.git/blob - t/tgit.py
Move python library files to lib/bup/
[bup.git] / t / tgit.py
1 import time
2 from bup import git
3 from bup.helpers import *
4 from wvtest import *
5
6
7 @wvtest
8 def testencode():
9     s = 'hello world'
10     looseb = ''.join(git._encode_looseobj('blob', s))
11     looset = ''.join(git._encode_looseobj('tree', s))
12     loosec = ''.join(git._encode_looseobj('commit', s))
13     packb = ''.join(git._encode_packobj('blob', s))
14     packt = ''.join(git._encode_packobj('tree', s))
15     packc = ''.join(git._encode_packobj('commit', s))
16     WVPASSEQ(git._decode_looseobj(looseb), ('blob', s))
17     WVPASSEQ(git._decode_looseobj(looset), ('tree', s))
18     WVPASSEQ(git._decode_looseobj(loosec), ('commit', s))
19     WVPASSEQ(git._decode_packobj(packb), ('blob', s))
20     WVPASSEQ(git._decode_packobj(packt), ('tree', s))
21     WVPASSEQ(git._decode_packobj(packc), ('commit', s))
22
23 @wvtest
24 def testpacks():
25     git.init_repo('pybuptest.tmp')
26     git.verbose = 1
27
28     now = str(time.time())  # hopefully not in any packs yet
29     w = git.PackWriter()
30     w.write('blob', now)
31     w.write('blob', now)
32     w.abort()
33     
34     w = git.PackWriter()
35     hashes = []
36     nobj = 1000
37     for i in range(nobj):
38         hashes.append(w.write('blob', str(i)))
39     log('\n')
40     nameprefix = w.close()
41     print repr(nameprefix)
42     WVPASS(os.path.exists(nameprefix + '.pack'))
43     WVPASS(os.path.exists(nameprefix + '.idx'))
44
45     r = git.PackIndex(nameprefix + '.idx')
46     print repr(r.fanout)
47
48     for i in range(nobj):
49         WVPASS(r.find_offset(hashes[i]) > 0)
50     WVPASS(r.exists(hashes[99]))
51     WVFAIL(r.exists('\0'*20))
52
53     pi = iter(r)
54     for h in sorted(hashes):
55         WVPASSEQ(str(pi.next()).encode('hex'), h.encode('hex'))
56
57     WVFAIL(r.find_offset('\0'*20))
58
59     r = git.MultiPackIndex('pybuptest.tmp/objects/pack')
60     WVPASS(r.exists(hashes[5]))
61     WVPASS(r.exists(hashes[6]))
62     WVFAIL(r.exists('\0'*20))