Handle IO error on document save (#961)

* Add try/except to document replace call
* Try the os.replace command 5 times
* Just use else condition on for loop instead
* Make the exceptions explicitly OSError
* Revert the os.replace loop, as this is not the issue
This commit is contained in:
Veronica Berglyd Olsen
2022-01-19 19:13:08 +01:00
committed by GitHub
parent 8b603d15a5
commit ec07cebb51
3 changed files with 18 additions and 2 deletions
+12
View File
@@ -112,6 +112,18 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, nwMinimal):
assert theDoc.writeDocument(theText) is False
assert theDoc.getError() == "OSError: Mock OSError"
theDoc._docError = ""
assert theDoc.getError() == ""
# Cause os.replace() to fail while saving
with monkeypatch.context() as mp:
mp.setattr("os.replace", causeOSError)
assert theDoc.writeDocument(theText) is False
assert theDoc.getError() == "OSError: Mock OSError"
theDoc._docError = ""
assert theDoc.getError() == ""
# Saving with no handle
theDoc._docHandle = None
assert theDoc.writeDocument(theText) is False