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
|
|
|
|
|
|
|
|
try:
|
|
|
|
import dulwich
|
|
|
|
except ImportError:
|
|
|
|
print "skipped: missing feature: dulwich"
|
|
|
|
sys.exit(80)
|
|
|
|
|
|
|
|
import os, tempfile, unittest, shutil
|
2009-10-20 21:33:06 +04:00
|
|
|
from mercurial import ui, hg, commands
|
|
|
|
|
2009-11-23 21:10:32 +03:00
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir))
|
2009-10-20 21:33:06 +04:00
|
|
|
|
2009-10-28 05:39:45 +03:00
|
|
|
from hggit.git_handler import GitHandler
|
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.
|
|
|
|
self.tmpdir = tempfile.mkdtemp('hg-git_url-test')
|
|
|
|
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):
|
|
|
|
print '%% expect %r' % (r, )
|
|
|
|
print l
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
self.assertEquals(path, '42qu/vps.git')
|
|
|
|
self.assertEquals(client.host, 'git@github.com')
|
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
self.assertEquals(path, 'webjam.git')
|
|
|
|
self.assertEquals(client.host, 'git@compatible.com')
|
|
|
|
|
|
|
|
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)
|
|
|
|
self.assertEquals(path, 'webjam.git')
|
|
|
|
self.assertEquals(client.host, 'git@heroku.com')
|
|
|
|
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
self.assertEquals(path, '/webjam/webjam.git')
|
2010-07-05 20:47:34 +04:00
|
|
|
try:
|
|
|
|
self.assertEquals(client._host, 'github.com')
|
|
|
|
except AttributeError:
|
|
|
|
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)
|
|
|
|
self.assertEquals(path, '/webjam/webjam.git')
|
|
|
|
self.assertEquals(client.host, 'git@github.com')
|
|
|
|
self.assertEquals(client.port, '10022')
|
|
|
|
|
|
|
|
def test_gitdaemon_style_with_port(self):
|
|
|
|
url = "git://github.com:19418/webjam/webjam.git"
|
|
|
|
client, path = self.handler.get_transport_and_path(url)
|
|
|
|
self.assertEquals(path, '/webjam/webjam.git')
|
|
|
|
try:
|
|
|
|
self.assertEquals(client._host, 'github.com')
|
|
|
|
except AttributeError:
|
|
|
|
self.assertEquals(client.host, 'github.com')
|
|
|
|
self.assertEquals(client._port, '19418')
|
2009-10-20 21:33:06 +04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2009-10-28 05:39:45 +03:00
|
|
|
tc = TestUrlParsing()
|
2012-04-21 06:11:19 +04: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()
|