diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-10-30 11:48:24 +0200 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2014-06-05 14:20:05 +0300 |
commit | 89dd7594600b05c8457c65fa56e04cb985446ba3 (patch) | |
tree | c41ff60ea3b0470793548aef59443374a2aba5e8 | |
parent | 92c419368bf27aa790ef97477d26e5ff4d83fdfd (diff) | |
download | git-buildpackage-89dd7594600b05c8457c65fa56e04cb985446ba3.tar.gz git-buildpackage-89dd7594600b05c8457c65fa56e04cb985446ba3.tar.bz2 git-buildpackage-89dd7594600b05c8457c65fa56e04cb985446ba3.zip |
tests: add unittests for gbp.rpm
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
23 files changed, 446 insertions, 0 deletions
diff --git a/tests/test_rpm.py b/tests/test_rpm.py new file mode 100644 index 00000000..d57ea575 --- /dev/null +++ b/tests/test_rpm.py @@ -0,0 +1,201 @@ +# vim: set fileencoding=utf-8 : +# +# (C) 2012 Intel Corporation <markus.lehtonen@linux.intel.com> +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +"""Test the classes under L{gbp.rpm}""" + +import filecmp +import os +import shutil +import tempfile +from nose.tools import assert_raises + +from gbp.errors import GbpError +from gbp.rpm import (SrcRpmFile, SpecFile, parse_srpm, parse_spec, guess_spec, + NoSpecError) + +DATA_DIR = os.path.abspath(os.path.splitext(__file__)[0] + '_data') +SRPM_DIR = os.path.join(DATA_DIR, 'srpms') +SPEC_DIR = os.path.join(DATA_DIR, 'specs') + +class TestSrcRpmFile(object): + """Test L{gbp.rpm.SrcRpmFile}""" + + def setup(self): + self.tmpdir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.') + + def teardown(self): + shutil.rmtree(self.tmpdir) + + def test_srpm(self): + """Test parsing of a source rpm""" + srpm = SrcRpmFile(os.path.join(SRPM_DIR, 'gbp-test-1.0-1.src.rpm')) + assert srpm.version == {'release': '1', 'upstreamversion': '1.0'} + assert srpm.name == 'gbp-test' + assert srpm.upstreamversion == '1.0' + assert srpm.packager is None + + def test_srpm_2(self): + """Test parsing of another source rpm""" + srpm = SrcRpmFile(os.path.join(SRPM_DIR, 'gbp-test2-3.0-0.src.rpm')) + assert srpm.version == {'release': '0', 'upstreamversion': '3.0', + 'epoch': '2'} + assert srpm.packager == 'Markus Lehtonen '\ + '<markus.lehtonen@linux.intel.com>' + + def test_unpack_srpm(self): + """Test unpacking of a source rpm""" + srpm = SrcRpmFile(os.path.join(SRPM_DIR, 'gbp-test-1.0-1.src.rpm')) + srpm.unpack(self.tmpdir) + for fn in ['gbp-test-1.0.tar.bz2', 'foo.txt', 'bar.tar.gz', 'my.patch', + 'my2.patch', 'my3.patch']: + assert os.path.exists(os.path.join(self.tmpdir, fn)), \ + "%s not found" % fn + + +class TestSpecFile(object): + """Test L{gbp.rpm.SpecFile}""" + + def setup(self): + self.tmpdir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.') + + def teardown(self): + shutil.rmtree(self.tmpdir) + + def test_spec(self): + """Test parsing of a valid spec file""" + spec_filepath = os.path.join(SPEC_DIR, 'gbp-test.spec') + spec = SpecFile(spec_filepath) + + # Test basic properties + assert spec.specfile == spec_filepath + assert spec.specdir == os.path.dirname(spec_filepath) + assert spec.specpath == spec_filepath + + assert spec.name == 'gbp-test' + assert spec.packager is None + + assert spec.upstreamversion == '1.0' + assert spec.release == '1' + assert spec.epoch is None + assert spec.version == {'release': '1', 'upstreamversion': '1.0'} + + orig = spec.orig_src + assert orig['filename'] == 'gbp-test-1.0.tar.bz2' + assert orig['filename_base'] == 'gbp-test-1.0' + assert orig['archive_fmt'] == 'tar' + assert orig['compression'] == 'bzip2' + assert orig['prefix'] == 'gbp-test/' + + def test_spec_2(self): + """Test parsing of another valid spec file""" + spec_filepath = os.path.join(SPEC_DIR, 'gbp-test2.spec') + spec = SpecFile(spec_filepath) + + # Test basic properties + assert spec.name == 'gbp-test2' + assert spec.packager == 'Markus Lehtonen ' \ + '<markus.lehtonen@linux.intel.com>' + + assert spec.epoch == '2' + assert spec.version == {'release': '0', 'upstreamversion': '3.0', + 'epoch': '2'} + + orig = spec.orig_src + assert orig['filename'] == 'gbp-test2-3.0.tar.gz' + assert orig['full_path'] == 'ftp://ftp.host.com/gbp-test2-3.0.tar.gz' + assert orig['archive_fmt'] == 'tar' + assert orig['compression'] == 'gzip' + assert orig['prefix'] == '' + + def test_spec_3(self): + """Test parsing of yet another valid spec file""" + spec_filepath = os.path.join(SPEC_DIR, 'gbp-test-native.spec') + spec = SpecFile(spec_filepath) + + # Test basic properties + assert spec.name == 'gbp-test-native' + orig = spec.orig_src + assert orig['filename'] == 'gbp-test-native-1.0.zip' + assert orig['archive_fmt'] == 'zip' + assert orig['compression'] == None + assert orig['prefix'] == 'gbp-test-native-1.0/' + + def test_spec_4(self): + """Test parsing of spec without orig tarball""" + spec_filepath = os.path.join(SPEC_DIR, 'gbp-test-native2.spec') + spec = SpecFile(spec_filepath) + + # Test basic properties + assert spec.name == 'gbp-test-native2' + assert spec.orig_src is None + + def test_update_spec(self): + """Test spec autoupdate functionality""" + # Create temporary spec file + tmp_spec = os.path.join(self.tmpdir, 'gbp-test.spec') + shutil.copy2(os.path.join(SPEC_DIR, 'gbp-test.spec'), tmp_spec) + + reference_spec = os.path.join(SPEC_DIR, 'gbp-test-reference.spec') + spec = SpecFile(tmp_spec) + spec.update_patches(['new.patch']) + spec.write_spec_file() + + assert filecmp.cmp(tmp_spec, reference_spec) is True + + def test_quirks(self): + """Test spec that is broken/has anomalities""" + spec_filepath = os.path.join(SPEC_DIR, 'gbp-test-quirks.spec') + spec = SpecFile(spec_filepath) + + # Check that we quess orig source and prefix correctly + assert spec.orig_src['prefix'] == 'foobar/' + + +class TestUtilityFunctions(object): + """Test utility functions of L{gbp.rpm}""" + + def test_parse_spec(self): + """Test parse_spec() function""" + parse_spec(os.path.join(SPEC_DIR, 'gbp-test.spec')) + with assert_raises(NoSpecError): + parse_spec(os.path.join(DATA_DIR, 'notexists.spec')) + with assert_raises(GbpError): + parse_spec(os.path.join(SRPM_DIR, 'gbp-test-1.0-1.src.rpm')) + + def test_parse_srpm(self): + """Test parse_srpm() function""" + parse_srpm(os.path.join(SRPM_DIR, 'gbp-test-1.0-1.src.rpm')) + with assert_raises(GbpError): + parse_srpm(os.path.join(DATA_DIR, 'notexists.src.rpm')) + with assert_raises(GbpError): + parse_srpm(os.path.join(SPEC_DIR, 'gbp-test.spec')) + + def test_guess_spec(self): + """Test guess_spec() function""" + # Spec not found + with assert_raises(NoSpecError): + guess_spec(DATA_DIR, recursive=False) + # Multiple spec files + with assert_raises(NoSpecError): + guess_spec(DATA_DIR, recursive=True) + with assert_raises(NoSpecError): + guess_spec(SPEC_DIR, recursive=False) + # Spec found + spec_fn = guess_spec(SPEC_DIR, recursive=False, + preferred_name = 'gbp-test2.spec') + assert spec_fn == os.path.join(SPEC_DIR, 'gbp-test2.spec') + +# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: diff --git a/tests/test_rpm_data/rpmbuild/SOURCES/bar.tar.gz b/tests/test_rpm_data/rpmbuild/SOURCES/bar.tar.gz Binary files differnew file mode 100644 index 00000000..f5dae803 --- /dev/null +++ b/tests/test_rpm_data/rpmbuild/SOURCES/bar.tar.gz diff --git a/tests/test_rpm_data/rpmbuild/SOURCES/foo.txt b/tests/test_rpm_data/rpmbuild/SOURCES/foo.txt new file mode 100644 index 00000000..25ed442f --- /dev/null +++ b/tests/test_rpm_data/rpmbuild/SOURCES/foo.txt @@ -0,0 +1,3 @@ +FOO: + +file for testing rpm support of git-buildpackage. diff --git a/tests/test_rpm_data/rpmbuild/SOURCES/gbp-test-1.0.tar.bz2 b/tests/test_rpm_data/rpmbuild/SOURCES/gbp-test-1.0.tar.bz2 Binary files differnew file mode 100644 index 00000000..7d0759fe --- /dev/null +++ b/tests/test_rpm_data/rpmbuild/SOURCES/gbp-test-1.0.tar.bz2 diff --git a/tests/test_rpm_data/rpmbuild/SOURCES/gbp-test-native-1.0.zip b/tests/test_rpm_data/rpmbuild/SOURCES/gbp-test-native-1.0.zip Binary files differnew file mode 100644 index 00000000..22a273d1 --- /dev/null +++ b/tests/test_rpm_data/rpmbuild/SOURCES/gbp-test-native-1.0.zip diff --git a/tests/test_rpm_data/rpmbuild/SOURCES/gbp-test2-3.0.tar.gz b/tests/test_rpm_data/rpmbuild/SOURCES/gbp-test2-3.0.tar.gz Binary files differnew file mode 100644 index 00000000..7b3eaf3c --- /dev/null +++ b/tests/test_rpm_data/rpmbuild/SOURCES/gbp-test2-3.0.tar.gz diff --git a/tests/test_rpm_data/rpmbuild/SOURCES/my.patch b/tests/test_rpm_data/rpmbuild/SOURCES/my.patch new file mode 100644 index 00000000..50870df2 --- /dev/null +++ b/tests/test_rpm_data/rpmbuild/SOURCES/my.patch @@ -0,0 +1,9 @@ +diff --git a/dummy.sh b/dummy.sh +index 8c33db6..6f04268 100755 +--- dummy.sh ++++ dummy.sh +@@ -1,3 +1,3 @@ + #!/bin/sh + +-echo "Hello world" ++echo "Hello GBP" diff --git a/tests/test_rpm_data/rpmbuild/SOURCES/my2.patch b/tests/test_rpm_data/rpmbuild/SOURCES/my2.patch new file mode 100644 index 00000000..ad5ca2d2 --- /dev/null +++ b/tests/test_rpm_data/rpmbuild/SOURCES/my2.patch @@ -0,0 +1,7 @@ +diff --git a/mydir/myfile.txt b/mydir/myfile.txt +new file mode 100644 +index 0000000..2cdad29 +--- /dev/null ++++ b/mydir/myfile.txt +@@ -0,0 +1 @@ ++Dummy diff --git a/tests/test_rpm_data/rpmbuild/SOURCES/my3.patch b/tests/test_rpm_data/rpmbuild/SOURCES/my3.patch new file mode 100644 index 00000000..9fee859d --- /dev/null +++ b/tests/test_rpm_data/rpmbuild/SOURCES/my3.patch @@ -0,0 +1,7 @@ +diff --git a/README b/README +index a1311cb..a59f1b9 100644 +--- a/README ++++ b/README +@@ -1 +1 @@ +-Just for testing git-buildpackage. ++Just for testing GBP. diff --git a/tests/test_rpm_data/rpmbuild/SPECS/gbp-test-native.spec b/tests/test_rpm_data/rpmbuild/SPECS/gbp-test-native.spec new file mode 100644 index 00000000..38b07e48 --- /dev/null +++ b/tests/test_rpm_data/rpmbuild/SPECS/gbp-test-native.spec @@ -0,0 +1,34 @@ +Name: gbp-test-native +Summary: Test package for git-buildpackage +Version: 1.0 +Release: 1 +Group: Development/Libraries +License: GPLv2 +Source1: %{name}-%{version}.zip +BuildRequires: unzip + +%description +Package for testing the RPM functionality of git-buildpackage. +Mimics a "native" package + + +%prep +unzip %{SOURCE1} +%setup -T -D + + +%build +make + + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/%{_datadir}/%{name} +cp -R * %{buildroot}/%{_datadir}/%{name} + + + +%files +%defattr(-,root,root,-) +%dir %{_datadir}/%{name} +%{_datadir}/%{name} diff --git a/tests/test_rpm_data/rpmbuild/SPECS/gbp-test-native2.spec b/tests/test_rpm_data/rpmbuild/SPECS/gbp-test-native2.spec new file mode 100644 index 00000000..34fd33dc --- /dev/null +++ b/tests/test_rpm_data/rpmbuild/SPECS/gbp-test-native2.spec @@ -0,0 +1,35 @@ +Name: gbp-test-native2 +Summary: Test package for git-buildpackage +Version: 2.0 +Release: 0 +Group: Development/Libraries +License: GPLv2 +Source: foo.txt +BuildRequires: unzip + +%description +Package for testing the RPM functionality of git-buildpackage. +Mimics a "native" package that doesn't have any source tarball. + + +%prep +# Just create build dir +%setup -T -c +cp %{SOURCE0} . + + +%build +# Nothing to do + + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/%{_datadir}/%{name} +cp -R * %{buildroot}/%{_datadir}/%{name} + + + +%files +%defattr(-,root,root,-) +%dir %{_datadir}/%{name} +%{_datadir}/%{name} diff --git a/tests/test_rpm_data/rpmbuild/SPECS/gbp-test.spec b/tests/test_rpm_data/rpmbuild/SPECS/gbp-test.spec new file mode 100644 index 00000000..8a07d662 --- /dev/null +++ b/tests/test_rpm_data/rpmbuild/SPECS/gbp-test.spec @@ -0,0 +1,42 @@ +Name: gbp-test +Summary: Test package for git-buildpackage +Version: 1.0 +Release: 1 +Group: Development/Libraries +License: GPLv2 +Source: %{name}-%{version}.tar.bz2 +Source1: foo.txt +Source20: bar.tar.gz +# GbpIgnorePatch: 0 +Patch0: my.patch +Patch10: my2.patch +Patch20: my3.patch + + +%description +Package for testing the RPM functionality of git-buildpackage. + + +%prep +%setup -n %{name} -a 20 + +%patch0 +%patch10 -p1 + + +%build +make + + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/%{_datadir}/%{name} +cp -R * %{buildroot}/%{_datadir}/%{name} +install %{SOURCE0} %{buildroot}/%{_datadir}/%{name} + + + +%files +%defattr(-,root,root,-) +%dir %{_datadir}/%{name} +%{_datadir}/%{name} diff --git a/tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec b/tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec new file mode 100644 index 00000000..932b8e8f --- /dev/null +++ b/tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec @@ -0,0 +1,43 @@ +Name: gbp-test2 +Summary: Test package 2 for git-buildpackage +Epoch: 2 +Version: 3.0 +Release: 0 +Group: Development/Libraries +License: GPLv2 +Source10: ftp://ftp.host.com/%{name}-%{version}.tar.gz +Source: foo.txt +Source20: bar.tar.gz +# GbpIgnorePatch: 0 +Patch: my.patch +Patch10: my2.patch +Patch20: my3.patch +Packager: Markus Lehtonen <markus.lehtonen@linux.intel.com> + +%description +Package for testing the RPM functionality of git-buildpackage. + + +%prep +%setup -T -n %{name}-%{version} -c -a 10 + +%patch +%patch -P 10 -p1 + + +%build +make + + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/%{_datadir}/%{name} +cp -R * %{buildroot}/%{_datadir}/%{name} +install %{SOURCE0} %{buildroot}/%{_datadir}/%{name} + + + +%files +%defattr(-,root,root,-) +%dir %{_datadir}/%{name} +%{_datadir}/%{name} diff --git a/tests/test_rpm_data/specs/gbp-test-native.spec b/tests/test_rpm_data/specs/gbp-test-native.spec new file mode 120000 index 00000000..60de36f2 --- /dev/null +++ b/tests/test_rpm_data/specs/gbp-test-native.spec @@ -0,0 +1 @@ +../rpmbuild/SPECS/gbp-test-native.spec
\ No newline at end of file diff --git a/tests/test_rpm_data/specs/gbp-test-native2.spec b/tests/test_rpm_data/specs/gbp-test-native2.spec new file mode 120000 index 00000000..ad13ad6a --- /dev/null +++ b/tests/test_rpm_data/specs/gbp-test-native2.spec @@ -0,0 +1 @@ +../rpmbuild/SPECS/gbp-test-native2.spec
\ No newline at end of file diff --git a/tests/test_rpm_data/specs/gbp-test-quirks.spec b/tests/test_rpm_data/specs/gbp-test-quirks.spec new file mode 100644 index 00000000..64db07fb --- /dev/null +++ b/tests/test_rpm_data/specs/gbp-test-quirks.spec @@ -0,0 +1,18 @@ +# +# Spec for testing some quirks of spec parsing +# + +Name: pkg_name +Summary: Spec for testing some quirks of spec parsing +Version: 0.1 +Release: 1.2 +License: GPLv2 +Source1: foobar.tar.gz + +%description +Spec for testing some quirks of spec parsing. No intended for building an RPM. + +%prep +# We don't have Source0 so rpmbuild would fail, but gbp shouldn't crash +%setup -q + diff --git a/tests/test_rpm_data/specs/gbp-test-reference.spec b/tests/test_rpm_data/specs/gbp-test-reference.spec new file mode 100644 index 00000000..884a64ca --- /dev/null +++ b/tests/test_rpm_data/specs/gbp-test-reference.spec @@ -0,0 +1,43 @@ +Name: gbp-test +Summary: Test package for git-buildpackage +Version: 1.0 +Release: 1 +Group: Development/Libraries +License: GPLv2 +Source: %{name}-%{version}.tar.bz2 +Source1: foo.txt +Source20: bar.tar.gz +# GbpIgnorePatch: 0 +Patch0: my.patch +# Patches auto-generated by git-buildpackage: +Patch1: new.patch + + +%description +Package for testing the RPM functionality of git-buildpackage. + + +%prep +%setup -n %{name} -a 20 + +%patch0 +# new.patch +%patch1 -p1 + + +%build +make + + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/%{_datadir}/%{name} +cp -R * %{buildroot}/%{_datadir}/%{name} +install %{SOURCE0} %{buildroot}/%{_datadir}/%{name} + + + +%files +%defattr(-,root,root,-) +%dir %{_datadir}/%{name} +%{_datadir}/%{name} diff --git a/tests/test_rpm_data/specs/gbp-test.spec b/tests/test_rpm_data/specs/gbp-test.spec new file mode 120000 index 00000000..30ae2845 --- /dev/null +++ b/tests/test_rpm_data/specs/gbp-test.spec @@ -0,0 +1 @@ +../rpmbuild/SPECS/gbp-test.spec
\ No newline at end of file diff --git a/tests/test_rpm_data/specs/gbp-test2.spec b/tests/test_rpm_data/specs/gbp-test2.spec new file mode 120000 index 00000000..af4080cb --- /dev/null +++ b/tests/test_rpm_data/specs/gbp-test2.spec @@ -0,0 +1 @@ +../rpmbuild/SPECS/gbp-test2.spec
\ No newline at end of file diff --git a/tests/test_rpm_data/srpms/gbp-test-1.0-1.src.rpm b/tests/test_rpm_data/srpms/gbp-test-1.0-1.src.rpm Binary files differnew file mode 100644 index 00000000..74afbd6c --- /dev/null +++ b/tests/test_rpm_data/srpms/gbp-test-1.0-1.src.rpm diff --git a/tests/test_rpm_data/srpms/gbp-test-native-1.0-1.src.rpm b/tests/test_rpm_data/srpms/gbp-test-native-1.0-1.src.rpm Binary files differnew file mode 100644 index 00000000..1002aaea --- /dev/null +++ b/tests/test_rpm_data/srpms/gbp-test-native-1.0-1.src.rpm diff --git a/tests/test_rpm_data/srpms/gbp-test-native2-2.0-0.src.rpm b/tests/test_rpm_data/srpms/gbp-test-native2-2.0-0.src.rpm Binary files differnew file mode 100644 index 00000000..880b3100 --- /dev/null +++ b/tests/test_rpm_data/srpms/gbp-test-native2-2.0-0.src.rpm diff --git a/tests/test_rpm_data/srpms/gbp-test2-3.0-0.src.rpm b/tests/test_rpm_data/srpms/gbp-test2-3.0-0.src.rpm Binary files differnew file mode 100644 index 00000000..1cf12c7a --- /dev/null +++ b/tests/test_rpm_data/srpms/gbp-test2-3.0-0.src.rpm |