def test_patch_dir(self, mock_which, mock_isdir): cmd_mock = MagicMock(return_value='test_retval') with patch.dict(filemod.__salt__, {'cmd.run_all': cmd_mock}): ret = filemod.patch('/path/to/dir', '/path/to/patch') cmd = ['/bin/patch', '--forward', '--reject-file=-', '-i', '/path/to/patch', '-d', '/path/to/dir', '--strip=0'] cmd_mock.assert_called_once_with(cmd, python_shell=False) self.assertEqual('test_retval', ret)
def test_patch_dry_run(self): with patch('os.path.isdir', return_value=False) as mock_isdir, \ patch('salt.utils.which', return_value='/bin/patch') as mock_which: cmd_mock = MagicMock(return_value='test_retval') with patch.dict(filemod.__salt__, {'cmd.run_all': cmd_mock}): ret = filemod.patch('/path/to/file', '/path/to/patch', dry_run=True) cmd = ['/bin/patch', '--dry-run', '--forward', '--reject-file=-', '-i', '/path/to/patch', '/path/to/file'] cmd_mock.assert_called_once_with(cmd, python_shell=False) self.assertEqual('test_retval', ret)
def test_patch(): with patch("os.path.isdir", return_value=False) as mock_isdir, patch( "salt.utils.path.which", return_value="/bin/patch" ) as mock_which: cmd_mock = MagicMock(return_value="test_retval") with patch.dict(filemod.__salt__, {"cmd.run_all": cmd_mock}): ret = filemod.patch("/path/to/file", "/path/to/patch") cmd = [ "/bin/patch", "--forward", "--reject-file=-", "-i", "/path/to/patch", "/path/to/file", ] cmd_mock.assert_called_once_with(cmd, python_shell=False) assert "test_retval" == ret