2016-04-08 21:46:18 +03:00
|
|
|
import silenttestrunner
|
|
|
|
import unittest
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from mercurial import manifest
|
2016-05-16 22:38:52 +03:00
|
|
|
from mercurial import scmutil
|
2016-04-08 21:46:18 +03:00
|
|
|
from mercurial import util
|
|
|
|
|
|
|
|
class HybridManifest(unittest.TestCase):
|
|
|
|
|
2016-05-25 23:23:19 +03:00
|
|
|
def test_wrap(self):
|
|
|
|
"""If a new magic method is added to manifestdict, we want to make sure
|
|
|
|
that hybridmanifest implement it, this test validates that all magic
|
|
|
|
methods of manifestdict are implemented by hybridmanifest to avoid
|
|
|
|
breakage in prod
|
2016-04-08 21:46:18 +03:00
|
|
|
|
2016-05-25 23:23:19 +03:00
|
|
|
"""
|
|
|
|
vfs = scmutil.vfs('')
|
2016-05-26 22:34:38 +03:00
|
|
|
hd = fastmanifest.implementation.hybridmanifest(None, vfs)
|
2016-05-25 23:23:19 +03:00
|
|
|
ismagic = lambda x: x.startswith("__") and x.endswith("__")
|
|
|
|
magicmethods = [k
|
|
|
|
for k, v in manifest.manifestdict.__dict__.items()
|
|
|
|
if util.safehasattr(v, '__call__') and ismagic(k)]
|
|
|
|
for method in magicmethods:
|
|
|
|
assert util.safehasattr(hd, method),\
|
|
|
|
"%s missing in hybrid manifest" % method
|
|
|
|
|
|
|
|
def test_cachelimit(self):
|
|
|
|
cachealloc = fastmanifest.systemawarecachelimit.cacheallocation
|
|
|
|
GB = fastmanifest.GB
|
|
|
|
MB = fastmanifest.MB
|
|
|
|
assert cachealloc(0) == 0
|
|
|
|
assert cachealloc(120 * GB) == 6 * GB
|
|
|
|
assert abs(cachealloc(28 * GB) - 5.6 * GB) < 5 * MB
|
2016-05-23 21:52:42 +03:00
|
|
|
|
2016-05-26 19:52:55 +03:00
|
|
|
def test_shufflebybatch(self):
|
|
|
|
data = range(10000)
|
|
|
|
fastmanifest.shufflebybatch(data, 5)
|
|
|
|
assert len(data) == 10000
|
|
|
|
assert data != range(10000)
|
|
|
|
|
2016-04-08 21:46:18 +03:00
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.path.insert(0, os.path.join(os.environ["TESTDIR"], ".."))
|
|
|
|
import fastmanifest
|
|
|
|
silenttestrunner.main(__name__)
|