diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2013-01-03 12:43:08 +0200 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2014-01-14 13:48:22 +0200 |
commit | 63fb45285be7bf8fa701b9b266cebd13fae2de59 (patch) | |
tree | b27c9d5d57812f0e8c12256b52797f169aee258e /tests | |
parent | 5dbea03caa4eb626084cbe2a6b41bb7ac6501cc1 (diff) | |
download | git-buildpackage-63fb45285be7bf8fa701b9b266cebd13fae2de59.tar.gz git-buildpackage-63fb45285be7bf8fa701b9b266cebd13fae2de59.tar.bz2 git-buildpackage-63fb45285be7bf8fa701b9b266cebd13fae2de59.zip |
rpm refactor: rewrite set_tag functionality
In addition to refactoring, make sure that we keep the internal _tags
structure in sync.
Changes the default place for new tags: add new tags after the 'Name:'
tag instead of 'Release:'.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_rpm.py | 43 | ||||
-rw-r--r-- | tests/test_rpm_data/specs/gbp-test-reference2.spec | 2 | ||||
-rw-r--r-- | tests/test_rpm_data/specs/gbp-test-updates-reference.spec | 39 | ||||
-rw-r--r-- | tests/test_rpm_data/specs/gbp-test-updates.spec | 43 |
4 files changed, 122 insertions, 5 deletions
diff --git a/tests/test_rpm.py b/tests/test_rpm.py index 55bb4159..88eb571f 100644 --- a/tests/test_rpm.py +++ b/tests/test_rpm.py @@ -30,6 +30,14 @@ 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 SpecFileTester(SpecFile): + """Helper class for testing""" + + def protected(self, name): + """Get a protected member""" + return super(SpecFileTester, self).__getattribute__(name) + + class TestSrcRpmFile(object): """Test L{gbp.rpm.SrcRpmFile}""" @@ -77,7 +85,7 @@ class TestSpecFile(object): 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) + spec = SpecFileTester(spec_filepath) # Test basic properties assert spec.specfile == spec_filepath @@ -154,7 +162,7 @@ class TestSpecFile(object): # Test adding the VCS tag reference_spec = os.path.join(SPEC_DIR, 'gbp-test-reference2.spec') - spec.set_tag('vcs', 'myvcstag') + spec.set_tag('VCS', None, 'myvcstag') spec.write_spec_file() assert filecmp.cmp(tmp_spec, reference_spec) is True @@ -166,14 +174,41 @@ class TestSpecFile(object): reference_spec = os.path.join(SPEC_DIR, 'gbp-test2-reference2.spec') spec = SpecFile(tmp_spec) spec.update_patches(['1.patch', '2.patch']) - spec.set_tag('vcs', 'myvcstag') + spec.set_tag('VCS', None, 'myvcstag') spec.update_patches(['new.patch']) spec.write_spec_file() assert filecmp.cmp(tmp_spec, reference_spec) is True # Test removing the VCS tag reference_spec = os.path.join(SPEC_DIR, 'gbp-test2-reference.spec') - spec.set_tag('vcs', '') + spec.set_tag('VCS', None, '') + spec.write_spec_file() + assert filecmp.cmp(tmp_spec, reference_spec) is True + + def test_modifying(self): + """Test updating/deleting of tags and macros""" + tmp_spec = os.path.join(self.tmpdir, 'gbp-test.spec') + shutil.copy2(os.path.join(SPEC_DIR, 'gbp-test-updates.spec'), tmp_spec) + reference_spec = os.path.join(SPEC_DIR, + 'gbp-test-updates-reference.spec') + spec = SpecFileTester(tmp_spec) + + # Mangle tags + prev = spec.protected('_delete_tag')('Vendor', None) + spec.protected('_set_tag')('License', None, 'new license', prev) + spec.protected('_delete_tag')('source', 0) + spec.protected('_delete_tag')('patch', 0) + spec.protected('_delete_tag')('patch', -1) + prev = spec.protected('_delete_tag')('invalidtag', None) + + with assert_raises(GbpError): + # Check that setting empty value fails + spec.protected('_set_tag')('Version', None, '', prev) + with assert_raises(GbpError): + # Check that setting invalid tag with public method fails + spec.set_tag('invalidtag', None, 'value') + + # Check resulting spec file spec.write_spec_file() assert filecmp.cmp(tmp_spec, reference_spec) is True diff --git a/tests/test_rpm_data/specs/gbp-test-reference2.spec b/tests/test_rpm_data/specs/gbp-test-reference2.spec index f006fc77..1cd922b2 100644 --- a/tests/test_rpm_data/specs/gbp-test-reference2.spec +++ b/tests/test_rpm_data/specs/gbp-test-reference2.spec @@ -1,8 +1,8 @@ Name: gbp-test +VCS: myvcstag Summary: Test package for git-buildpackage Version: 1.0 Release: 1 -VCS: myvcstag Group: Development/Libraries License: GPLv2 Source: %{name}-%{version}.tar.bz2 diff --git a/tests/test_rpm_data/specs/gbp-test-updates-reference.spec b/tests/test_rpm_data/specs/gbp-test-updates-reference.spec new file mode 100644 index 00000000..557f8b77 --- /dev/null +++ b/tests/test_rpm_data/specs/gbp-test-updates-reference.spec @@ -0,0 +1,39 @@ +# +# Spec file for testing deleting/adding/updating tags and macros +# + +# Gbp-Undefined-Tag: foobar + +# Test that we accept different cases +Name: my_name +Version: 0 +Release: 1 +Summary: my_summary +License: new license +Distribution: my_distribution +Group: my_group +Packager: my_packager +Url: my_url +Vcs: my_vcs +BuildRoot: my_buildroot +Provides: my_provides +Requires: my_requires +Conflicts: my_conflicts +Obsoletes: my_obsoletes +BuildConflicts: my_buildconflicts +BuildRequires: my_buildrequires +AutoReqProv: No +AutoReq: No +AutoProv: No +DistTag: my_disttag +BugUrl: my_bugurl +Collections: my_collections + +%description +Package for testing GBP. + +%prep + +%build + +%install diff --git a/tests/test_rpm_data/specs/gbp-test-updates.spec b/tests/test_rpm_data/specs/gbp-test-updates.spec new file mode 100644 index 00000000..1cdcb212 --- /dev/null +++ b/tests/test_rpm_data/specs/gbp-test-updates.spec @@ -0,0 +1,43 @@ +# +# Spec file for testing deleting/adding/updating tags and macros +# + +# Gbp-Undefined-Tag: foobar + +# Test that we accept different cases +Name: my_name +Version: 0 +Release: 1 +Summary: my_summary +License: my_license +Distribution: my_distribution +Vendor: my_vendor +Group: my_group +Packager: my_packager +Url: my_url +Vcs: my_vcs +Source: my_source +Patch: my_%patch_fn_base +Patch0: my_%{patch_fn_base}0 +BuildRoot: my_buildroot +Provides: my_provides +Requires: my_requires +Conflicts: my_conflicts +Obsoletes: my_obsoletes +BuildConflicts: my_buildconflicts +BuildRequires: my_buildrequires +AutoReqProv: No +AutoReq: No +AutoProv: No +DistTag: my_disttag +BugUrl: my_bugurl +Collections: my_collections + +%description +Package for testing GBP. + +%prep + +%build + +%install |