]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Add a simple test to read metadata from Python
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 29 Aug 2023 16:43:33 +0000 (16:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 29 Aug 2023 16:43:33 +0000 (16:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
tests/python/package.py [new file with mode: 0755]

index 402557bdae47d167d450ba4061b037d8ba2420b8..0ca4fb3d41cfa4dfaa744c9ad9045a0ed08872e7 100644 (file)
@@ -905,6 +905,7 @@ TESTS_ENVIRONMENT = \
 dist_check_SCRIPTS = \
        tests/python/keys.py \
        tests/python/jail.py \
+       tests/python/package.py \
        tests/python/progressbar.py \
        tests/python/test.py
 
diff --git a/tests/python/package.py b/tests/python/package.py
new file mode 100755 (executable)
index 0000000..723a5fe
--- /dev/null
@@ -0,0 +1,94 @@
+#!/usr/bin/python3
+
+import os
+import pakfire
+import unittest
+
+class Test(unittest.TestCase):
+       """
+               This tests the Package class
+       """
+       def setUp(self):
+               path = os.environ.get("TEST_STUB_ROOT")
+               if not path:
+                       raise RuntimeError("TEST_STUB_ROOT is not defined")
+
+               self.pakfire = pakfire.Pakfire(path)
+
+       def test_open(self):
+               path = os.path.join(
+                       os.environ["TEST_DATA_DIR"],
+                       "beep-1.3-2.ip3.x86_64.pfm",
+               )
+
+               # Open the archive
+               a = self.pakfire.open(path)
+
+               # Fetch the package
+               p = a.get_package()
+
+               # Check metadata
+               self.assertEqual(p.name, "beep")
+               self.assertEqual(p.evr, "1.3-2.ipfire3")
+               self.assertEqual(p.arch, "x86_64")
+
+               self.assertEqual(p.summary, "Beep the PC speaker any number of ways.")
+               self.assertEqual(p.description,
+                       "Beep allows the user to control the PC speaker with precision, "
+                       "allowing different sounds to indicate different events. While "
+                       "it can be run quite happily on the commandline, it's intended "
+                       "place of residence is within shell/perl scripts, notifying the "
+                       "user when something interesting occurs. Of course, it has no "
+                       "notion of what's interesting, but it's real good at that "
+                       "notifying part.")
+               self.assertEqual(p.url, "http://www.johnath.com/beep/")
+               self.assertEqual(p.license, "GPLv2+")
+               self.assertEqual(p.vendor, "IPFire Project")
+               self.assertEqual(p.distribution, "ipfire3")
+               self.assertEqual(p.groups, "Applications/System")
+
+               self.assertEqual(p.uuid, "a20dddff-d8e8-4544-aaee-8bab618b0b3f")
+               self.assertIsNone(p.packager)
+
+               self.assertEqual(p.filename, "beep-1.3-2.ip3.x86_64.pfm")
+               self.assertEqual(p.downloadsize, 11271)
+               self.assertEqual(p.installsize, 40980)
+
+               self.assertEqual(p.buildhost, "michael.sof.ipfire.org")
+               self.assertEqual(p.buildtime, 1677608628)
+
+               # Dependencies
+               self.assertEqual(p.requires, [
+                       "pakfire(Digest-SHA3-512)",
+                       "pakfire(Digest-BLAKE2b512)",
+                       "/lib64/ld-linux-x86-64.so.2",
+                       "libc.so.6()(64bit)",
+                       "libc.so.6(GLIBC_2.2.5)(64bit)",
+                       "libc.so.6(GLIBC_2.3.4)(64bit)",
+                       "libc.so.6(GLIBC_2.34)(64bit)",
+                       "libc.so.6(GLIBC_2.4)(64bit)",
+                       "libc.so.6(GLIBC_2.7)(64bit)",
+                       "pakfire(Compress-Zstandard)",
+                       "pakfire(PackageFormat-6)",
+               ])
+               self.assertEqual(p.provides, ["beep = 1.3-2.ipfire3"])
+               self.assertEqual(p.obsoletes, [])
+               self.assertEqual(p.conflicts, [])
+               self.assertEqual(p.suggests, [])
+               self.assertEqual(p.recommends, [])
+
+               # Source
+               self.assertEqual(p.source_package, "beep-1.3-2.ipfire3.src")
+               self.assertEqual(p.source_name, "beep")
+               self.assertEqual(p.source_arch, "src")
+               self.assertEqual(p.source_evr, "1.3-2.ipfire3")
+
+               # Digest
+               algo, digest = p.digest
+
+               self.assertEqual(algo, "sha2-512")
+               self.assertEqual(digest, b"BP+\xb256\xc3\x12w\xf0l\xc2\xd7\x87j\xe3\xf0\x84\x85v\xc56B|\x8e\x99\x95\xf1 Z\xbf\xe7U\xa0C\xc8\xf1hklg{\x89\xa5\x98\x9e\nG\xdb!\ng\xbe\xa0\xcdt6\x04\x00\xeby\xd18\x91")
+
+
+if __name__ == "__main__":
+       unittest.main()