From 73b413c7310e7b6a511ec0d682cd058e16fca185 Mon Sep 17 00:00:00 2001
From: Dan Callaghan <dcallagh@redhat.com>
Date: Sep 26 2016 05:59:28 +0000
Subject: [PATCH 1/2] tests: skip tests for weak deps if RPM is too old to support it


---

diff --git a/rpmfluff.py b/rpmfluff.py
index c23529b..10fab1f 100644
--- a/rpmfluff.py
+++ b/rpmfluff.py
@@ -480,6 +480,9 @@ def can_compile_m32():
     # necessary bits are installed (they are often not).
     return os.path.exists('/usr/include/gnu/stubs-32.h') and os.path.exists('/lib/libgcc_s.so.1')
 
+def can_use_rpm_weak_deps():
+    return int(rpm.__version_info__[0]) >= 4 and int(rpm.__version_info__[1]) >= 12
+
 class Trigger:
     def __init__(self, event, triggerConds, script, program=None):
         """For documentation on RPM triggers, see
@@ -1361,6 +1364,7 @@ class TestSimpleRpmBuild(unittest.TestCase):
 
             self.assert_conflicts(rpmFile, 'test-conflicts')
 
+    @unittest.skipIf(not can_use_rpm_weak_deps(), 'RPM weak deps are not supported')
     def test_add_recommends(self):
         self.rpmbuild.add_recommends('test-recommendation')
         self.rpmbuild.make()
@@ -1371,6 +1375,7 @@ class TestSimpleRpmBuild(unittest.TestCase):
 
             self.assert_recommends(rpmFile, 'test-recommendation')
 
+    @unittest.skipIf(not can_use_rpm_weak_deps(), 'RPM weak deps are not supported')
     def test_add_suggests(self):
         self.rpmbuild.add_suggests('test-suggestion')
         self.rpmbuild.make()
@@ -1381,6 +1386,7 @@ class TestSimpleRpmBuild(unittest.TestCase):
 
             self.assert_suggests(rpmFile, 'test-suggestion')
 
+    @unittest.skipIf(not can_use_rpm_weak_deps(), 'RPM weak deps are not supported')
     def test_add_supplements(self):
         self.rpmbuild.add_supplements('test-supplement')
         self.rpmbuild.make()
@@ -1391,6 +1397,7 @@ class TestSimpleRpmBuild(unittest.TestCase):
 
             self.assert_supplements(rpmFile, 'test-supplement')
 
+    @unittest.skipIf(not can_use_rpm_weak_deps(), 'RPM weak deps are not supported')
     def test_add_enhances(self):
         self.rpmbuild.add_enhances('test-enhancement')
         self.rpmbuild.make()

From 2aab0345f813eeb96d408d420c4677106a7540f2 Mon Sep 17 00:00:00 2001
From: Dan Callaghan <dcallagh@redhat.com>
Date: Sep 26 2016 05:59:30 +0000
Subject: [PATCH 2/2] tests: use rpm.fi instead of rpm.files


The older rpm.fi API is uglier and more painful to use than rpm.files,
but it exists on older rpm versions (such as rpm 4.11 on RHEL7). Whereas
rpm.files was only added in rpm 4.12+.

---

diff --git a/rpmfluff.py b/rpmfluff.py
index 10fab1f..c0958d9 100644
--- a/rpmfluff.py
+++ b/rpmfluff.py
@@ -1718,9 +1718,15 @@ class TestSimpleRpmBuild(unittest.TestCase):
         self.rpmbuild.add_simple_compilation(installPath='/usr/bin/program')
         self.rpmbuild.make()
         hdr = self.rpmbuild.get_built_rpm_header('i386')
-        self.assertEqual(1, rpm.files(hdr)['/usr/bin/program'].color)
+        fi = hdr.fiFromHeader()
+        fi.next()
+        self.assertEqual('/usr/bin/program', fi.FN())
+        self.assertEqual(1, fi.FColor())
         hdr = self.rpmbuild.get_built_rpm_header('x86_64')
-        self.assertEqual(2, rpm.files(hdr)['/usr/bin/program'].color)
+        fi = hdr.fiFromHeader()
+        fi.next()
+        self.assertEqual('/usr/bin/program', fi.FN())
+        self.assertEqual(2, fi.FColor())
 
     def test_multilib_conflict(self):
         """Ensure that the hooks to create a multilib conflict work as expected"""
@@ -1777,10 +1783,12 @@ class TestSimpleRpmBuild(unittest.TestCase):
                 owner='apache', group='apache')
         self.rpmbuild.make()
         hdr = self.rpmbuild.get_built_rpm_header(expectedArch)
-        files = rpm.files(hdr)
-        self.assertEqual('/var/www/html/index.html', files[0].name)
-        self.assertEqual('apache', files[0].user)
-        self.assertEqual('apache', files[0].group)
+        files = list(hdr.fiFromHeader())
+        self.assertEqual(1, len(files))
+        (filename, size, mode, mtime, flags, rdev, inode, FNlink, Fstate, vflags, user, group, md5sum) = files[0]
+        self.assertEqual('/var/www/html/index.html', filename)
+        self.assertEqual('apache', user)
+        self.assertEqual('apache', group)
 
     def test_specfile_encoding_utf8(self):
         self.rpmbuild.section_changelog = u"* Fri Mar 30 2001 Trond Eivind Glomsr\u00F8d <teg@redhat.com>\nDo something"

