From 14b727cc717d04fefba1cc31b6f29b549ced986f Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 6 Apr 2021 18:34:08 -0700 Subject: [PATCH] add rpm_qi tests --- tests/fixtures/centos-7.7/rpm-qi-package.json | 1 + tests/fixtures/centos-7.7/rpm-qi-package.out | 26 +++++++++++ tests/test_rpm_qai.py | 46 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 tests/fixtures/centos-7.7/rpm-qi-package.json create mode 100644 tests/fixtures/centos-7.7/rpm-qi-package.out create mode 100644 tests/test_rpm_qai.py diff --git a/tests/fixtures/centos-7.7/rpm-qi-package.json b/tests/fixtures/centos-7.7/rpm-qi-package.json new file mode 100644 index 00000000..5373595d --- /dev/null +++ b/tests/fixtures/centos-7.7/rpm-qi-package.json @@ -0,0 +1 @@ +[{"name":"make","epoch":1,"version":"3.82","release":"24.el7","architecture":"x86_64","install_date":"Wed 16 Oct 2019 09:21:42 AM PDT","group":"Development/Tools","size":1160660,"license":"GPLv2+","signature":"RSA/SHA256, Thu 22 Aug 2019 02:34:59 PM PDT, Key ID 24c6a8a7f4a80eb5","source_rpm":"make-3.82-24.el7.src.rpm","build_date":"Thu 08 Aug 2019 05:47:25 PM PDT","build_host":"x86-01.bsys.centos.org","relocations":"(not relocatable)","packager":"CentOS BuildSystem ","vendor":"CentOS","url":"http://www.gnu.org/software/make/","summary":"A GNU tool which simplifies the build process for users","description":"A GNU tool for controlling the generation of executables and other non-source files of a program from the program's source files. Make allows users to build and install packages without any significant knowledge about the details of the build process. The details about how the program should be built are provided for make in the program's makefile.","build_epoch":1565311645,"build_epoch_utc":null}] diff --git a/tests/fixtures/centos-7.7/rpm-qi-package.out b/tests/fixtures/centos-7.7/rpm-qi-package.out new file mode 100644 index 00000000..a2b5c1b3 --- /dev/null +++ b/tests/fixtures/centos-7.7/rpm-qi-package.out @@ -0,0 +1,26 @@ +Name : make +Epoch : 1 +Version : 3.82 +Release : 24.el7 +Architecture: x86_64 +Install Date: Wed 16 Oct 2019 09:21:42 AM PDT +Group : Development/Tools +Size : 1160660 +License : GPLv2+ +Signature : RSA/SHA256, Thu 22 Aug 2019 02:34:59 PM PDT, Key ID 24c6a8a7f4a80eb5 +Source RPM : make-3.82-24.el7.src.rpm +Build Date : Thu 08 Aug 2019 05:47:25 PM PDT +Build Host : x86-01.bsys.centos.org +Relocations : (not relocatable) +Packager : CentOS BuildSystem +Vendor : CentOS +URL : http://www.gnu.org/software/make/ +Summary : A GNU tool which simplifies the build process for users +Description : +A GNU tool for controlling the generation of executables and other +non-source files of a program from the program's source files. Make +allows users to build and install packages without any significant +knowledge about the details of the build process. The details about +how the program should be built are provided for make in the program's +makefile. + diff --git a/tests/test_rpm_qai.py b/tests/test_rpm_qai.py new file mode 100644 index 00000000..799ca186 --- /dev/null +++ b/tests/test_rpm_qai.py @@ -0,0 +1,46 @@ +import os +import unittest +import json +import jc.parsers.rpm_qi + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + + def setUp(self): + # input + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rpm-qai.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_rpm_qai = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rpm-qi-package.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_rpm_qi_package = f.read() + + # output + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rpm-qai.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_rpm_qai_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rpm-qi-package.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_rpm_qi_package_json = json.loads(f.read()) + + def test_rpm_qi_nodata(self): + """ + Test 'rpm -qi' with no data + """ + self.assertEqual(jc.parsers.rpm_qi.parse('', quiet=True), []) + + def test_rpm_qai_centos_7_7(self): + """ + Test 'rpm -qai' on Centos 7.7 + """ + self.assertEqual(jc.parsers.rpm_qi.parse(self.centos_7_7_rpm_qai, quiet=True), self.centos_7_7_rpm_qai_json) + + def test_rpm_qi_package_centos_7_7(self): + """ + Test 'rpm -qi make' on Centos 7.7 + """ + self.assertEqual(jc.parsers.rpm_qi.parse(self.centos_7_7_rpm_qi_package, quiet=True), self.centos_7_7_rpm_qi_package_json) + + +if __name__ == '__main__': + unittest.main()