slpkg/tests/test_utilities.py

65 lines
2.2 KiB
Python
Raw Normal View History

2022-06-21 21:00:20 +02:00
import unittest
2023-03-20 20:22:56 +01:00
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
2024-03-21 17:33:33 +01:00
from slpkg.load_data import LoadData
2022-06-21 21:00:20 +02:00
class TestUtilities(unittest.TestCase):
2024-05-21 21:01:26 +02:00
"""Test for utilities."""
2024-04-29 21:38:02 +02:00
def setUp(self) -> None:
2024-05-22 18:23:55 +02:00
"""Set the test."""
2022-06-21 21:00:20 +02:00
self.utils = Utilities()
2023-05-11 11:45:06 +02:00
self.repository: str = 'slack'
2024-03-21 17:33:33 +01:00
load = LoadData()
self.data: dict = load.load(self.repository)
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
2024-04-29 21:38:02 +02:00
def test_ins_installed(self) -> None:
2024-05-21 21:01:26 +02:00
"""Test fro installed."""
2023-04-03 10:54:11 +02:00
self.assertEqual(self.package, self.utils.is_package_installed('aaa_base'))
2024-04-29 21:38:02 +02:00
def test_split_name(self) -> None:
2024-05-21 21:01:26 +02:00
"""Test for name split."""
2023-05-11 11:41:38 +02:00
self.assertEqual('aaa_base', self.utils.split_package(self.package)['name'])
2024-04-29 21:38:02 +02:00
def test_split_version(self) -> None:
2024-05-21 21:01:26 +02:00
"""Test for version split."""
2023-05-11 11:41:38 +02:00
self.assertEqual('15.0', self.utils.split_package(self.package)['version'])
2024-04-29 21:38:02 +02:00
def test_split_arch(self) -> None:
2024-05-21 21:01:26 +02:00
"""Test for arch split."""
2023-05-11 11:41:38 +02:00
self.assertEqual('x86_64', self.utils.split_package(self.package)['arch'])
2024-04-29 21:38:02 +02:00
def test_split_build(self) -> None:
2024-05-21 21:01:26 +02:00
"""Test for build split."""
2023-05-11 11:41:38 +02:00
self.assertEqual('4', self.utils.split_package(self.package)['build'])
2024-04-29 21:38:02 +02:00
def test_is_installed(self) -> None:
2024-05-21 21:01:26 +02:00
"""Test for is installed."""
2023-04-03 10:54:11 +02:00
self.assertEqual(self.package, self.utils.is_package_installed('aaa_base'))
2024-04-29 21:38:02 +02:00
def test_all_installed(self) -> None:
2024-05-21 21:01:26 +02:00
"""Test for all installed."""
2024-03-21 17:33:33 +01:00
self.assertIn(self.package, self.utils.all_installed().values())
2023-04-03 10:54:11 +02:00
2024-04-29 21:38:02 +02:00
def test_is_option(self) -> None:
2024-05-21 21:01:26 +02:00
"""Test for is option."""
2024-04-29 21:38:02 +02:00
is_parallel: bool = True
self.assertTrue(is_parallel, self.utils.is_option(('-P', '--parallel'),
['-k', '-p', '-P', '--parallel', '--repository']))
2023-04-03 10:54:11 +02:00
2024-04-29 21:38:02 +02:00
def test_get_file_size(self) -> None:
2024-05-21 21:01:26 +02:00
"""Test for file size."""
2024-03-21 17:33:33 +01:00
self.assertEqual(1249, self.utils.count_file_size('aaa_base'))
2023-04-03 10:54:11 +02:00
2024-04-29 21:38:02 +02:00
def test_apply_package_pattern(self) -> None:
2024-05-21 21:01:26 +02:00
"""Test for apply pattern."""
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()