|
- import re
- import sys
- import unittest
-
- # man git-check-ref-format
-
- reponameregex = re.compile(r'^(https://(?P<domain>github\.com)/(?P<slashpath>.*)\.git$)')
-
- def doconvert(i):
- mat = reponameregex.match(i)
-
- gd = mat.groupdict()
-
- p = gd['slashpath'].replace('/', '-')
-
- return '%s--%s' % (gd['domain'], p)
-
- if __name__ == '__main__':
- for i in sys.stdin:
- i = i.strip()
- if not i or i.startswith('#'):
- continue
-
- print(i, doconvert(i))
-
- class _TestCases(unittest.TestCase):
- def test_foo(self):
- data = [
- ('https://github.com/python/cpython.git', 'github.com--python-cpython'),
- ]
-
- for i in data:
- r = doconvert(i[0])
-
- self.assertEqual(r, i[1], msg='%s resulting in %s, should have been %s' % tuple(repr(x) for x in (i[0], r, i[1])))
|