]>
git.ipfire.org Git - pakfire.git/blob - tests/python/archive.py
10 class ArchiveTest(tests
.TestCase
):
12 This tests the Package class
15 self
.pakfire
= self
.setup_pakfire()
19 Test if we can open an archive
21 path
= self
.path("beep-1.3-2.ip3.x86_64.pfm")
24 archive
= self
.pakfire
.open(path
)
27 self
.assertEqual(archive
.path
, path
)
29 # The format should be 6
30 self
.assertEqual(archive
.format
, 6)
32 def test_filelist(self
):
34 Test parsing the filelist that is stored in the archive
36 path
= self
.path("beep-1.3-2.ip3.x86_64.pfm")
39 archive
= self
.pakfire
.open(path
)
41 # Check that we read the entire list of 7 files
42 self
.assertEqual(len(archive
.filelist
), 7)
44 # Check that we got files
45 for file in archive
.filelist
:
46 self
.assertIsInstance(file, pakfire
.File
)
48 # Check attributes of a few files
49 for file in archive
.filelist
:
50 # Check attributes of /usr/bin/beep
51 if file.path
== "/usr/bin/beep":
52 self
.assertEqual(file.type, stat
.S_IFREG
)
55 self
.assertEqual(file.size
, 17192)
58 self
.assertEqual(file.mode
, 0o100755)
61 self
.assertEqual(file.uname
, "root")
62 self
.assertEqual(file.gname
, "root")
64 # Creation/Modification Time
65 self
.assertEqual(file.ctime
, datetime
.datetime(2023, 2, 28, 18, 23, 48))
66 self
.assertEqual(file.mtime
, datetime
.datetime(2023, 2, 28, 18, 23, 48))
68 # This file has no capabilities
69 self
.assertIsNone(file.capabilities
)
71 # This file has no mimetype
72 self
.assertIsNone(file.mimetype
)
76 Test whether we can read a file from the archive
78 # XXX needs tests for reading symlinks
80 path
= self
.path("beep-1.3-2.ip3.x86_64.pfm")
83 archive
= self
.pakfire
.open(path
)
85 # Try opening /usr/bin/beep
86 f
= archive
.read("/usr/bin/beep")
88 # Check if we got the correct type
89 self
.assertIsInstance(f
, pakfire
.ArchiveFile
)
91 # Read the entire payload
95 self
.assertIsInstance(payload
, bytes
)
97 # Make sure we read the entire file
98 self
.assertEqual(len(payload
), 17192)
100 # Check that the payload starts like an ELF file
101 self
.assertEqual(payload
[:4], b
"\x7fELF")
103 # Try to read more after we have read everything
104 self
.assertEqual(b
"", f
.read())
106 # Try reading a file which does not exist
107 with self
.assertRaises(FileNotFoundError
):
108 archive
.read("/usr/bin/does-not-exist")
110 # Try reading a directory
111 with self
.assertRaises(FileNotFoundError
):
112 archive
.read("/usr/bin")
114 def test_extract(self
):
116 Tests extracting an archive
118 path
= self
.path("beep-1.3-2.ip3.x86_64.pfm")
121 archive
= self
.pakfire
.open(path
)
123 with self
.tempdir() as t
:
125 archive
.extract(path
=t
)
127 self
.assertTrue(os
.path
.exists("%s/usr" % t
))
128 self
.assertTrue(os
.path
.exists("%s/usr/bin" % t
))
129 self
.assertTrue(os
.path
.exists("%s/usr/bin/beep" % t
))
130 self
.assertTrue(os
.path
.exists("%s/usr/share" % t
))
131 self
.assertTrue(os
.path
.exists("%s/usr/share/man" % t
))
132 self
.assertTrue(os
.path
.exists("%s/usr/share/man/man1" % t
))
133 self
.assertTrue(os
.path
.exists("%s/usr/share/man/man1/beep.1.xz" % t
))
135 # XXX how can we check that there isn't anything else?
137 def test_package(self
):
139 Tests reading package metadata
141 path
= self
.path("beep-1.3-2.ip3.x86_64.pfm")
144 archive
= self
.pakfire
.open(path
)
146 # Fetch the package metadata
147 package
= archive
.get_package()
149 self
.assertIsInstance(package
, pakfire
.Package
)
151 # The rest will be tested in packages.py
154 if __name__
== "__main__":