Add character counts to session log

This commit is contained in:
Veronica Berglyd Olsen
2025-04-29 23:31:25 +02:00
parent 67d0b486e9
commit 53e60c7b59
3 changed files with 43 additions and 21 deletions
+8 -6
View File
@@ -43,8 +43,8 @@ def testCoreSessions_Main(monkeypatch, mockGUI, fncPath):
assert isinstance(logFile, Path)
# Set some mock word counts
project.data.setInitCounts(50, 60)
project.data.setCurrCounts(160, 150)
project.data.setInitCounts(50, 60, 500, 600)
project.data.setCurrCounts(160, 150, 1600, 1500)
# The project init should already have created the session
sessLog = project.session
@@ -71,17 +71,19 @@ def testCoreSessions_Main(monkeypatch, mockGUI, fncPath):
assert records[1]["type"] == "record"
assert records[1]["novel"] == 160
assert records[1]["notes"] == 150
assert records[1]["cnovel"] == 1600
assert records[1]["cnotes"] == 1500
assert records[1]["idle"] == 1 # Should be rounded to full seconds
# Adding another record without changing word count should do nothing
project.data.setInitCounts(160, 150)
project.data.setCurrCounts(160, 150)
project.data.setInitCounts(160, 150, 1600, 1500)
project.data.setCurrCounts(160, 150, 1600, 1500)
assert sessLog.appendSession(1.6) is False
assert len(list(sessLog.iterRecords())) == 2
# But adding when count has changed should
project.data.setInitCounts(160, 150)
project.data.setCurrCounts(270, 240)
project.data.setInitCounts(160, 150, 1600, 1500)
project.data.setCurrCounts(270, 240, 2700, 2400)
sessLog._start -= 350.0 # Backdate the session start to allow logging
assert sessLog.appendSession(1.6) is True
records = list(sessLog.iterRecords())
+6 -2
View File
@@ -435,8 +435,8 @@ def testCoreStorage_OldFormatConvert(monkeypatch, mockGUI, fncPath):
sessLogOld.write_text((
"# Offset 150\n"
"# Start Time End Time Novel Notes Idle\n"
"2021-02-02 02:02:02 2021-02-02 03:03:03 200 200 10\n"
"2021-03-03 03:03:03 2021-03-03 04:04:04 300 300 20\n"
"2021-02-02 02:02:02 2021-02-02 03:03:03 200 200 10\n"
"2021-03-03 03:03:03 2021-03-03 04:04:04 300 300 20\n"
), encoding="utf-8")
assert sessLogOld.exists() is True
@@ -496,6 +496,8 @@ def testCoreStorage_OldFormatConvert(monkeypatch, mockGUI, fncPath):
"end": "2021-02-02 03:03:03",
"novel": 200,
"notes": 200,
"cnovel": 0,
"cnotes": 0,
"idle": 10,
}
assert data[2] == {
@@ -504,6 +506,8 @@ def testCoreStorage_OldFormatConvert(monkeypatch, mockGUI, fncPath):
"end": "2021-03-03 04:04:04",
"novel": 300,
"notes": 300,
"cnovel": 0,
"cnotes": 0,
"idle": 20,
}