summaryrefslogtreecommitdiffstats
path: root/tests/resetreferencelogs.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-11-21 15:00:40 +0100
committerDaniel Baumann <daniel@debian.org>2024-11-21 15:00:40 +0100
commit012d9cb5faed22cb9b4151569d30cc08563b02d1 (patch)
treefd901b9c231aeb8afa713851f23369fa4a1af2b3 /tests/resetreferencelogs.py
parentInitial commit. (diff)
downloadpysilfont-012d9cb5faed22cb9b4151569d30cc08563b02d1.tar.xz
pysilfont-012d9cb5faed22cb9b4151569d30cc08563b02d1.zip
Adding upstream version 1.8.0.upstream/1.8.0upstream
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'tests/resetreferencelogs.py')
-rw-r--r--tests/resetreferencelogs.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/resetreferencelogs.py b/tests/resetreferencelogs.py
new file mode 100644
index 0000000..03fc317
--- /dev/null
+++ b/tests/resetreferencelogs.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+''' Reset the reference log files following changes to tests
+Works on one test group at a time.
+Copies the results logs to reference .lg files, replacing making file paths generic.
+setupTestdata.py then generates correct log files from .lg files
+'''
+__url__ = 'https://github.com/silnrsi/pysilfont'
+__copyright__ = 'Copyright (c) 2018 SIL International (https://www.sil.org)'
+__license__ = 'Released under the MIT License (https://opensource.org/licenses/MIT)'
+__author__ = 'David Raymond'
+
+import os, sys, shutil, glob, io
+from silfont.util import text_diff
+
+# Check being run in pysilfont root directory
+cwd = os.getcwd()
+if os.path.split(cwd)[1] != "pysilfont":
+ print("resetReferenceLogs must be run in pysilfont root directory")
+ sys.exit(1)
+
+if len(sys.argv) != 2:
+ print("Usage: resetReferenceLogs testgroupname")
+ print("*** Should only be run when reference logs in the local/testresults/<testgorupname> directory"
+ " are known to be good ***")
+ sys.exit()
+
+testgroup = sys.argv[1]
+
+if testgroup not in ("ufo", "fontparts"):
+ print("Invalid test group")
+ sys.exit()
+
+logsdir = "local/testresults/" + testgroup + "/"
+refdir = "tests/reference/" + testgroup + "/"
+
+if not os.path.isdir(logsdir):
+ print(logsdir + " does not exist")
+ sys.exit()
+
+
+# Read the new log files and create new .lg files from them
+logs = glob.iglob(logsdir + "*.log")
+updates = False
+for log in logs:
+ inlog = io.open(log, mode="r", encoding="utf-8")
+ testn = os.path.splitext(os.path.split(log)[1])[0]
+ outtmp = refdir + testn + ".tmp"
+ outlg = refdir + testn + ".lg"
+ outlog = io.open(outtmp, mode="w", encoding="utf-8")
+ for line in inlog:
+ line = line.replace(cwd, "@cwd@") # Replace machine-specific cwd with placeholder
+ line = line.replace("\\","/") # Replace Windows \ with /
+ outlog.write(line)
+ outlog.close()
+ # Only update the .lg if it has changed
+ diff = text_diff(outtmp, outlg, ignore_chars=20)
+ if diff.returncode: # Either they are different or .lg file is missing
+ try:
+ os.remove(outlg)
+ except:
+ pass
+ os.rename(outtmp, outlg)
+ updates = True
+ print(outlg + " recreated")
+ else:
+ os.remove(outtmp)
+if updates: print("Run tests/setuptestdata.py to reset reference .log files") \ No newline at end of file