From 57c2cce7ece8cebbae93adb80255c0f6f0884029 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Nov 15 2016 08:17:36 +0000 Subject: Fix tests for running tests in Copr Three fixes are included. - Workaround of asserting RPM's existence when building package in Copr. - Workaround of translate i386 to i686 when building package in a i386 target in Copr. - Configure user.name and user.email in cloned repository in commands/test_*.py. This was detected when building packages in Fedora Copr. Signed-off-by: Chenxiong Qi --- diff --git a/tests/commands/__init__.py b/tests/commands/__init__.py index d226223..ba4d3ce 100644 --- a/tests/commands/__init__.py +++ b/tests/commands/__init__.py @@ -88,6 +88,10 @@ class CommandTestCase(unittest.TestCase): # Drop the clone shutil.rmtree(cloneroot) + def config_repo(self, repo_path): + subprocess.check_call(['git', 'config', 'user.name', 'tester'], cwd=repo_path) + subprocess.check_call(['git', 'config', 'user.email', 'tester@example.com'], cwd=repo_path) + def get_tags(self, gitdir): result = [] diff --git a/tests/commands/test_add_tag.py b/tests/commands/test_add_tag.py index 6e13404..e618f02 100644 --- a/tests/commands/test_add_tag.py +++ b/tests/commands/test_add_tag.py @@ -32,6 +32,7 @@ class CommandAddTagTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir + self.config_repo(cmd.path) # `git tag` will call $EDITOR to ask the user to write a message os.environ['GIT_EDITOR'] = ('/usr/bin/python -c "import sys; ' @@ -58,6 +59,7 @@ class CommandAddTagTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir + self.config_repo(cmd.path) cmd.add_tag(tag, message=message) @@ -79,6 +81,7 @@ class CommandAddTagTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir + self.config_repo(cmd.path) message_file = os.path.join(moduledir, 'tag_message') @@ -105,6 +108,7 @@ class CommandAddTagTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir + self.config_repo(cmd.path) cmd.add_tag(tag, message=message) @@ -130,6 +134,7 @@ class CommandAddTagTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir + self.config_repo(cmd.path) cmd.add_tag(tag, message=message) @@ -155,6 +160,7 @@ class CommandAddTagTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir + self.config_repo(cmd.path) for tag, message in tags: cmd.add_tag(tag, message=message) diff --git a/tests/commands/test_check_repo.py b/tests/commands/test_check_repo.py index 0ca24df..bfe9580 100644 --- a/tests/commands/test_check_repo.py +++ b/tests/commands/test_check_repo.py @@ -29,6 +29,7 @@ class CheckRepoCase(CommandTestCase): self.build_client, self.user, self.dist, self.target, self.quiet ) + self.config_repo(self.clonedir) def tearDown(self): super(CheckRepoCase, self).tearDown() diff --git a/tests/commands/test_delete_tag.py b/tests/commands/test_delete_tag.py index 2141059..fe67a4a 100644 --- a/tests/commands/test_delete_tag.py +++ b/tests/commands/test_delete_tag.py @@ -20,6 +20,7 @@ class CommandDeleteTagTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir + self.config_repo(cmd.path) # First, add a tag cmd.add_tag(tag, message=message) @@ -45,6 +46,7 @@ class CommandDeleteTagTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir + self.config_repo(cmd.path) # Try deleting an inexistent tag def raises(): diff --git a/tests/commands/test_list_tag.py b/tests/commands/test_list_tag.py index 8135f5e..9827867 100644 --- a/tests/commands/test_list_tag.py +++ b/tests/commands/test_list_tag.py @@ -17,6 +17,7 @@ class CommandListTagTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir + self.config_repo(cmd.path) with self.hijack_stdout() as out: cmd.list_tag() @@ -39,6 +40,7 @@ class CommandListTagTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir + self.config_repo(cmd.path) for tag, message in tags: cmd.add_tag(tag, message=message) @@ -66,6 +68,7 @@ class CommandListTagTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir + self.config_repo(cmd.path) for tag, message in tags: cmd.add_tag(tag, message=message) @@ -93,6 +96,7 @@ class CommandListTagTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir + self.config_repo(cmd.path) for tag, message in tags: cmd.add_tag(tag, message=message) @@ -120,6 +124,7 @@ class CommandListTagTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir + self.config_repo(cmd.path) for tag, message in tags: cmd.add_tag(tag, message=message) @@ -147,6 +152,7 @@ class CommandListTagTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir + self.config_repo(cmd.path) for tag, message in tags: cmd.add_tag(tag, message=message) diff --git a/tests/test_cli.py b/tests/test_cli.py index 46f06e9..d88949e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- -import rpm import os +from os.path import exists +from os.path import join from six.moves import configparser import git @@ -196,18 +197,17 @@ class TestInstall(CliTestCase): class TestLocal(CliTestCase): - def _subdir_has_arch_prefix(self): - """Check if RPMs will be put into an arch subdirectory or not + def translate_arch(self, arch): + """Translate local arch to arch the rpmbuild uses - This is a wordaround to ensure these tests can run in Fedora Copr. + This is another workaround for running tests in Copr, where when + building RPM in a i386 target, local arch is i386, but arch in RPM is + "translated" to i686. """ - macro = '%{_build_name_fmt}' - value = rpm.expandMacro(macro) - if value == macro: - # Cannot determine the macro because the macro name is - # returned. So, as a default, it has. - return True - return value.startswith('%{ARCH}/') + translation = { + 'i386': 'i686', + } + return translation.get(arch, arch) def test_local(self): with patch('sys.argv', new=['rpkg', '--path', self.cloned_repo_path, @@ -215,11 +215,14 @@ class TestLocal(CliTestCase): cli = self.new_cli() cli.local() - self.assertFilesExists(( - 'docpkg-1.2-2.el6.src.rpm', - '{0}docpkg-1.2-2.el6.x86_64.rpm'.format( - 'x86_64/' if self._subdir_has_arch_prefix() else ''), - )) + self.assertTrue(exists(join(self.cloned_repo_path, 'docpkg-1.2-2.el6.src.rpm'))) + # This covers some special cases, e.g. building in copr, that is + # RPMs are not put in arch subdirectory even if %{_build_name_fmt} + # is %{ARCH}/%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm + arch = self.translate_arch(cli.cmd.localarch) + self.assertTrue( + exists(join(self.cloned_repo_path, 'docpkg-1.2-2.el6.{0}.rpm'.format(arch))) or + exists(join(self.cloned_repo_path, '{0}/docpkg-1.2-2.el6.{0}.rpm'.format(arch)))) def test_local_with_arch(self): with patch('sys.argv', new=['rpkg', '--path', self.cloned_repo_path, @@ -227,11 +230,10 @@ class TestLocal(CliTestCase): cli = self.new_cli() cli.local() - self.assertFilesExists(( - 'docpkg-1.2-2.el6.src.rpm', - '{0}docpkg-1.2-2.el6.i686.rpm'.format( - 'i686/' if self._subdir_has_arch_prefix() else ''), - )) + self.assertTrue(exists(join(self.cloned_repo_path, 'docpkg-1.2-2.el6.src.rpm'))) + self.assertTrue( + exists(join(self.cloned_repo_path, 'docpkg-1.2-2.el6.i686.rpm')) or + exists(join(self.cloned_repo_path, 'i686/docpkg-1.2-2.el6.i686.rpm'))) def test_local_with_builddir(self): custom_builddir = os.path.join(self.cloned_repo_path, 'this-builddir')