mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 17:27:53 +03:00
9dc21f8d0b
Summary: D13853115 adds `edenscm/` to `sys.path` and code still uses `import mercurial`. That has nasty problems if both `import mercurial` and `import edenscm.mercurial` are used, because Python would think `mercurial.foo` and `edenscm.mercurial.foo` are different modules so code like `try: ... except mercurial.error.Foo: ...`, or `isinstance(x, mercurial.foo.Bar)` would fail to handle the `edenscm.mercurial` version. There are also some module-level states (ex. `extensions._extensions`) that would cause trouble if they have multiple versions in a single process. Change imports to use the `edenscm` so ideally the `mercurial` is no longer imported at all. Add checks in extensions.py to catch unexpected extensions importing modules from the old (wrong) locations when running tests. Reviewed By: phillco Differential Revision: D13868981 fbshipit-source-id: f4e2513766957fd81d85407994f7521a08e4de48
91 lines
2.9 KiB
Python
91 lines
2.9 KiB
Python
# no-check-code -- see T24862348
|
|
|
|
import os
|
|
import sys
|
|
|
|
import test_hgsubversion_util
|
|
from edenscm.hgext.hgsubversion import svncommands
|
|
from edenscm.mercurial import context, extensions
|
|
|
|
|
|
test_rebuildmeta = test_hgsubversion_util.import_test("test_rebuildmeta")
|
|
|
|
|
|
def _do_case(self, name, layout):
|
|
subdir = test_hgsubversion_util.subdir.get(name, "")
|
|
single = layout == "single"
|
|
u = test_hgsubversion_util.testui()
|
|
config = {}
|
|
if layout == "custom":
|
|
config["hgsubversion.layout"] = "custom"
|
|
u.setconfig("hgsubversion", "layout", "custom")
|
|
for branch, path in test_hgsubversion_util.custom.get(name, {}).iteritems():
|
|
config["hgsubversionbranch.%s" % branch] = path
|
|
u.setconfig("hgsubversionbranch", branch, path)
|
|
|
|
repo, repo_path = self.load_and_fetch(
|
|
name, subdir=subdir, layout=layout, config=config
|
|
)
|
|
assert test_hgsubversion_util.repolen(self.repo) > 0
|
|
wc2_path = self.wc_path + "_clone"
|
|
src, dest = test_hgsubversion_util.hgclone(u, self.wc_path, wc2_path, update=False)
|
|
src = test_hgsubversion_util.getlocalpeer(src)
|
|
dest = test_hgsubversion_util.getlocalpeer(dest)
|
|
|
|
# insert a wrapper that prevents calling changectx.children()
|
|
def failfn(orig, ctx):
|
|
self.fail(
|
|
"calling %s is forbidden; it can cause massive slowdowns "
|
|
"when rebuilding large repositories" % orig
|
|
)
|
|
|
|
origchildren = getattr(context.changectx, "children")
|
|
extensions.wrapfunction(context.changectx, "children", failfn)
|
|
|
|
# test updatemeta on an empty repo
|
|
try:
|
|
svncommands.updatemeta(
|
|
u, dest, args=[test_hgsubversion_util.fileurl(repo_path + subdir)]
|
|
)
|
|
finally:
|
|
# remove the wrapper
|
|
context.changectx.children = origchildren
|
|
|
|
self._run_assertions(name, single, src, dest, u)
|
|
|
|
|
|
def _run_assertions(self, name, single, src, dest, u):
|
|
test_rebuildmeta._run_assertions(self, name, single, src, dest, u)
|
|
|
|
|
|
skip = set(["project_root_not_repo_root.svndump", "corrupt.svndump"])
|
|
|
|
attrs = {
|
|
"_do_case": _do_case,
|
|
"_run_assertions": _run_assertions,
|
|
"stupid_mode_tests": True,
|
|
}
|
|
for case in [
|
|
f for f in os.listdir(test_hgsubversion_util.FIXTURES) if f.endswith(".svndump")
|
|
]:
|
|
# this fixture results in an empty repository, don't use it
|
|
if case in skip:
|
|
continue
|
|
bname = "test_" + case[: -len(".svndump")]
|
|
attrs[bname] = test_rebuildmeta.buildmethod(case, bname, "auto")
|
|
attrs[bname + "_single"] = test_rebuildmeta.buildmethod(
|
|
case, bname + "_single", "single"
|
|
)
|
|
if case in test_hgsubversion_util.custom:
|
|
attrs[bname + "_custom"] = test_rebuildmeta.buildmethod(
|
|
case, bname + "_custom", "custom"
|
|
)
|
|
|
|
|
|
UpdateMetaTests = type("UpdateMetaTests", (test_hgsubversion_util.TestBase,), attrs)
|
|
|
|
if __name__ == "__main__":
|
|
import silenttestrunner
|
|
|
|
silenttestrunner.main(__name__)
|