From baa39b2b99df0c0d44e3c9a179e802764064abf4 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Mar 10 2017 07:22:31 +0000 Subject: Load module name correctly even if push url ends in slash Fix #192 Signed-off-by: Chenxiong Qi --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 7ded7f1..66dd7e2 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -590,7 +590,7 @@ class Commands(object): # FIXME # if self.distgit_namespaced: # self._module_name = "/".join(parts.path.split("/")[-2:]) - module_name = posixpath.basename(parts.path) + module_name = posixpath.basename(parts.path.strip('/')) if module_name.endswith('.git'): module_name = module_name[:-len('.git')] diff --git a/tests/test_commands.py b/tests/test_commands.py index aae6921..891b29a 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -543,3 +543,25 @@ class TestTagInheritanceTag(CommandTestCase): cmd = self.make_commands() self.assertRaises(rpkgError, cmd.check_inheritance, build_target, dest_tag) + + +class TestLoadModuleNameFromSpecialPushURL(CommandTestCase): + """Test load module name from a special push url that ends in / + + For issue: https://pagure.io/rpkg/issue/192 + """ + + def setUp(self): + super(TestLoadModuleNameFromSpecialPushURL, self).setUp() + + self.case_repo = tempfile.mkdtemp(prefix='case-test-load-module-name-') + cmd = ['git', 'clone', '{0}/'.format(self.repo_path), self.case_repo] + self.run_cmd(cmd) + + def tearDown(self): + shutil.rmtree(self.case_repo) + super(TestLoadModuleNameFromSpecialPushURL, self).tearDown() + + def test_load_module_name(self): + cmd = self.make_commands(path=self.case_repo) + self.assertEqual(os.path.basename(self.repo_path), cmd.module_name)