sapling/tests/test-hgsubversion-svn-pre-commit-hooks.py
Jun Wu 9dc21f8d0b codemod: import from the edenscm package
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
2019-01-29 17:25:32 -08:00

30 lines
942 B
Python

# no-check-code -- see T24862348
import os
import test_hgsubversion_util
from edenscm.mercurial import util
class TestSvnPreCommitHooks(test_hgsubversion_util.TestBase):
def setUp(self):
super(TestSvnPreCommitHooks, self).setUp()
self.repo_path = self.load_and_fetch("single_rev.svndump")[1]
# creating pre-commit hook that doesn't allow any commit
hook_file_name = os.path.join(self.repo_path, "hooks", "pre-commit")
hook_file = open(hook_file_name, "w")
hook_file.write("#!/bin/sh\n" 'echo "Commits are not allowed" >&2; exit 1;\n')
hook_file.close()
os.chmod(hook_file_name, 0o755)
def test_push_with_pre_commit_hooks(self):
changes = [("narf/a", "narf/a", "ohai")]
self.commitchanges(changes)
self.assertRaises(util.Abort, self.pushrevisions)
if __name__ == "__main__":
import silenttestrunner
silenttestrunner.main(__name__)