Move session log handling to a separate class, and use jsonl format
This commit is contained in:
@@ -487,7 +487,7 @@ def testCoreProject_Methods(monkeypatch, mockGUI, fncPath, mockRnd):
|
||||
|
||||
# Edit Time
|
||||
theProject.data.setEditTime(1234)
|
||||
theProject._projOpened = 1600000000
|
||||
theProject._session._start = 1600000000
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("novelwriter.core.project.time", lambda: 1600005600)
|
||||
assert theProject.getCurrentEditTime() == 6834
|
||||
@@ -585,32 +585,32 @@ def testCoreProject_Methods(monkeypatch, mockGUI, fncPath, mockRnd):
|
||||
# No path for writing
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("novelwriter.core.storage.NWStorage.getMetaFile", lambda *a: None)
|
||||
assert theProject._appendSessionStats(idleTime=0) is False
|
||||
assert theProject.session.appendSession(idleTime=0) is False
|
||||
|
||||
# Block open
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("builtins.open", causeOSError)
|
||||
assert theProject._appendSessionStats(idleTime=0) is False
|
||||
assert theProject.session.appendSession(idleTime=0) is False
|
||||
|
||||
# Session too short
|
||||
theProject._projOpened = time()
|
||||
theProject._session._start = time()
|
||||
theProject.data.setInitCounts(50, 50)
|
||||
theProject.data.setCurrCounts(50, 50)
|
||||
assert theProject._appendSessionStats(idleTime=0) is False
|
||||
assert theProject.session.appendSession(idleTime=0) is False
|
||||
|
||||
# Write entry
|
||||
statsFile = theProject.storage.getMetaFile(nwFiles.SESS_STATS)
|
||||
statsFile = theProject.storage.getMetaFile(nwFiles.SESS_FILE)
|
||||
assert isinstance(statsFile, Path)
|
||||
if statsFile.exists():
|
||||
statsFile.unlink()
|
||||
|
||||
theProject._projOpened = 1600002000
|
||||
theProject._session._start = 1600002000
|
||||
theProject.data._initCounts = [50, 50]
|
||||
theProject.data._currCounts = [200, 100]
|
||||
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("novelwriter.core.project.time", lambda: 1600005600)
|
||||
assert theProject._appendSessionStats(idleTime=99)
|
||||
assert theProject.session.appendSession(idleTime=99)
|
||||
|
||||
assert statsFile.read_text(encoding="utf-8") == (
|
||||
"# Offset 100\n"
|
||||
|
||||
+1
-2
@@ -19,7 +19,6 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import time
|
||||
import shutil
|
||||
|
||||
from pathlib import Path
|
||||
@@ -201,7 +200,7 @@ def buildTestProject(theObject, projPath):
|
||||
aDoc.writeDocument("### %s\n\n" % theProject.tr("New Scene"))
|
||||
theProject.index.reIndexHandle(xHandle[8])
|
||||
|
||||
theProject._projOpened = time.time()
|
||||
theProject.session.startSession()
|
||||
theProject.setProjectChanged(True)
|
||||
theProject.saveProject(autoSave=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user