more tests

This commit is contained in:
Mike McLean 2017-04-19 15:42:09 -04:00
parent a4131e354c
commit 76dc071fe8
2 changed files with 24 additions and 6 deletions

View file

@ -879,10 +879,12 @@ def get_rpm_header(f, ts=None):
def get_header_field(hdr, name, src_arch=False):
"""Extract named field from an rpm header"""
if not RPM_SUPPORTS_OPTIONAL_DEPS and name in ('SUGGESTNAME', 'SUGGESTVERSION', 'SUGGESTFLAGS',
'ENHANCENAME', 'ENHANCEVERSION', 'ENHANCEFLAGS',
'SUPPLEMENTNAME', 'SUPPLEMENTVERSION', 'SUPPLEMENTFLAGS',
'RECOMMENDNAME', 'RECOMMENDVERSION', 'RECOMMENDFLAGS'):
opt_dep_hdrs = (
'SUGGESTNAME', 'SUGGESTVERSION', 'SUGGESTFLAGS',
'ENHANCENAME', 'ENHANCEVERSION', 'ENHANCEFLAGS',
'SUPPLEMENTNAME', 'SUPPLEMENTVERSION', 'SUPPLEMENTFLAGS',
'RECOMMENDNAME', 'RECOMMENDVERSION', 'RECOMMENDFLAGS')
if not RPM_SUPPORTS_OPTIONAL_DEPS and name.upper() in opt_dep_hdrs:
return []
if (src_arch and name.lower() == "arch"

View file

@ -2,6 +2,7 @@
"""Test the __init__.py module"""
import mock
import os
import rpm
import unittest
@ -149,7 +150,7 @@ class HeaderTestCase(unittest.TestCase):
data = koji.get_header_fields(srpm, ['arch'])
self.assertEqual(data['arch'], 'x86_64')
# eith src_arch, should return src
# with src_arch, should return src
data = koji.get_header_fields(srpm, ['arch'], src_arch=True)
self.assertEqual(data['arch'], 'src')
@ -163,12 +164,27 @@ class HeaderTestCase(unittest.TestCase):
data = koji.get_header_fields(srpm, ['arch'])
self.assertEqual(data['arch'], 'x86_64')
# eith src_arch, should return nosrc
# with src_arch, should return nosrc
for srpm in srpm1, srpm2:
data = koji.get_header_fields(srpm, ['arch'], src_arch=True)
self.assertEqual(data['arch'], 'nosrc')
@mock.patch('rpm.RPMTAG_NOSOURCE', new=None)
@mock.patch('rpm.RPMTAG_NOPATCH', new=None)
@mock.patch('koji.RPM_SUPPORTS_OPTIONAL_DEPS', new=False)
def test_get_header_field_workarounds(self):
srpm0 = os.path.join(self.rpmdir, 'test-src-1-1.fc24.src.rpm')
srpm1 = os.path.join(self.rpmdir, 'test-nosrc-1-1.fc24.nosrc.rpm')
srpm2 = os.path.join(self.rpmdir, 'test-nopatch-1-1.fc24.nosrc.rpm')
# should still work even with rpm constants set to None
self.assertEqual([0], koji.get_header_fields(srpm1, ['nosource'])['nosource'])
self.assertEqual([0], koji.get_header_fields(srpm2, ['nopatch'])['nopatch'])
# should return [] with optional dep support off
self.assertEqual([], koji.get_header_fields(srpm0, ['suggestname'])['suggestname'])
if __name__ == '__main__':
unittest.main()