summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/fonts/amiri/tools/runtest.py
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/doc/fonts/amiri/tools/runtest.py')
-rwxr-xr-xMaster/texmf-dist/doc/fonts/amiri/tools/runtest.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/fonts/amiri/tools/runtest.py b/Master/texmf-dist/doc/fonts/amiri/tools/runtest.py
new file mode 100755
index 00000000000..fe14f279766
--- /dev/null
+++ b/Master/texmf-dist/doc/fonts/amiri/tools/runtest.py
@@ -0,0 +1,79 @@
+#!/usr/bin/python
+
+import sys
+import os
+import csv
+import subprocess
+
+def runHB(row, font):
+ args = ["hb-shape", "--no-clusters", "--no-positions",
+ "--font-file=%s" %font,
+ "--direction=%s" %row[0],
+ "--script=%s" %row[1],
+ "--language=%s" %row[2],
+ "--features=%s" %row[3],
+ "--text=%s" %row[4]]
+ process = subprocess.Popen(args, stdout=subprocess.PIPE)
+ return process.communicate()[0].strip()
+
+def runTest(reader, font):
+ count = 0
+ failed = {}
+ passed = []
+ for row in reader:
+ count += 1
+ row[4] = ('\\' in row[4]) and row[4].decode('unicode-escape') or row[4]
+ text = row[4]
+ reference = row[5]
+ result = runHB(row, font)
+ if reference == result:
+ passed.append(count)
+ else:
+ failed[count] = (text, reference, result)
+
+ return passed, failed
+
+def initTest(reader, font):
+ out = ""
+ for row in reader:
+ result = runHB(row, font)
+ out += "%s;%s\n" %(";".join(row), result)
+
+ return out
+
+if __name__ == '__main__':
+ init = False
+ args = sys.argv[1:]
+
+ if len (sys.argv) > 2 and sys.argv[1] == "-i":
+ init = True
+ args = sys.argv[2:]
+
+ for arg in args:
+ testname = arg
+
+ testfd = open(testname, 'r')
+ fontname = testfd.readline().strip("# \n")
+ reader = csv.reader(testfd, delimiter=';')
+
+ if init:
+ outname = testname+".test"
+ outfd = open(outname, "w")
+ outfd.write("# %s\n" %fontname)
+ outfd.write(initTest(reader, fontname))
+ outfd.close()
+ sys.exit(0)
+
+ passed, failed = runTest(reader, fontname)
+ message = "%s: %d passed, %d failed" %(os.path.basename(testname), len(passed), len(failed))
+
+ if failed:
+ print message
+ for test in failed:
+ print test
+ print "string: \t", failed[test][0]
+ print "reference:\t", failed[test][1]
+ print "result: \t", failed[test][2]
+ sys.exit(1)
+ else:
+ print message