From d9cccc87523a32fefa136e9288fcb9925e5b381c Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 17 Dec 2020 18:52:56 +0100 Subject: [PATCH] The Writing Stats tool should not pop an error message if there is no satistics log --- nw/gui/writingstats.py | 6 +++++- tests/test_gui_writingstats.py | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/nw/gui/writingstats.py b/nw/gui/writingstats.py index 3b5bc5c5..18abe3ff 100644 --- a/nw/gui/writingstats.py +++ b/nw/gui/writingstats.py @@ -403,8 +403,12 @@ class GuiWritingStats(QDialog): ttNotes = 0 ttTime = 0 + logFile = os.path.join(self.theProject.projMeta, nwFiles.SESS_STATS) + if not os.path.isfile(logFile): + logger.info("This project has no writing stats logfile") + return False + try: - logFile = os.path.join(self.theProject.projMeta, nwFiles.SESS_STATS) with open(logFile, mode="r", encoding="utf8") as inFile: for inLine in inFile: if inLine.startswith("#"): diff --git a/tests/test_gui_writingstats.py b/tests/test_gui_writingstats.py index 62f8af9f..038b3dcf 100644 --- a/tests/test_gui_writingstats.py +++ b/tests/test_gui_writingstats.py @@ -203,6 +203,7 @@ def testGuiWritingStats_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj): # IOError # ======= monkeypatch.setattr("builtins.open", causeOSError) + assert not sessLog._loadLogFile() assert not sessLog._saveData(sessLog.FMT_CSV) # qtbot.stopForInteraction()