diff options
Diffstat (limited to 'tests/component/rpm/test_buildpackage_rpm.py')
-rw-r--r-- | tests/component/rpm/test_buildpackage_rpm.py | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/tests/component/rpm/test_buildpackage_rpm.py b/tests/component/rpm/test_buildpackage_rpm.py index 4f0c2905..71ff7b77 100644 --- a/tests/component/rpm/test_buildpackage_rpm.py +++ b/tests/component/rpm/test_buildpackage_rpm.py @@ -26,12 +26,12 @@ import stat import subprocess from nose import SkipTest -from nose.tools import assert_raises, eq_, ok_ # pylint: disable=E0611 +from nose.tools import assert_raises, eq_, ok_ # pylint: disable=E0611 from gbp.git import GitRepository from gbp.scripts.buildpackage_rpm import main as gbp_rpm from tests.component.rpm import RpmRepoTestBase, RPM_TEST_DATA_DIR -from tests.testutils import ls_tar, ls_zip +from tests.testutils import ls_tar, ls_zip, capture # Disable "Method could be a function warning" # pylint: disable=R0201 @@ -47,8 +47,10 @@ MOCK_NOTIFICATIONS = [] def mock_gbp(args): """Wrapper for gbp-buildpackage-rpm""" - return gbp_rpm(['arg0', '--git-notify=off'] + args + - ['-ba', '--clean', '--target=noarch', '--nodeps']) + with capture.capture_stderr(): + return gbp_rpm(['arg0', '--git-notify=off'] + args + + ['-ba', '--clean', '--target=noarch', '--nodeps']) + def mock_notify(summary, message, notify_opt): """Mock notification system""" @@ -75,7 +77,7 @@ class TestGbpRpm(RpmRepoTestBase): raise Exception("Failed to get file metadata for %s: %s" % (rpm, stderr)) return sorted([(nam, mod, dig) for dig, mod, nam in - [lin.split(None, 2) for lin in stdout.splitlines()]]) + [lin.split(None, 2) for lin in stdout.splitlines()]]) @staticmethod def check_rpms(directory): @@ -104,18 +106,7 @@ class TestGbpRpm(RpmRepoTestBase): """Run outside a git repository""" eq_(mock_gbp([]), 1) self._check_log(0, 'gbp:error: %s is not a git repository' % - os.path.abspath('.')) - - def test_invalid_config_file(self): - """Test invalid config file""" - # Create and commit dummy invalid config file - repo = GitRepository.create('.') - with open('.gbp.conf', 'w') as conffd: - conffd.write('foobar\n') - repo.add_files('.gbp.conf') - repo.commit_all('Add conf') - eq_(mock_gbp([]), 1) - self._check_log(0, 'gbp:error: File contains no section headers.') + os.path.abspath('.')) def test_native_build(self): """Basic test of native pkg""" @@ -224,7 +215,7 @@ class TestGbpRpm(RpmRepoTestBase): eq_(mock_gbp(['--git-tag', '--git-packaging-tag=rel-tag']), 1) # Re-tag - eq_(mock_gbp(['--git-retag', '--git-packaging-tag=rel-tag']), 1) + eq_(mock_gbp(['--git-retag', '--git-packaging-tag=rel-tag']), 3) self._check_log(-1, "gbp:error: '--git-retag' needs either '--git-tag'") eq_(mock_gbp(['--git-tag', '--git-packaging-tag=rel-tag', @@ -256,8 +247,8 @@ class TestGbpRpm(RpmRepoTestBase): # Dummy update to upstream branch pkg_branch = repo.get_branch() upstr_branch = 'upstream' - orig_files = ['gbp-test/' + path for \ - path in repo.ls_tree(upstr_branch)] + ['gbp-test'] + orig_files = ['gbp-test/' + path for + path in repo.ls_tree(upstr_branch)] + ['gbp-test'] repo.set_branch(upstr_branch) with open('new-file', 'w') as fobj: fobj.write('New file\n') @@ -329,7 +320,7 @@ class TestGbpRpm(RpmRepoTestBase): eq_(len(repo.get_commits(until='pristine-tar')), 2) shutil.rmtree('../rpmbuild') - # Second time no pristine-tar should not be commited + # Second time no pristine-tar should not be committed eq_(mock_gbp(['--git-pristine-tar-commit']), 0) eq_(len(repo.get_commits(until='pristine-tar')), 2) @@ -384,7 +375,7 @@ class TestGbpRpm(RpmRepoTestBase): sub_files = sub_repo.ls_tree('HEAD') upstr_files = ['gbp-test/' + path for - path in repo.ls_tree(upstr_branch)] + path in repo.ls_tree(upstr_branch)] # Test the "no" option eq_(mock_gbp(['--git-no-submodules', '--git-upstream-tree=%s' % @@ -398,7 +389,7 @@ class TestGbpRpm(RpmRepoTestBase): upstr_branch, '--git-ignore-new']), 0) tar_files = ls_tar('../rpmbuild/SOURCES/gbp-test-1.1.tar.bz2', False) ref_files = upstr_files + ['gbp-test/gbp-test-native.repo/' + path for - path in sub_files] + path in sub_files] self.check_files(ref_files, tar_files) shutil.rmtree('../rpmbuild') @@ -407,6 +398,10 @@ class TestGbpRpm(RpmRepoTestBase): repo.create('gbp-test-native.repo') eq_(mock_gbp(['--git-submodules', '--git-upstream-tree=%s' % upstr_branch, '--git-ignore-new']), 2) + self._check_log(-2, + ".*Error generating submodules' archives: " + "Failed to list submodules of [0-9a-f]{40}: fatal: " + "not a tree object") def test_option_submodules_native(self): """Test the --git-submodules option for native packages""" @@ -426,7 +421,7 @@ class TestGbpRpm(RpmRepoTestBase): zip_files = ls_zip('../rpmbuild/SOURCES/gbp-test-native-1.0.zip', False) ref_files = master_files + \ ['gbp-test-native-1.0/gbp-test-native2.repo/' + path for - path in sub_files] + path in sub_files] self.check_files(ref_files, zip_files) # Test submodule failure @@ -551,7 +546,7 @@ class TestGbpRpm(RpmRepoTestBase): # Test exporting of some other commit than HEAD eq_(mock_gbp(['--git-export=release/1.0-1']), 0) eq_(os.listdir('../rpmbuild/RPMS/noarch'), - ['gbp-test-1.0-1.noarch.rpm']) + ['gbp-test-1.0-1.noarch.rpm']) self.check_rpms('../rpmbuild/RPMS/*') # Modify one tracked file, create one untracked and one ignored file @@ -613,4 +608,3 @@ class TestGbpRpm(RpmRepoTestBase): # Packaging dir should be taken from spec file if it is defined eq_(mock_gbp(['--git-packaging-dir=foo', '--git-spec-file=packaging/gbp-test-native.spec']), 0) - |