All the paths are now bytes, so now things work correctly.
- skip-blame just bytes/str issues in this test
pulkit |
hg-reviewers |
All the paths are now bytes, so now things work correctly.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
Path | Packages | |||
---|---|---|---|---|
M | tests/test-fastannotate-revmap.py (22 lines) |
path = gettemppath() | path = gettemppath() | ||||
rm = revmap.revmap(path) | rm = revmap.revmap(path) | ||||
ensure(rm.maxrev == 0) | ensure(rm.maxrev == 0) | ||||
for i in xrange(5): | for i in xrange(5): | ||||
ensure(rm.rev2hsh(i) is None) | ensure(rm.rev2hsh(i) is None) | ||||
ensure(rm.hsh2rev(b'\0' * 20) is None) | ensure(rm.hsh2rev(b'\0' * 20) is None) | ||||
paths = ['', 'a', None, 'b', 'b', 'c', 'c', None, 'a', 'b', 'a', 'a'] | paths = [ | ||||
b'', b'a', None, b'b', b'b', b'c', b'c', None, b'a', b'b', b'a', b'a'] | |||||
for i in xrange(1, 5): | for i in xrange(1, 5): | ||||
ensure(rm.append(genhsh(i), sidebranch=(i & 1), path=paths[i]) == i) | ensure(rm.append(genhsh(i), sidebranch=(i & 1), path=paths[i]) == i) | ||||
ensure(rm.maxrev == 4) | ensure(rm.maxrev == 4) | ||||
for i in xrange(1, 5): | for i in xrange(1, 5): | ||||
ensure(rm.hsh2rev(genhsh(i)) == i) | ensure(rm.hsh2rev(genhsh(i)) == i) | ||||
ensure(rm.rev2hsh(i) == genhsh(i)) | ensure(rm.rev2hsh(i) == genhsh(i)) | ||||
ensure(False) | ensure(False) | ||||
except Exception: | except Exception: | ||||
pass | pass | ||||
def testcorruptformat(): | def testcorruptformat(): | ||||
path = gettemppath() | path = gettemppath() | ||||
# incorrect header | # incorrect header | ||||
with open(path, 'w') as f: | with open(path, 'wb') as f: | ||||
f.write(b'NOT A VALID HEADER') | f.write(b'NOT A VALID HEADER') | ||||
try: | try: | ||||
revmap.revmap(path) | revmap.revmap(path) | ||||
ensure(False) | ensure(False) | ||||
except error.CorruptedFileError: | except error.CorruptedFileError: | ||||
pass | pass | ||||
# rewrite the file | # rewrite the file | ||||
os.unlink(path) | os.unlink(path) | ||||
rm = revmap.revmap(path) | rm = revmap.revmap(path) | ||||
rm.append(genhsh(0), flush=True) | rm.append(genhsh(0), flush=True) | ||||
rm = revmap.revmap(path) | rm = revmap.revmap(path) | ||||
ensure(rm.maxrev == 1) | ensure(rm.maxrev == 1) | ||||
# corrupt the file by appending a byte | # corrupt the file by appending a byte | ||||
size = os.stat(path).st_size | size = os.stat(path).st_size | ||||
with open(path, 'a') as f: | with open(path, 'ab') as f: | ||||
f.write('\xff') | f.write(b'\xff') | ||||
try: | try: | ||||
revmap.revmap(path) | revmap.revmap(path) | ||||
ensure(False) | ensure(False) | ||||
except error.CorruptedFileError: | except error.CorruptedFileError: | ||||
pass | pass | ||||
# corrupt the file by removing the last byte | # corrupt the file by removing the last byte | ||||
ensure(size > 0) | ensure(size > 0) | ||||
with open(path, 'w') as f: | with open(path, 'wb') as f: | ||||
f.truncate(size - 1) | f.truncate(size - 1) | ||||
try: | try: | ||||
revmap.revmap(path) | revmap.revmap(path) | ||||
ensure(False) | ensure(False) | ||||
except error.CorruptedFileError: | except error.CorruptedFileError: | ||||
pass | pass | ||||
os.unlink(path) | os.unlink(path) | ||||
def testcopyfrom(): | def testcopyfrom(): | ||||
path = gettemppath() | path = gettemppath() | ||||
rm = revmap.revmap(path) | rm = revmap.revmap(path) | ||||
for i in xrange(1, 10): | for i in xrange(1, 10): | ||||
ensure(rm.append(genhsh(i), sidebranch=(i & 1), path=str(i // 3)) == i) | ensure(rm.append(genhsh(i), | ||||
sidebranch=(i & 1), path=(b'%d' % (i // 3))) == i) | |||||
rm.flush() | rm.flush() | ||||
# copy rm to rm2 | # copy rm to rm2 | ||||
rm2 = revmap.revmap() | rm2 = revmap.revmap() | ||||
rm2.copyfrom(rm) | rm2.copyfrom(rm) | ||||
path2 = gettemppath() | path2 = gettemppath() | ||||
rm2.path = path2 | rm2.path = path2 | ||||
rm2.flush() | rm2.flush() | ||||
ensure((fakefctx(genhsh(i)) in rm) == ((i & 1) == 0)) | ensure((fakefctx(genhsh(i)) in rm) == ((i & 1) == 0)) | ||||
for i in xrange(5, 10): | for i in xrange(5, 10): | ||||
ensure(fakefctx(genhsh(i)) not in rm) | ensure(fakefctx(genhsh(i)) not in rm) | ||||
ensure((genhsh(i), None) not in rm) | ensure((genhsh(i), None) not in rm) | ||||
# "contains" checks paths | # "contains" checks paths | ||||
rm = revmap.revmap() | rm = revmap.revmap() | ||||
for i in xrange(1, 5): | for i in xrange(1, 5): | ||||
ensure(rm.append(genhsh(i), path=str(i // 2)) == i) | ensure(rm.append(genhsh(i), path=(b'%d' % (i // 2))) == i) | ||||
for i in xrange(1, 5): | for i in xrange(1, 5): | ||||
ensure(fakefctx(genhsh(i), path=str(i // 2)) in rm) | ensure(fakefctx(genhsh(i), path=(b'%d' % (i // 2))) in rm) | ||||
ensure(fakefctx(genhsh(i), path='a') not in rm) | ensure(fakefctx(genhsh(i), path=b'a') not in rm) | ||||
def testlastnode(): | def testlastnode(): | ||||
path = gettemppath() | path = gettemppath() | ||||
ensure(revmap.getlastnode(path) is None) | ensure(revmap.getlastnode(path) is None) | ||||
rm = revmap.revmap(path) | rm = revmap.revmap(path) | ||||
ensure(revmap.getlastnode(path) is None) | ensure(revmap.getlastnode(path) is None) | ||||
for i in xrange(1, 10): | for i in xrange(1, 10): | ||||
hsh = genhsh(i) | hsh = genhsh(i) | ||||
rm.append(hsh, path=str(i // 2), flush=True) | rm.append(hsh, path=(b'%d' % (i // 2)), flush=True) | ||||
ensure(revmap.getlastnode(path) == hsh) | ensure(revmap.getlastnode(path) == hsh) | ||||
rm2 = revmap.revmap(path) | rm2 = revmap.revmap(path) | ||||
ensure(rm2.rev2hsh(rm2.maxrev) == hsh) | ensure(rm2.rev2hsh(rm2.maxrev) == hsh) | ||||
testbasicreadwrite() | testbasicreadwrite() | ||||
testcorruptformat() | testcorruptformat() | ||||
testcopyfrom() | testcopyfrom() | ||||
testcontains() | testcontains() | ||||
testlastnode() | testlastnode() |