sapling/eden/scm/tests/test-linkrevcache-linkrevdb.py
Simon Farnsworth 5232dcf9d1 py3: make .py tests continue to run on python 2
Summary:
Use sed to convert testutil.ddot requires to hghave.

ignore-conflict-markers

for test-simplemerge.py

Reviewed By: simpkins

Differential Revision: D19658355

fbshipit-source-id: afae73eb1e43ead79514dfaf9f911f51ac25972e
2020-01-31 00:18:22 -08:00

63 lines
1.4 KiB
Python

from __future__ import absolute_import, print_function
import tempfile
from edenscm.hgext import linkrevcache
from hghave import require
require(["py2"])
try:
xrange(0)
except NameError:
xrange = range
def genhsh(i):
return chr(i) + b"\0" * 19
def ensure(condition):
if not condition:
raise RuntimeError("Unexpected")
def testbasicreadwrite():
path = tempfile.mkdtemp()
db = linkrevcache.linkrevdb(path, write=True)
ensure(db.getlastrev() == 0)
for i in xrange(25):
fname = str(i % 5)
fnode = genhsh(i // 5)
ensure(db.getlinkrevs(fname, fnode) == [])
db.appendlinkrev(fname, fnode, i)
ensure(db.getlinkrevs(fname, fnode) == [i])
db.appendlinkrev(fname, fnode, i)
db.appendlinkrev(fname, fnode, i + 1)
db.appendlinkrev(fname, fnode, i)
ensure(db.getlinkrevs(fname, fnode) == [i, i + 1])
db.setlastrev(i)
ensure(db.getlastrev() == i)
db.close()
# re-open for reading
db = linkrevcache.linkrevdb(path)
ensure(db.getlastrev() == 24)
for i in xrange(25):
fname = str(i % 5)
fnode = genhsh(i // 5)
ensure(db.getlinkrevs(fname, fnode) == [i, i + 1])
for i in xrange(26, 50):
fname = str(i % 5)
fnode = genhsh(i // 5)
ensure(db.getlinkrevs(fname, fnode) == [])
testbasicreadwrite()