2019-05-21 19:06:46 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2018-07-06 03:45:27 +03:00
|
|
|
import shutil
|
tests: add check for dulwich in test-url-parsing.py
Previously, if dulwich wasn't available, this test would fail with a traceback
(example included below). This changeset makes it so that the test will be
skipped with an informative message if dulwich isn't available.
Traceback (most recent call last):
File "/Users/carrd/hg-repos/hg-git-queue/tests/test-url-parsing.py", line 6, in <module>
from hggit.git_handler import GitHandler
File "/Users/carrd/hg-repos/hg-git-queue/tests/../hggit/__init__.py", line 42, in <module>
import gitrepo, hgrepo
File "/Users/carrd/hg-repos/hg-git-queue/tests/../hggit/gitrepo.py", line 13, in <module>
from git_handler import GitHandler
File "/Users/carrd/hg-repos/hg-git-queue/tests/../hggit/git_handler.py", line 4, in <module>
from dulwich.errors import HangupException, GitProtocolError, UpdateRefsError
ImportError: No module named dulwich.errors
2012-10-31 07:16:07 +04:00
|
|
|
import sys
|
2018-07-06 03:45:27 +03:00
|
|
|
import tempfile
|
|
|
|
|
2019-01-30 03:25:33 +03:00
|
|
|
from edenscm.hgext.hggit.git_handler import GitHandler
|
|
|
|
from edenscm.mercurial import commands, hg, ui
|
2018-07-06 03:45:27 +03:00
|
|
|
|
tests: add check for dulwich in test-url-parsing.py
Previously, if dulwich wasn't available, this test would fail with a traceback
(example included below). This changeset makes it so that the test will be
skipped with an informative message if dulwich isn't available.
Traceback (most recent call last):
File "/Users/carrd/hg-repos/hg-git-queue/tests/test-url-parsing.py", line 6, in <module>
from hggit.git_handler import GitHandler
File "/Users/carrd/hg-repos/hg-git-queue/tests/../hggit/__init__.py", line 42, in <module>
import gitrepo, hgrepo
File "/Users/carrd/hg-repos/hg-git-queue/tests/../hggit/gitrepo.py", line 13, in <module>
from git_handler import GitHandler
File "/Users/carrd/hg-repos/hg-git-queue/tests/../hggit/git_handler.py", line 4, in <module>
from dulwich.errors import HangupException, GitProtocolError, UpdateRefsError
ImportError: No module named dulwich.errors
2012-10-31 07:16:07 +04:00
|
|
|
|
|
|
|
try:
|
|
|
|
import dulwich
|
2018-07-06 03:45:27 +03:00
|
|
|
|
|
|
|
type(dulwich) # avoid pyflakes unused import error
|
tests: add check for dulwich in test-url-parsing.py
Previously, if dulwich wasn't available, this test would fail with a traceback
(example included below). This changeset makes it so that the test will be
skipped with an informative message if dulwich isn't available.
Traceback (most recent call last):
File "/Users/carrd/hg-repos/hg-git-queue/tests/test-url-parsing.py", line 6, in <module>
from hggit.git_handler import GitHandler
File "/Users/carrd/hg-repos/hg-git-queue/tests/../hggit/__init__.py", line 42, in <module>
import gitrepo, hgrepo
File "/Users/carrd/hg-repos/hg-git-queue/tests/../hggit/gitrepo.py", line 13, in <module>
from git_handler import GitHandler
File "/Users/carrd/hg-repos/hg-git-queue/tests/../hggit/git_handler.py", line 4, in <module>
from dulwich.errors import HangupException, GitProtocolError, UpdateRefsError
ImportError: No module named dulwich.errors
2012-10-31 07:16:07 +04:00
|
|
|
except ImportError:
|
2018-07-06 03:45:27 +03:00
|
|
|
print("skipped: missing feature: dulwich")
|
tests: add check for dulwich in test-url-parsing.py
Previously, if dulwich wasn't available, this test would fail with a traceback
(example included below). This changeset makes it so that the test will be
skipped with an informative message if dulwich isn't available.
Traceback (most recent call last):
File "/Users/carrd/hg-repos/hg-git-queue/tests/test-url-parsing.py", line 6, in <module>
from hggit.git_handler import GitHandler
File "/Users/carrd/hg-repos/hg-git-queue/tests/../hggit/__init__.py", line 42, in <module>
import gitrepo, hgrepo
File "/Users/carrd/hg-repos/hg-git-queue/tests/../hggit/gitrepo.py", line 13, in <module>
from git_handler import GitHandler
File "/Users/carrd/hg-repos/hg-git-queue/tests/../hggit/git_handler.py", line 4, in <module>
from dulwich.errors import HangupException, GitProtocolError, UpdateRefsError
ImportError: No module named dulwich.errors
2012-10-31 07:16:07 +04:00
|
|
|
sys.exit(80)
|
|
|
|
|
2009-10-20 21:33:06 +04:00
|
|
|
|
2009-10-28 05:39:45 +03:00
|
|
|
class TestUrlParsing(object):
|
2009-10-20 21:33:06 +04:00
|
|
|
def setUp(self):
|
|
|
|
# create a test repo location.
|
2018-07-06 03:45:27 +03:00
|
|
|
self.tmpdir = tempfile.mkdtemp("hg-git_url-test")
|
2009-10-20 21:33:06 +04:00
|
|
|
commands.init(ui.ui(), self.tmpdir)
|
|
|
|
repo = hg.repository(ui.ui(), self.tmpdir)
|
|
|
|
self.handler = GitHandler(repo, ui.ui())
|
2009-10-28 05:39:45 +03:00
|
|
|
|
2009-10-20 21:33:06 +04:00
|
|
|
def tearDown(self):
|
|
|
|
# remove the temp repo
|
|
|
|
shutil.rmtree(self.tmpdir)
|
2009-10-28 05:39:45 +03:00
|
|
|
|
|
|
|
def assertEquals(self, l, r):
|
2018-07-06 03:45:27 +03:00
|
|
|
print("%% expect %r" % (r,))
|
|
|
|
print(l)
|
2009-10-28 05:39:45 +03:00
|
|
|
assert l == r
|
|
|
|
|
2009-10-20 21:33:06 +04:00
|
|
|
def test_ssh_github_style_slash(self):
|
|
|
|
url = "git+ssh://git@github.com/webjam/webjam.git"
|
|
|
|
client, path = self.handler.get_transport_and_path(url)
|
2018-07-06 03:45:27 +03:00
|
|
|
self.assertEquals(path, "/webjam/webjam.git")
|
|
|
|
self.assertEquals(client.host, "git@github.com")
|
2009-10-28 05:39:45 +03:00
|
|
|
|
2012-04-21 06:16:32 +04:00
|
|
|
def test_ssh_github_style_colon_number_starting_username(self):
|
|
|
|
url = "git+ssh://git@github.com:42qu/vps.git"
|
|
|
|
client, path = self.handler.get_transport_and_path(url)
|
2018-07-06 03:45:27 +03:00
|
|
|
self.assertEquals(path, "42qu/vps.git")
|
|
|
|
self.assertEquals(client.host, "git@github.com")
|
2012-04-21 06:16:32 +04:00
|
|
|
|
2009-10-20 21:33:06 +04:00
|
|
|
def test_ssh_github_style_colon(self):
|
|
|
|
url = "git+ssh://git@github.com:webjam/webjam.git"
|
|
|
|
client, path = self.handler.get_transport_and_path(url)
|
2018-07-06 03:45:27 +03:00
|
|
|
self.assertEquals(path, "webjam/webjam.git")
|
|
|
|
self.assertEquals(client.host, "git@github.com")
|
2009-10-28 05:39:45 +03:00
|
|
|
|
2009-10-20 21:33:06 +04:00
|
|
|
def test_ssh_heroku_style(self):
|
|
|
|
url = "git+ssh://git@heroku.com:webjam.git"
|
|
|
|
client, path = self.handler.get_transport_and_path(url)
|
2018-07-06 03:45:27 +03:00
|
|
|
self.assertEquals(path, "webjam.git")
|
|
|
|
self.assertEquals(client.host, "git@heroku.com")
|
2012-01-28 07:48:55 +04:00
|
|
|
# also test that it works even if heroku isn't in the name
|
|
|
|
url = "git+ssh://git@compatible.com:webjam.git"
|
|
|
|
client, path = self.handler.get_transport_and_path(url)
|
2018-07-06 03:45:27 +03:00
|
|
|
self.assertEquals(path, "webjam.git")
|
|
|
|
self.assertEquals(client.host, "git@compatible.com")
|
2012-01-28 07:48:55 +04:00
|
|
|
|
|
|
|
def test_ssh_heroku_style_with_trailing_slash(self):
|
|
|
|
# some versions of mercurial add a trailing slash even if
|
|
|
|
# the user didn't supply one.
|
|
|
|
url = "git+ssh://git@heroku.com:webjam.git/"
|
|
|
|
client, path = self.handler.get_transport_and_path(url)
|
2018-07-06 03:45:27 +03:00
|
|
|
self.assertEquals(path, "webjam.git")
|
|
|
|
self.assertEquals(client.host, "git@heroku.com")
|
2012-01-28 07:48:55 +04:00
|
|
|
|
|
|
|
def test_heroku_style_with_port(self):
|
|
|
|
url = "git+ssh://git@heroku.com:999:webjam.git"
|
|
|
|
client, path = self.handler.get_transport_and_path(url)
|
2018-07-06 03:45:27 +03:00
|
|
|
self.assertEquals(path, "webjam.git")
|
|
|
|
self.assertEquals(client.host, "git@heroku.com")
|
|
|
|
self.assertEquals(client.port, "999")
|
2009-10-28 05:39:45 +03:00
|
|
|
|
2009-10-20 21:33:06 +04:00
|
|
|
def test_gitdaemon_style(self):
|
|
|
|
url = "git://github.com/webjam/webjam.git"
|
|
|
|
client, path = self.handler.get_transport_and_path(url)
|
2018-07-06 03:45:27 +03:00
|
|
|
self.assertEquals(path, "/webjam/webjam.git")
|
2010-07-05 20:47:34 +04:00
|
|
|
try:
|
2018-07-06 03:45:27 +03:00
|
|
|
self.assertEquals(client._host, "github.com")
|
2010-07-05 20:47:34 +04:00
|
|
|
except AttributeError:
|
2018-07-06 03:45:27 +03:00
|
|
|
self.assertEquals(client.host, "github.com")
|
2009-10-28 05:39:45 +03:00
|
|
|
|
2011-07-13 12:51:16 +04:00
|
|
|
def test_ssh_github_style_slash_with_port(self):
|
|
|
|
url = "git+ssh://git@github.com:10022/webjam/webjam.git"
|
|
|
|
client, path = self.handler.get_transport_and_path(url)
|
2018-07-06 03:45:27 +03:00
|
|
|
self.assertEquals(path, "/webjam/webjam.git")
|
|
|
|
self.assertEquals(client.host, "git@github.com")
|
|
|
|
self.assertEquals(client.port, "10022")
|
2011-07-13 12:51:16 +04:00
|
|
|
|
|
|
|
def test_gitdaemon_style_with_port(self):
|
|
|
|
url = "git://github.com:19418/webjam/webjam.git"
|
|
|
|
client, path = self.handler.get_transport_and_path(url)
|
2018-07-06 03:45:27 +03:00
|
|
|
self.assertEquals(path, "/webjam/webjam.git")
|
2011-07-13 12:51:16 +04:00
|
|
|
try:
|
2018-07-06 03:45:27 +03:00
|
|
|
self.assertEquals(client._host, "github.com")
|
2011-07-13 12:51:16 +04:00
|
|
|
except AttributeError:
|
2018-07-06 03:45:27 +03:00
|
|
|
self.assertEquals(client.host, "github.com")
|
|
|
|
self.assertEquals(client._port, "19418")
|
|
|
|
|
2009-10-20 21:33:06 +04:00
|
|
|
|
2018-07-06 03:45:27 +03:00
|
|
|
if __name__ == "__main__":
|
2009-10-28 05:39:45 +03:00
|
|
|
tc = TestUrlParsing()
|
2018-07-06 03:45:27 +03:00
|
|
|
for test in sorted([t for t in dir(tc) if t.startswith("test_")]):
|
2009-10-28 05:39:45 +03:00
|
|
|
tc.setUp()
|
|
|
|
getattr(tc, test)()
|
|
|
|
tc.tearDown()
|