sapling/tests/test-hgsubversion-urls.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

103 lines
3.7 KiB
Python

# no-check-code -- see T24862348
import urllib
import test_hgsubversion_util
from edenscm.hgext.hgsubversion import svnrepo
from edenscm.hgext.hgsubversion.svnwrap import parse_url
class TestSubversionUrls(test_hgsubversion_util.TestBase):
def test_standard_url(self):
self.check_parse_url(
(None, None, "file:///var/svn/repo"), ("file:///var/svn/repo",)
)
def test_user_url(self):
self.check_parse_url(
("joe", None, "https://svn.testurl.com/repo"),
("https://joe@svn.testurl.com/repo",),
)
self.check_parse_url(
("bob", None, "https://svn.testurl.com/repo"),
("https://joe@svn.testurl.com/repo", "bob"),
)
def test_password_url(self):
self.check_parse_url(
(None, "t3stpw", "svn+ssh://svn.testurl.com/repo"),
("svn+ssh://:t3stpw@svn.testurl.com/repo",),
)
self.check_parse_url(
(None, "123abc", "svn+ssh://svn.testurl.com/repo"),
("svn+ssh://:t3stpw@svn.testurl.com/repo", None, "123abc"),
)
def test_svnssh_preserve_user(self):
self.check_parse_url(
("user", "t3stpw", "svn+ssh://user@svn.testurl.com/repo"),
("svn+ssh://user:t3stpw@svn.testurl.com/repo",),
)
self.check_parse_url(
("bob", "123abc", "svn+ssh://bob@svn.testurl.com/repo"),
("svn+ssh://user:t3stpw@svn.testurl.com/repo", "bob", "123abc"),
)
self.check_parse_url(
("user2", None, "svn+ssh://user2@svn.testurl.com/repo"),
("svn+ssh://user2@svn.testurl.com/repo",),
)
self.check_parse_url(
("bob", None, "svn+ssh://bob@svn.testurl.com/repo"),
("svn+ssh://user2@svn.testurl.com/repo", "bob"),
)
def test_user_password_url(self):
self.check_parse_url(
("joe", "t3stpw", "https://svn.testurl.com/repo"),
("https://joe:t3stpw@svn.testurl.com/repo",),
)
self.check_parse_url(
("bob", "123abc", "https://svn.testurl.com/repo"),
("https://joe:t3stpw@svn.testurl.com/repo", "bob", "123abc"),
)
def test_url_rewriting(self):
ui = test_hgsubversion_util.testui()
ui.setconfig("hgsubversion", "username", "bob")
repo = svnrepo.svnremoterepo(ui, "svn+ssh://joe@foo/bar")
self.assertEqual("svn+ssh://bob@foo/bar", repo.svnauth[0])
self.assertEqual("svn+ssh://bob@foo/bar", repo.svnurl)
repo = svnrepo.svnremoterepo(ui, "svn+http://joe@foo/bar")
self.assertEqual(("http://foo/bar", "bob", None), repo.svnauth)
self.assertEqual("http://foo/bar", repo.svnurl)
repo = svnrepo.svnremoterepo(ui, "svn+https://joe@foo/bar")
self.assertEqual(("https://foo/bar", "bob", None), repo.svnauth)
self.assertEqual("https://foo/bar", repo.svnurl)
def test_quoting(self):
ui = self.ui()
repo_path = self.load_svndump("non_ascii_path_1.svndump")
repo_url = test_hgsubversion_util.fileurl(repo_path)
subdir = "/b\xC3\xB8b"
quoted_subdir = urllib.quote(subdir)
repo1 = svnrepo.svnremoterepo(ui, repo_url + subdir)
repo2 = svnrepo.svnremoterepo(ui, repo_url + quoted_subdir)
self.assertEqual(repo1.svnurl, repo2.svnurl)
def check_parse_url(self, expected, args):
self.assertEqual(expected, parse_url(*args))
if len(args) == 1:
repo = svnrepo.svnremoterepo(self.ui(), path=args[0])
self.assertEqual(expected[2], repo.svnauth[0])
self.assertEqual(expected[2], repo.svnurl)
if __name__ == "__main__":
import silenttestrunner
silenttestrunner.main(__name__)