def test_list_pkgs_no_context(): """ Test if it list the packages currently installed in a dict """ cmdmock = MagicMock(return_value="A 1.0\nB 2.0") sortmock = MagicMock() stringifymock = MagicMock() mock_ret = {"A": ["1.0"], "B": ["2.0"]} with patch.dict( pacman.__salt__, { "cmd.run": cmdmock, "pkg_resource.add_pkg": lambda pkgs, name, version: pkgs.setdefault( name, [] ).append(version), "pkg_resource.sort_pkglist": sortmock, "pkg_resource.stringify": stringifymock, }, ), patch.object(pacman, "_list_pkgs_from_context") as list_pkgs_context_mock: assert pacman.list_pkgs() == mock_ret pkgs = pacman.list_pkgs(versions_as_list=True, use_context=False) list_pkgs_context_mock.assert_not_called() list_pkgs_context_mock.reset_mock() pkgs = pacman.list_pkgs(versions_as_list=True, use_context=False) list_pkgs_context_mock.assert_not_called() list_pkgs_context_mock.reset_mock()
def test_list_pkgs_as_list(self): """ Test if it lists the packages currently installed in a dict """ cmdmock = MagicMock(return_value="A 1.0\nB 2.0") sortmock = MagicMock() stringifymock = MagicMock() mock_ret = {"A": ["1.0"], "B": ["2.0"]} with patch.dict( pacman.__salt__, { "cmd.run": cmdmock, "pkg_resource.add_pkg": lambda pkgs, name, version: pkgs.setdefault(name, []).append( version), "pkg_resource.sort_pkglist": sortmock, "pkg_resource.stringify": stringifymock, }, ): self.assertDictEqual(pacman.list_pkgs(True), mock_ret) sortmock.assert_called_with(mock_ret) self.assertTrue(stringifymock.call_count == 0)
def test_list_pkgs_as_list(self): ''' Test if it lists the packages currently installed in a dict ''' cmdmock = MagicMock(return_value='A 1.0\nB 2.0') sortmock = MagicMock() stringifymock = MagicMock() mock_ret = {'A': ['1.0'], 'B': ['2.0']} with patch.dict( pacman.__salt__, { 'cmd.run': cmdmock, 'pkg_resource.add_pkg': lambda pkgs, name, version: pkgs.setdefault(name, []). append(version), 'pkg_resource.sort_pkglist': sortmock, 'pkg_resource.stringify': stringifymock }): self.assertDictEqual(pacman.list_pkgs(True), mock_ret) sortmock.assert_called_with(mock_ret) self.assertTrue(stringifymock.call_count == 0)