def test_list_pkgs_no_context(): """ Test for listing installed packages. """ def _add_data(data, key, value): data[key] = value pkg_info_out = [ "png-1.6.23", "vim-7.4.1467p1-gtk2", # vim--gtk2 "ruby-2.3.1p1", # ruby%2.3 ] run_stdout_mock = MagicMock(return_value="\n".join(pkg_info_out)) patches = { "cmd.run_stdout": run_stdout_mock, "pkg_resource.add_pkg": _add_data, "pkg_resource.sort_pkglist": MagicMock(), "pkg_resource.stringify": MagicMock(), } with patch.dict(openbsdpkg.__salt__, patches), patch.object( openbsdpkg, "_list_pkgs_from_context" ) as list_pkgs_context_mock: pkgs = openbsdpkg.list_pkgs(use_context=False) list_pkgs_context_mock.assert_not_called() list_pkgs_context_mock.reset_mock() pkgs = openbsdpkg.list_pkgs(use_context=False) list_pkgs_context_mock.assert_not_called() list_pkgs_context_mock.reset_mock()
def test_list_pkgs(): """ Test for listing installed packages. """ def _add_data(data, key, value): data[key] = value pkg_info_out = [ "png-1.6.23", "vim-7.4.1467p1-gtk2", # vim--gtk2 "ruby-2.3.1p1", # ruby%2.3 ] run_stdout_mock = MagicMock(return_value="\n".join(pkg_info_out)) patches = { "cmd.run_stdout": run_stdout_mock, "pkg_resource.add_pkg": _add_data, "pkg_resource.sort_pkglist": MagicMock(), "pkg_resource.stringify": MagicMock(), } with patch.dict(openbsdpkg.__salt__, patches): pkgs = openbsdpkg.list_pkgs() assert pkgs == { "png": "1.6.23", "vim--gtk2": "7.4.1467p1", "ruby": "2.3.1p1" } run_stdout_mock.assert_called_once_with("pkg_info -q -a", output_loglevel="trace")
def test_list_pkgs(self): ''' Test for listing installed packages. ''' def _add_data(data, key, value): data[key] = value pkg_info_out = [ 'png-1.6.23', 'vim-7.4.1467p1-gtk2', # vim--gtk2 'ruby-2.3.1p1' # ruby%2.3 ] run_stdout_mock = MagicMock(return_value='\n'.join(pkg_info_out)) patches = { 'cmd.run_stdout': run_stdout_mock, 'pkg_resource.add_pkg': _add_data, 'pkg_resource.sort_pkglist': MagicMock(), 'pkg_resource.stringify': MagicMock(), } with patch.dict(openbsdpkg.__salt__, patches): pkgs = openbsdpkg.list_pkgs() self.assertDictEqual(pkgs, { 'png': '1.6.23', 'vim--gtk2': '7.4.1467p1', 'ruby': '2.3.1p1' }) run_stdout_mock.assert_called_once_with('pkg_info -q -a', output_loglevel='trace')
def test_list_pkgs(self): ''' Test for listing installed packages. ''' def _add_data(data, key, value): data[key] = value pkg_info_out = [ 'png-1.6.23', 'vim-7.4.1467p1-gtk2', # vim--gtk2 'ruby-2.3.1p1' # ruby%2.3 ] run_stdout_mock = MagicMock(return_value='\n'.join(pkg_info_out)) patches = { 'cmd.run_stdout': run_stdout_mock, 'pkg_resource.add_pkg': _add_data, 'pkg_resource.sort_pkglist': MagicMock(), 'pkg_resource.stringify': MagicMock(), } with patch.dict(openbsdpkg.__salt__, patches): pkgs = openbsdpkg.list_pkgs() self.assertDictEqual(pkgs, { 'png': '1.6.23', 'vim--gtk2': '7.4.1467p1', 'ruby': '2.3.1p1'}) run_stdout_mock.assert_called_once_with('pkg_info -q -a', output_loglevel='trace')