slpkg/tests/test_utilities.py

56 lines
1.9 KiB
Python
Raw Normal View History

2022-06-21 21:00:20 +02:00
import unittest
2023-03-20 20:22:56 +01:00
2023-04-06 18:42:12 +02:00
from pathlib import Path
2022-06-21 21:00:20 +02:00
from slpkg.configs import Configs
2023-03-20 20:22:56 +01:00
from slpkg.utilities import Utilities
2023-05-11 11:45:06 +02:00
from slpkg.binaries.queries import BinQueries
2022-06-21 21:00:20 +02:00
class TestUtilities(unittest.TestCase):
def setUp(self):
self.utils = Utilities()
2023-05-11 11:45:06 +02:00
self.repository: str = 'slack'
self.queries = BinQueries('slack')
self.data: dict = self.queries.repository_data()
2022-06-21 21:00:20 +02:00
self.build_path = Configs.build_path
2023-04-03 10:54:11 +02:00
self.package = 'aaa_base-15.0-x86_64-4_slack15.0'
2022-06-21 21:00:20 +02:00
def test_ins_installed(self):
2023-04-03 10:54:11 +02:00
self.assertEqual(self.package, self.utils.is_package_installed('aaa_base'))
def test_split_name(self):
2023-05-11 11:41:38 +02:00
self.assertEqual('aaa_base', self.utils.split_package(self.package)['name'])
def test_split_version(self):
2023-05-11 11:41:38 +02:00
self.assertEqual('15.0', self.utils.split_package(self.package)['version'])
def test_split_arch(self):
2023-05-11 11:41:38 +02:00
self.assertEqual('x86_64', self.utils.split_package(self.package)['arch'])
def test_split_build(self):
2023-05-11 11:41:38 +02:00
self.assertEqual('4', self.utils.split_package(self.package)['build'])
2023-04-03 10:54:11 +02:00
def test_is_installed(self):
self.assertEqual(self.package, self.utils.is_package_installed('aaa_base'))
def test_all_installed(self):
2023-04-14 11:29:55 +02:00
self.assertIn(self.package, self.utils.installed_packages.values())
2023-04-03 10:54:11 +02:00
def test_read_build_tag(self):
2023-05-13 16:51:44 +02:00
self.assertEqual('1', self.utils.read_slackbuild_build_tag('slpkg', 'system', 'sbo'))
2023-04-03 10:54:11 +02:00
def test_is_option(self):
2023-05-23 21:18:01 +02:00
self.assertTrue(True, self.utils.is_option(('-P', '--parallel'),
2023-05-13 16:51:44 +02:00
['-k', '-p', '-P', '--parallel', '--repository']))
2023-04-03 10:54:11 +02:00
def test_get_file_size(self):
2023-04-17 09:56:42 +02:00
self.assertEqual('2 MB', self.utils.get_file_size(Path('/var/log/packages/', self.package)))
2023-04-03 10:54:11 +02:00
def test_apply_package_pattern(self):
2023-04-09 19:38:17 +02:00
self.assertGreater(len(self.utils.apply_package_pattern(self.data, ['*'])), 1)
2022-06-21 21:00:20 +02:00
if __name__ == '__main__':
unittest.main()