[arch] fix: displaying already installed packages when suggesting optional dependencies

This commit is contained in:
Vinicius Moreira
2022-04-13 17:47:07 -03:00
parent 4c9ca22b43
commit 268b59bc3a
3 changed files with 93 additions and 23 deletions

View File

@@ -1,7 +1,9 @@
import os
import warnings
from unittest import TestCase
from unittest.mock import patch, Mock
from bauh import __app_name__
from bauh.gems.arch import pacman
FILE_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -26,3 +28,71 @@ class PacmanTest(TestCase):
self.assertIsNotNone(ignored)
self.assertEqual(0, len(ignored))
@patch(f'{__app_name__}.gems.arch.pacman.run_cmd', return_value="""
Name : package-test
Version : 3.4.4-1
Description : Test
Depends On : embree freetype2 libglvnd
Optional Deps : lib32-vulkan-icd-loader: Vulkan support [installed]
Required By : None
""")
def test_map_optional_deps__no_remote_and_not_installed__only_one_installed_with_description(self, run_cmd: Mock):
res = pacman.map_optional_deps(('package-test',), remote=False, not_installed=True)
run_cmd.assert_called_once_with('pacman -Qi package-test')
self.assertEqual({'package-test': {}}, res)
@patch(f'{__app_name__}.gems.arch.pacman.run_cmd', return_value="""
Name : package-test
Version : 3.4.4-1
Description : Test
Depends On : embree freetype2 libglvnd
Optional Deps : lib32-vulkan-icd-loader: Vulkan support
Required By : None
""")
def test_map_optional_deps__no_remote_and_not_installed__only_one_not_installed_with_description(self, run_cmd: Mock):
res = pacman.map_optional_deps(('package-test',), remote=False, not_installed=True)
run_cmd.assert_called_once_with('pacman -Qi package-test')
self.assertEqual({'package-test': {'lib32-vulkan-icd-loader': 'Vulkan support'}}, res)
@patch(f'{__app_name__}.gems.arch.pacman.run_cmd', return_value="""
Name : package-test
Version : 3.4.4-1
Description : Test
Depends On : embree freetype2 libglvnd
Optional Deps : pipewire-alsa
Required By : None
""")
def test_map_optional_deps__no_remote_and_not_installed__only_one_not_installed_no_description(self, run_cmd: Mock):
res = pacman.map_optional_deps(('package-test',), remote=False, not_installed=True)
run_cmd.assert_called_once_with('pacman -Qi package-test')
self.assertEqual({'package-test': {'pipewire-alsa': ''}}, res)
@patch(f'{__app_name__}.gems.arch.pacman.run_cmd', return_value="""
Name : package-test
Version : 3.4.4-1
Description : Test
Depends On : embree freetype2 libglvnd
Optional Deps : pipewire-alsa [installed]
Required By : None
""")
def test_map_optional_deps__no_remote_and_not_installed__only_one_installed_no_description(self, run_cmd: Mock):
res = pacman.map_optional_deps(('package-test',), remote=False, not_installed=True)
run_cmd.assert_called_once_with('pacman -Qi package-test')
self.assertEqual({'package-test': {}}, res)
@patch(f'{__app_name__}.gems.arch.pacman.run_cmd', return_value="""
Name : package-test
Version : 3.4.4-1
Description : Test
Depends On : embree freetype2 libglvnd libtheora
Optional Deps : pipewire-alsa
pipewire-pulse [installed]
pipewire
lib32-vulkan-icd-loader: Vulkan support [installed]
Required By : None
""")
def test_map_optional_deps__no_remote_and_not_installed__several(self, run_cmd: Mock):
res = pacman.map_optional_deps(('package-test',), remote=False, not_installed=True)
run_cmd.assert_called_once_with('pacman -Qi package-test')
self.assertEqual({'package-test': {'pipewire-alsa': '', 'pipewire': ''}}, res)