From 914baa636d0d5933c9e12752d55e68e976a437d4 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Nov 11 2016 10:12:38 +0000 Subject: [PATCH 1/2] Fix tests This patch fixes several errors in the tests. A workaround is added to solve the a difference between Copr and dev machine. That is, in Copr, after running rpmbuild, RPMs are not put in an arch subdirectory. Signed-off-by: Chenxiong Qi --- diff --git a/tests/commands/__init__.py b/tests/commands/__init__.py index 380dc78..d226223 100644 --- a/tests/commands/__init__.py +++ b/tests/commands/__init__.py @@ -60,6 +60,12 @@ class CommandTestCase(unittest.TestCase): clonedir = os.path.join(cloneroot, module.split('/')[-1]) open(os.path.join(clonedir, '.gitignore'), 'w').close() open(os.path.join(clonedir, 'sources'), 'w').close() + subprocess.check_call(['git', 'config', 'user.name', 'Chenxiong Qi'], + cwd=clonedir, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + subprocess.check_call(['git', 'config', 'user.email', 'cqi@redhat.com'], + cwd=clonedir, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) subprocess.check_call(['git', 'add', '.gitignore', 'sources'], cwd=clonedir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/tests/test_cli.py b/tests/test_cli.py index e29e7fe..46f06e9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import rpm import os from six.moves import configparser @@ -195,6 +196,19 @@ class TestInstall(CliTestCase): class TestLocal(CliTestCase): + def _subdir_has_arch_prefix(self): + """Check if RPMs will be put into an arch subdirectory or not + + This is a wordaround to ensure these tests can run in Fedora Copr. + """ + 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}/') + def test_local(self): with patch('sys.argv', new=['rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6', 'local']): @@ -203,7 +217,8 @@ class TestLocal(CliTestCase): self.assertFilesExists(( 'docpkg-1.2-2.el6.src.rpm', - 'x86_64/docpkg-1.2-2.el6.x86_64.rpm', + '{0}docpkg-1.2-2.el6.x86_64.rpm'.format( + 'x86_64/' if self._subdir_has_arch_prefix() else ''), )) def test_local_with_arch(self): @@ -214,7 +229,8 @@ class TestLocal(CliTestCase): self.assertFilesExists(( 'docpkg-1.2-2.el6.src.rpm', - 'i686/docpkg-1.2-2.el6.i686.rpm', + '{0}docpkg-1.2-2.el6.i686.rpm'.format( + 'i686/' if self._subdir_has_arch_prefix() else ''), )) def test_local_with_builddir(self): diff --git a/tests/test_commands.py b/tests/test_commands.py index 2e672d5..3998311 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -156,12 +156,12 @@ class LoadBranchMergeTest(CommandTestCase): try: self.cmd.load_branch_merge() except rpkgError as e: - self.assertEqual('Unable to find remote branch. Use --dist', str(e)) + self.assertEqual('Unable to find remote branch. Use --release', str(e)) else: self.fail("It's expected to raise rpkgError, but not.") - def test_load_branch_merge_using_dist_option(self): - """Ensure load_branch_merge uses dist specified via --dist + def test_load_branch_merge_using_release_option(self): + """Ensure load_branch_merge uses release specified via --release Switch to eng-rhel-6 branch, that is valid for load_branch_merge and to see if load_branch_merge still uses dist rather than such a valid diff --git a/tests/utils.py b/tests/utils.py index c386510..4d4946e 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -96,7 +96,6 @@ class CommandTestCase(Assertions, unittest.TestCase): git_cmds = [ ['git', 'config', 'user.email', 'cqi@redhat.com'], ['git', 'config', 'user.name', 'Chenxiong Qi'], - ['git', 'config', 'push.default', 'simple'], ['git', 'branch', '--track', 'eng-rhel-6', 'origin/eng-rhel-6'], ['git', 'branch', '--track', 'eng-rhel-6.5', 'origin/eng-rhel-6.5'], ['git', 'branch', '--track', 'eng-rhel-7', 'origin/eng-rhel-7'], From cd1d92d81c1c55fa74614d0c41932ce6484140c5 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Nov 11 2016 10:45:44 +0000 Subject: [PATCH 2/2] Add missing -q option to rpm command This is needed by RPM 4.8.0 in EL6. Signed-off-by: Chenxiong Qi --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 57fb0a7..28a85a9 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -1921,7 +1921,7 @@ class Commands(object): """Write the latest spec changelog entry to a clog file""" spec_file = os.path.join(self.path, self.spec) - cmd = ['rpm', '--qf', '%{CHANGELOGTEXT}\n', '--specfile', spec_file] + cmd = ['rpm', '-q', '--qf', '%{CHANGELOGTEXT}\n', '--specfile', spec_file] proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = proc.communicate() if proc.returncode > 0: