def test_absent(self): ''' Test to verify that the specified python is not installed with pyenv. ''' name = 'python-2.7.6' ret = {'name': name, 'changes': {}, 'result': None, 'comment': ''} with patch.dict(pyenv.__opts__, {'test': True}): comt = ('python 2.7.6 is set to be uninstalled') ret.update({'comment': comt}) self.assertDictEqual(pyenv.absent(name), ret) with patch.dict(pyenv.__opts__, {'test': False}): mock_f = MagicMock(side_effect=[False, True]) mock_t = MagicMock(return_value=True) mock_str = MagicMock(return_value='2.7.6') mock_lst = MagicMock(return_value=['2.7.6']) with patch.dict(pyenv.__salt__, {'pyenv.is_installed': mock_f, 'pyenv.uninstall_python': mock_t, 'pyenv.default': mock_str, 'pyenv.versions': mock_lst}): comt = ('pyenv not installed, 2.7.6 not either') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(pyenv.absent(name), ret) comt = ('Successfully removed python') ret.update({'comment': comt, 'result': True, 'default': True, 'changes': {'2.7.6': 'Uninstalled'}}) self.assertDictEqual(pyenv.absent(name), ret)
def test_absent(): """ Test to verify that the specified python is not installed with pyenv. """ name = "python-2.7.6" ret = {"name": name, "changes": {}, "result": None, "comment": ""} with patch.dict(pyenv.__opts__, {"test": True}): comt = "python 2.7.6 is set to be uninstalled" ret.update({"comment": comt}) assert pyenv.absent(name) == ret with patch.dict(pyenv.__opts__, {"test": False}): mock_f = MagicMock(side_effect=[False, True]) mock_t = MagicMock(return_value=True) mock_str = MagicMock(return_value="2.7.6") mock_lst = MagicMock(return_value=["2.7.6"]) with patch.dict( pyenv.__salt__, { "pyenv.is_installed": mock_f, "pyenv.uninstall_python": mock_t, "pyenv.default": mock_str, "pyenv.versions": mock_lst, }, ): comt = "pyenv not installed, 2.7.6 not either" ret.update({"comment": comt, "result": True}) assert pyenv.absent(name) == ret comt = "Successfully removed python" ret.update({ "comment": comt, "result": True, "default": True, "changes": { "2.7.6": "Uninstalled" }, }) assert pyenv.absent(name) == ret