def test_mkdir_open_handle_oserror_for_file_exist(self): mock_os = self.patch("passpie.utils.os") self.patch("passpie.utils.open", self.mock_open(), create=True) path = "path/to/foo.pass" mock_os.makedirs.side_effect = OSError(17, "File Exists") with mkdir_open(path, "w") as fd: self.assertIsNotNone(fd) mock_os.makedirs.side_effect = OSError(2, "File Not Found") with self.assertRaises(OSError): with mkdir_open(path, "w") as fd: pass
def test_mkdir_open_handle_oserror_for_file_exist(mocker): mock_os = mocker.patch("passpie.utils.os") mocker.patch("passpie.utils.open", mock_open(), create=True) path = "path/to/foo.pass" mock_os.makedirs.side_effect = OSError(17, "File Exists") with mkdir_open(path, "w") as fd: assert fd is not None mock_os.makedirs.side_effect = OSError(2, "File Not Found") with pytest.raises(OSError): with mkdir_open(path, "w") as fd: pass
def test_mkdir_open_makedirs_on_path_dirname(self): mock_os = self.patch("passpie.utils.os") self.patch("passpie.utils.open", self.mock_open(), create=True) path = "path/to/foo.pass" with mkdir_open(path, "w"): dirname = mock_os.path.dirname(path) mock_os.makedirs.assert_called_once_with(dirname)
def test_mkdir_open_makedirs_on_path_dirname(mocker): mock_os = mocker.patch("passpie.utils.os") mocker.patch("passpie.utils.open", mock_open(), create=True) path = "path/to/foo.pass" with mkdir_open(path, "w"): dirname = mock_os.path.dirname(path) mock_os.makedirs.assert_called_once_with(dirname)