This avoids a deprecation warning under at least Python 3.7.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
hg-reviewers |
This avoids a deprecation warning under at least Python 3.7.
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | tests/test-remotefilelog-datapack.py (32 lines) | |||
M | tests/test-remotefilelog-histpack.py (56 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Gregory Szorc | Jan 22 2019, 9:16 PM |
"""Test putting a simple blob into a pack and reading it out. | """Test putting a simple blob into a pack and reading it out. | ||||
""" | """ | ||||
filename = "foo" | filename = "foo" | ||||
node = self.getHash(content) | node = self.getHash(content) | ||||
revisions = [(filename, node, nullid, content)] | revisions = [(filename, node, nullid, content)] | ||||
pack = self.createPack(revisions) | pack = self.createPack(revisions) | ||||
if self.paramsavailable: | if self.paramsavailable: | ||||
self.assertEquals(pack.params.fanoutprefix, | self.assertEqual(pack.params.fanoutprefix, | ||||
basepack.SMALLFANOUTPREFIX) | basepack.SMALLFANOUTPREFIX) | ||||
chain = pack.getdeltachain(filename, node) | chain = pack.getdeltachain(filename, node) | ||||
self.assertEquals(content, chain[0][4]) | self.assertEqual(content, chain[0][4]) | ||||
def testAddSingle(self): | def testAddSingle(self): | ||||
self._testAddSingle('') | self._testAddSingle('') | ||||
def testAddSingleEmpty(self): | def testAddSingleEmpty(self): | ||||
self._testAddSingle('abcdef') | self._testAddSingle('abcdef') | ||||
def testAddMultiple(self): | def testAddMultiple(self): | ||||
"""Test putting multiple unrelated blobs into a pack and reading them | """Test putting multiple unrelated blobs into a pack and reading them | ||||
out. | out. | ||||
""" | """ | ||||
revisions = [] | revisions = [] | ||||
for i in range(10): | for i in range(10): | ||||
filename = "foo%s" % i | filename = "foo%s" % i | ||||
content = "abcdef%s" % i | content = "abcdef%s" % i | ||||
node = self.getHash(content) | node = self.getHash(content) | ||||
revisions.append((filename, node, self.getFakeHash(), content)) | revisions.append((filename, node, self.getFakeHash(), content)) | ||||
pack = self.createPack(revisions) | pack = self.createPack(revisions) | ||||
for filename, node, base, content in revisions: | for filename, node, base, content in revisions: | ||||
entry = pack.getdelta(filename, node) | entry = pack.getdelta(filename, node) | ||||
self.assertEquals((content, filename, base, {}), entry) | self.assertEqual((content, filename, base, {}), entry) | ||||
chain = pack.getdeltachain(filename, node) | chain = pack.getdeltachain(filename, node) | ||||
self.assertEquals(content, chain[0][4]) | self.assertEqual(content, chain[0][4]) | ||||
def testAddDeltas(self): | def testAddDeltas(self): | ||||
"""Test putting multiple delta blobs into a pack and read the chain. | """Test putting multiple delta blobs into a pack and read the chain. | ||||
""" | """ | ||||
revisions = [] | revisions = [] | ||||
filename = "foo" | filename = "foo" | ||||
lastnode = nullid | lastnode = nullid | ||||
for i in range(10): | for i in range(10): | ||||
content = "abcdef%s" % i | content = "abcdef%s" % i | ||||
node = self.getHash(content) | node = self.getHash(content) | ||||
revisions.append((filename, node, lastnode, content)) | revisions.append((filename, node, lastnode, content)) | ||||
lastnode = node | lastnode = node | ||||
pack = self.createPack(revisions) | pack = self.createPack(revisions) | ||||
entry = pack.getdelta(filename, revisions[0][1]) | entry = pack.getdelta(filename, revisions[0][1]) | ||||
realvalue = (revisions[0][3], filename, revisions[0][2], {}) | realvalue = (revisions[0][3], filename, revisions[0][2], {}) | ||||
self.assertEquals(entry, realvalue) | self.assertEqual(entry, realvalue) | ||||
# Test that the chain for the final entry has all the others | # Test that the chain for the final entry has all the others | ||||
chain = pack.getdeltachain(filename, node) | chain = pack.getdeltachain(filename, node) | ||||
for i in range(10): | for i in range(10): | ||||
content = "abcdef%s" % i | content = "abcdef%s" % i | ||||
self.assertEquals(content, chain[-i - 1][4]) | self.assertEqual(content, chain[-i - 1][4]) | ||||
def testPackMany(self): | def testPackMany(self): | ||||
"""Pack many related and unrelated objects. | """Pack many related and unrelated objects. | ||||
""" | """ | ||||
# Build a random pack file | # Build a random pack file | ||||
revisions = [] | revisions = [] | ||||
blobs = {} | blobs = {} | ||||
random.seed(0) | random.seed(0) | ||||
pack = self.createPack(revisions) | pack = self.createPack(revisions) | ||||
# Verify the pack contents | # Verify the pack contents | ||||
for (filename, node, lastnode), content in sorted(blobs.iteritems()): | for (filename, node, lastnode), content in sorted(blobs.iteritems()): | ||||
chain = pack.getdeltachain(filename, node) | chain = pack.getdeltachain(filename, node) | ||||
for entry in chain: | for entry in chain: | ||||
expectedcontent = blobs[(entry[0], entry[1], entry[3])] | expectedcontent = blobs[(entry[0], entry[1], entry[3])] | ||||
self.assertEquals(entry[4], expectedcontent) | self.assertEqual(entry[4], expectedcontent) | ||||
def testPackMetadata(self): | def testPackMetadata(self): | ||||
revisions = [] | revisions = [] | ||||
for i in range(100): | for i in range(100): | ||||
filename = '%s.txt' % i | filename = '%s.txt' % i | ||||
content = 'put-something-here \n' * i | content = 'put-something-here \n' * i | ||||
node = self.getHash(content) | node = self.getHash(content) | ||||
meta = {constants.METAKEYFLAG: i ** 4, | meta = {constants.METAKEYFLAG: i ** 4, | ||||
constants.METAKEYSIZE: len(content), | constants.METAKEYSIZE: len(content), | ||||
'Z': 'random_string', | 'Z': 'random_string', | ||||
'_': '\0' * i} | '_': '\0' * i} | ||||
revisions.append((filename, node, nullid, content, meta)) | revisions.append((filename, node, nullid, content, meta)) | ||||
pack = self.createPack(revisions) | pack = self.createPack(revisions) | ||||
for name, node, x, content, origmeta in revisions: | for name, node, x, content, origmeta in revisions: | ||||
parsedmeta = pack.getmeta(name, node) | parsedmeta = pack.getmeta(name, node) | ||||
# flag == 0 should be optimized out | # flag == 0 should be optimized out | ||||
if origmeta[constants.METAKEYFLAG] == 0: | if origmeta[constants.METAKEYFLAG] == 0: | ||||
del origmeta[constants.METAKEYFLAG] | del origmeta[constants.METAKEYFLAG] | ||||
self.assertEquals(parsedmeta, origmeta) | self.assertEqual(parsedmeta, origmeta) | ||||
def testGetMissing(self): | def testGetMissing(self): | ||||
"""Test the getmissing() api. | """Test the getmissing() api. | ||||
""" | """ | ||||
revisions = [] | revisions = [] | ||||
filename = "foo" | filename = "foo" | ||||
lastnode = nullid | lastnode = nullid | ||||
for i in range(10): | for i in range(10): | ||||
content = "abcdef%s" % i | content = "abcdef%s" % i | ||||
node = self.getHash(content) | node = self.getHash(content) | ||||
revisions.append((filename, node, lastnode, content)) | revisions.append((filename, node, lastnode, content)) | ||||
lastnode = node | lastnode = node | ||||
pack = self.createPack(revisions) | pack = self.createPack(revisions) | ||||
missing = pack.getmissing([("foo", revisions[0][1])]) | missing = pack.getmissing([("foo", revisions[0][1])]) | ||||
self.assertFalse(missing) | self.assertFalse(missing) | ||||
missing = pack.getmissing([("foo", revisions[0][1]), | missing = pack.getmissing([("foo", revisions[0][1]), | ||||
("foo", revisions[1][1])]) | ("foo", revisions[1][1])]) | ||||
self.assertFalse(missing) | self.assertFalse(missing) | ||||
fakenode = self.getFakeHash() | fakenode = self.getFakeHash() | ||||
missing = pack.getmissing([("foo", revisions[0][1]), ("foo", fakenode)]) | missing = pack.getmissing([("foo", revisions[0][1]), ("foo", fakenode)]) | ||||
self.assertEquals(missing, [("foo", fakenode)]) | self.assertEqual(missing, [("foo", fakenode)]) | ||||
def testAddThrows(self): | def testAddThrows(self): | ||||
pack = self.createPack() | pack = self.createPack() | ||||
try: | try: | ||||
pack.add('filename', nullid, 'contents') | pack.add('filename', nullid, 'contents') | ||||
self.assertTrue(False, "datapack.add should throw") | self.assertTrue(False, "datapack.add should throw") | ||||
except RuntimeError: | except RuntimeError: | ||||
except RuntimeError: | except RuntimeError: | ||||
pass | pass | ||||
def testMissingDeltabase(self): | def testMissingDeltabase(self): | ||||
fakenode = self.getFakeHash() | fakenode = self.getFakeHash() | ||||
revisions = [("filename", fakenode, self.getFakeHash(), "content")] | revisions = [("filename", fakenode, self.getFakeHash(), "content")] | ||||
pack = self.createPack(revisions) | pack = self.createPack(revisions) | ||||
chain = pack.getdeltachain("filename", fakenode) | chain = pack.getdeltachain("filename", fakenode) | ||||
self.assertEquals(len(chain), 1) | self.assertEqual(len(chain), 1) | ||||
def testLargePack(self): | def testLargePack(self): | ||||
"""Test creating and reading from a large pack with over X entries. | """Test creating and reading from a large pack with over X entries. | ||||
This causes it to use a 2^16 fanout table instead.""" | This causes it to use a 2^16 fanout table instead.""" | ||||
revisions = [] | revisions = [] | ||||
blobs = {} | blobs = {} | ||||
total = basepack.SMALLFANOUTCUTOFF + 1 | total = basepack.SMALLFANOUTCUTOFF + 1 | ||||
for i in pycompat.xrange(total): | for i in pycompat.xrange(total): | ||||
filename = "filename-%s" % i | filename = "filename-%s" % i | ||||
content = filename | content = filename | ||||
node = self.getHash(content) | node = self.getHash(content) | ||||
blobs[(filename, node)] = content | blobs[(filename, node)] = content | ||||
revisions.append((filename, node, nullid, content)) | revisions.append((filename, node, nullid, content)) | ||||
pack = self.createPack(revisions) | pack = self.createPack(revisions) | ||||
if self.paramsavailable: | if self.paramsavailable: | ||||
self.assertEquals(pack.params.fanoutprefix, | self.assertEqual(pack.params.fanoutprefix, | ||||
basepack.LARGEFANOUTPREFIX) | basepack.LARGEFANOUTPREFIX) | ||||
for (filename, node), content in blobs.iteritems(): | for (filename, node), content in blobs.iteritems(): | ||||
actualcontent = pack.getdeltachain(filename, node)[0][4] | actualcontent = pack.getdeltachain(filename, node)[0][4] | ||||
self.assertEquals(actualcontent, content) | self.assertEqual(actualcontent, content) | ||||
def testPacksCache(self): | def testPacksCache(self): | ||||
"""Test that we remember the most recent packs while fetching the delta | """Test that we remember the most recent packs while fetching the delta | ||||
chain.""" | chain.""" | ||||
packdir = self.makeTempDir() | packdir = self.makeTempDir() | ||||
deltachains = [] | deltachains = [] | ||||
store = testdatapackstore(uimod.ui(), packdir) | store = testdatapackstore(uimod.ui(), packdir) | ||||
random.shuffle(deltachains) | random.shuffle(deltachains) | ||||
for randomchain in deltachains: | for randomchain in deltachains: | ||||
revision = random.choice(randomchain) | revision = random.choice(randomchain) | ||||
chain = store.getdeltachain(revision[0], revision[1]) | chain = store.getdeltachain(revision[0], revision[1]) | ||||
mostrecentpack = next(iter(store.packs), None) | mostrecentpack = next(iter(store.packs), None) | ||||
self.assertEquals( | self.assertEqual( | ||||
mostrecentpack.getdeltachain(revision[0], revision[1]), | mostrecentpack.getdeltachain(revision[0], revision[1]), | ||||
chain | chain | ||||
) | ) | ||||
self.assertEquals(randomchain.index(revision) + 1, len(chain)) | self.assertEqual(randomchain.index(revision) + 1, len(chain)) | ||||
# perf test off by default since it's slow | # perf test off by default since it's slow | ||||
def _testIndexPerf(self): | def _testIndexPerf(self): | ||||
random.seed(0) | random.seed(0) | ||||
print("Multi-get perf test") | print("Multi-get perf test") | ||||
packsizes = [ | packsizes = [ | ||||
100, | 100, | ||||
10000, | 10000, |
p1 = self.getFakeHash() | p1 = self.getFakeHash() | ||||
p2 = self.getFakeHash() | p2 = self.getFakeHash() | ||||
linknode = self.getFakeHash() | linknode = self.getFakeHash() | ||||
revisions = [(filename, node, p1, p2, linknode, None)] | revisions = [(filename, node, p1, p2, linknode, None)] | ||||
pack = self.createPack(revisions) | pack = self.createPack(revisions) | ||||
actual = pack.getancestors(filename, node)[node] | actual = pack.getancestors(filename, node)[node] | ||||
self.assertEquals(p1, actual[0]) | self.assertEqual(p1, actual[0]) | ||||
self.assertEquals(p2, actual[1]) | self.assertEqual(p2, actual[1]) | ||||
self.assertEquals(linknode, actual[2]) | self.assertEqual(linknode, actual[2]) | ||||
def testAddMultiple(self): | def testAddMultiple(self): | ||||
"""Test putting multiple unrelated revisions into a pack and reading | """Test putting multiple unrelated revisions into a pack and reading | ||||
them out. | them out. | ||||
""" | """ | ||||
revisions = [] | revisions = [] | ||||
for i in range(10): | for i in range(10): | ||||
filename = "foo-%s" % i | filename = "foo-%s" % i | ||||
node = self.getFakeHash() | node = self.getFakeHash() | ||||
p1 = self.getFakeHash() | p1 = self.getFakeHash() | ||||
p2 = self.getFakeHash() | p2 = self.getFakeHash() | ||||
linknode = self.getFakeHash() | linknode = self.getFakeHash() | ||||
revisions.append((filename, node, p1, p2, linknode, None)) | revisions.append((filename, node, p1, p2, linknode, None)) | ||||
pack = self.createPack(revisions) | pack = self.createPack(revisions) | ||||
for filename, node, p1, p2, linknode, copyfrom in revisions: | for filename, node, p1, p2, linknode, copyfrom in revisions: | ||||
actual = pack.getancestors(filename, node)[node] | actual = pack.getancestors(filename, node)[node] | ||||
self.assertEquals(p1, actual[0]) | self.assertEqual(p1, actual[0]) | ||||
self.assertEquals(p2, actual[1]) | self.assertEqual(p2, actual[1]) | ||||
self.assertEquals(linknode, actual[2]) | self.assertEqual(linknode, actual[2]) | ||||
self.assertEquals(copyfrom, actual[3]) | self.assertEqual(copyfrom, actual[3]) | ||||
def testAddAncestorChain(self): | def testAddAncestorChain(self): | ||||
"""Test putting multiple revisions in into a pack and read the ancestor | """Test putting multiple revisions in into a pack and read the ancestor | ||||
chain. | chain. | ||||
""" | """ | ||||
revisions = [] | revisions = [] | ||||
filename = b"foo" | filename = b"foo" | ||||
lastnode = nullid | lastnode = nullid | ||||
for i in range(10): | for i in range(10): | ||||
node = self.getFakeHash() | node = self.getFakeHash() | ||||
revisions.append((filename, node, lastnode, nullid, nullid, None)) | revisions.append((filename, node, lastnode, nullid, nullid, None)) | ||||
lastnode = node | lastnode = node | ||||
# revisions must be added in topological order, newest first | # revisions must be added in topological order, newest first | ||||
revisions = list(reversed(revisions)) | revisions = list(reversed(revisions)) | ||||
pack = self.createPack(revisions) | pack = self.createPack(revisions) | ||||
# Test that the chain has all the entries | # Test that the chain has all the entries | ||||
ancestors = pack.getancestors(revisions[0][0], revisions[0][1]) | ancestors = pack.getancestors(revisions[0][0], revisions[0][1]) | ||||
for filename, node, p1, p2, linknode, copyfrom in revisions: | for filename, node, p1, p2, linknode, copyfrom in revisions: | ||||
ap1, ap2, alinknode, acopyfrom = ancestors[node] | ap1, ap2, alinknode, acopyfrom = ancestors[node] | ||||
self.assertEquals(ap1, p1) | self.assertEqual(ap1, p1) | ||||
self.assertEquals(ap2, p2) | self.assertEqual(ap2, p2) | ||||
self.assertEquals(alinknode, linknode) | self.assertEqual(alinknode, linknode) | ||||
self.assertEquals(acopyfrom, copyfrom) | self.assertEqual(acopyfrom, copyfrom) | ||||
def testPackMany(self): | def testPackMany(self): | ||||
"""Pack many related and unrelated ancestors. | """Pack many related and unrelated ancestors. | ||||
""" | """ | ||||
# Build a random pack file | # Build a random pack file | ||||
allentries = {} | allentries = {} | ||||
ancestorcounts = {} | ancestorcounts = {} | ||||
revisions = [] | revisions = [] | ||||
# Must add file entries in reverse topological order | # Must add file entries in reverse topological order | ||||
revisions = list(reversed(revisions)) | revisions = list(reversed(revisions)) | ||||
pack = self.createPack(revisions) | pack = self.createPack(revisions) | ||||
# Verify the pack contents | # Verify the pack contents | ||||
for (filename, node), (p1, p2, lastnode) in allentries.items(): | for (filename, node), (p1, p2, lastnode) in allentries.items(): | ||||
ancestors = pack.getancestors(filename, node) | ancestors = pack.getancestors(filename, node) | ||||
self.assertEquals(ancestorcounts[(filename, node)], | self.assertEqual(ancestorcounts[(filename, node)], | ||||
len(ancestors)) | len(ancestors)) | ||||
for anode, (ap1, ap2, alinknode, copyfrom) in ancestors.items(): | for anode, (ap1, ap2, alinknode, copyfrom) in ancestors.items(): | ||||
ep1, ep2, elinknode = allentries[(filename, anode)] | ep1, ep2, elinknode = allentries[(filename, anode)] | ||||
self.assertEquals(ap1, ep1) | self.assertEqual(ap1, ep1) | ||||
self.assertEquals(ap2, ep2) | self.assertEqual(ap2, ep2) | ||||
self.assertEquals(alinknode, elinknode) | self.assertEqual(alinknode, elinknode) | ||||
self.assertEquals(copyfrom, None) | self.assertEqual(copyfrom, None) | ||||
def testGetNodeInfo(self): | def testGetNodeInfo(self): | ||||
revisions = [] | revisions = [] | ||||
filename = b"foo" | filename = b"foo" | ||||
lastnode = nullid | lastnode = nullid | ||||
for i in range(10): | for i in range(10): | ||||
node = self.getFakeHash() | node = self.getFakeHash() | ||||
revisions.append((filename, node, lastnode, nullid, nullid, None)) | revisions.append((filename, node, lastnode, nullid, nullid, None)) | ||||
lastnode = node | lastnode = node | ||||
pack = self.createPack(revisions) | pack = self.createPack(revisions) | ||||
# Test that getnodeinfo returns the expected results | # Test that getnodeinfo returns the expected results | ||||
for filename, node, p1, p2, linknode, copyfrom in revisions: | for filename, node, p1, p2, linknode, copyfrom in revisions: | ||||
ap1, ap2, alinknode, acopyfrom = pack.getnodeinfo(filename, node) | ap1, ap2, alinknode, acopyfrom = pack.getnodeinfo(filename, node) | ||||
self.assertEquals(ap1, p1) | self.assertEqual(ap1, p1) | ||||
self.assertEquals(ap2, p2) | self.assertEqual(ap2, p2) | ||||
self.assertEquals(alinknode, linknode) | self.assertEqual(alinknode, linknode) | ||||
self.assertEquals(acopyfrom, copyfrom) | self.assertEqual(acopyfrom, copyfrom) | ||||
def testGetMissing(self): | def testGetMissing(self): | ||||
"""Test the getmissing() api. | """Test the getmissing() api. | ||||
""" | """ | ||||
revisions = [] | revisions = [] | ||||
filename = b"foo" | filename = b"foo" | ||||
for i in range(10): | for i in range(10): | ||||
node = self.getFakeHash() | node = self.getFakeHash() | ||||
missing = pack.getmissing([(filename, revisions[0][1]), | missing = pack.getmissing([(filename, revisions[0][1]), | ||||
(filename, revisions[1][1])]) | (filename, revisions[1][1])]) | ||||
self.assertFalse(missing) | self.assertFalse(missing) | ||||
fakenode = self.getFakeHash() | fakenode = self.getFakeHash() | ||||
missing = pack.getmissing([(filename, revisions[0][1]), | missing = pack.getmissing([(filename, revisions[0][1]), | ||||
(filename, fakenode)]) | (filename, fakenode)]) | ||||
self.assertEquals(missing, [(filename, fakenode)]) | self.assertEqual(missing, [(filename, fakenode)]) | ||||
# Test getmissing on a non-existant filename | # Test getmissing on a non-existant filename | ||||
missing = pack.getmissing([("bar", fakenode)]) | missing = pack.getmissing([("bar", fakenode)]) | ||||
self.assertEquals(missing, [("bar", fakenode)]) | self.assertEqual(missing, [("bar", fakenode)]) | ||||
def testAddThrows(self): | def testAddThrows(self): | ||||
pack = self.createPack() | pack = self.createPack() | ||||
try: | try: | ||||
pack.add(b'filename', nullid, nullid, nullid, nullid, None) | pack.add(b'filename', nullid, nullid, nullid, nullid, None) | ||||
self.assertTrue(False, "historypack.add should throw") | self.assertTrue(False, "historypack.add should throw") | ||||
except RuntimeError: | except RuntimeError: | ||||
filename = b"foo-%d" % i | filename = b"foo-%d" % i | ||||
node = self.getFakeHash() | node = self.getFakeHash() | ||||
p1 = self.getFakeHash() | p1 = self.getFakeHash() | ||||
p2 = self.getFakeHash() | p2 = self.getFakeHash() | ||||
linknode = self.getFakeHash() | linknode = self.getFakeHash() | ||||
revisions.append((filename, node, p1, p2, linknode, None)) | revisions.append((filename, node, p1, p2, linknode, None)) | ||||
pack = self.createPack(revisions) | pack = self.createPack(revisions) | ||||
self.assertEquals(pack.params.fanoutprefix, basepack.LARGEFANOUTPREFIX) | self.assertEqual(pack.params.fanoutprefix, basepack.LARGEFANOUTPREFIX) | ||||
for filename, node, p1, p2, linknode, copyfrom in revisions: | for filename, node, p1, p2, linknode, copyfrom in revisions: | ||||
actual = pack.getancestors(filename, node)[node] | actual = pack.getancestors(filename, node)[node] | ||||
self.assertEquals(p1, actual[0]) | self.assertEqual(p1, actual[0]) | ||||
self.assertEquals(p2, actual[1]) | self.assertEqual(p2, actual[1]) | ||||
self.assertEquals(linknode, actual[2]) | self.assertEqual(linknode, actual[2]) | ||||
self.assertEquals(copyfrom, actual[3]) | self.assertEqual(copyfrom, actual[3]) | ||||
# TODO: | # TODO: | ||||
# histpack store: | # histpack store: | ||||
# - repack two packs into one | # - repack two packs into one | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
if pycompat.iswindows: | if pycompat.iswindows: | ||||
sys.exit(80) # Skip on Windows | sys.exit(80) # Skip on Windows | ||||
silenttestrunner.main(__name__) | silenttestrunner.main(__name__) |