def test_add(self): ''' Test to add the directory to the SYSTEM path ''' mock_get = MagicMock(return_value=['c:\\salt']) with patch.object(win_path, 'get_path', mock_get): mock_set = MagicMock(return_value=True) with patch.dict(win_path.__salt__, {'reg.set_value': mock_set}): mock_rehash = MagicMock(side_effect=[True, False]) with patch.object(win_path, 'rehash', mock_rehash): self.assertTrue(win_path.add("c:\\salt", 1)) self.assertFalse(win_path.add("c:\\salt", 1))
def test_add(self): """ Test to add the directory to the SYSTEM path """ mock = MagicMock(return_value=["c:\\salt"]) with patch.object(win_path, "get_path", mock): mock = MagicMock(return_value=True) with patch.dict(win_path.__salt__, {"reg.set_key": mock}): mock = MagicMock(side_effect=[True, False]) with patch.object(win_path, "rehash", mock): self.assertTrue(win_path.add("c:\\salt", 1)) self.assertFalse(win_path.add("c:\\salt", 1))
def _run(name, index=None, retval=True, path=None): if path is None: path = orig_path env = _env(path) mock_get = MagicMock(return_value=list(path)) mock_set = MagicMock(return_value=retval) with patch.object(win_path, 'PATHSEP', self.pathsep), \ patch.object(win_path, 'get_path', mock_get), \ patch.object(os, 'environ', env), \ patch.dict(win_path.__utils__, {'reg.set_value': mock_set}), \ patch.object(win_path, 'rehash', MagicMock(return_value=True)): return win_path.add(name, index), env, mock_set
def _run(name, index=None, retval=True, path=None): if path is None: path = orig_path env = _env(path) mock_get = MagicMock(return_value=list(path)) mock_set = MagicMock(return_value=retval) with patch.object(win_path, "PATHSEP", self.pathsep), patch.object( win_path, "get_path", mock_get), patch.object(os, "environ", env), patch.dict( win_path.__salt__, {"reg.set_value": mock_set}), patch.object( win_path, "rehash", MagicMock(return_value=True)): return win_path.add(name, index), env, mock_set
def _run(name, index=None, retval=True, path=None): if path is None: path = orig_path env = _env(path) # Mock getters and setters mock_get = MagicMock(return_value=list(path)) mock_set = MagicMock(return_value=retval) # Mock individual calls that would occur during normal usage patch_sep = patch.object(win_path, "PATHSEP", pathsep) patch_path = patch.object(win_path, "get_path", mock_get) patch_env = patch.object(os, "environ", env) patch_dict = patch.dict(win_path.__utils__, {"reg.set_value": mock_set}) patch_rehash = patch.object(win_path, "rehash", MagicMock(return_value=True)) with patch_sep, patch_path, patch_env, patch_dict, patch_rehash: return win_path.add(name, index), env, mock_set