Revision: 668 Author: mesar.hameed@xxxxxxxxx Date: Tue Jun 5 00:23:28 2012 Log: runHarnessV2.py: * python 2/3 bytestrings vs unicode object agnostic. * Add backtranslate test (Thanks Attila). http://code.google.com/p/liblouis/source/detail?r=668 Modified: /trunk/tests/runHarnessV2.py ======================================= --- /trunk/tests/runHarnessV2.py Wed May 30 10:00:22 2012 +++ /trunk/tests/runHarnessV2.py Tue Jun 5 00:23:28 2012 @@ -23,14 +23,23 @@ @author: Mesar Hameed <mhameed@xxxxxxxxxxxxx> @author: Michael Whapples <mwhapples@xxxxxxx> +@author: Hammer Attila <hammera@xxxxxxxxx> """ import json import os -from louis import translate +import sys +from louis import translate, backTranslateStringfrom louis import noContractions, compbrlAtCursor, dotsIO, comp8Dots, pass1Only, compbrlLeftCursor, otherTrans, ucBrl
from glob import iglob +PY2 = sys.version_info[0] == 2 + +def u(a): + if PY2: + return a.encode("utf-8") + return a + modes = { 'noContractions': noContractions, 'compbrlAtCursor': compbrlAtCursor, @@ -52,7 +61,7 @@ return "".join(display) class BrailleTest():- def __init__(self, harnessName, table, txt, brl, mode=0, cursorPos=None, brlCursorPos=None, comment=None): + def __init__(self, harnessName, table, txt, brl, mode=0, cursorPos=None, brlCursorPos=None, comment=None, test_type=None):
self.harnessName = harnessName self.table = table self.txt = txt @@ -60,11 +69,14 @@ self.mode = mode if not mode else modes[mode] self.cursorPos = cursorPos self.expectedBrlCursorPos = brlCursorPos + self.comment = comment + self.test_type = 'translate' if not test_type else test_type def __str__(self): return "%s: %s" % (self.harnessName, self.txt) - def check_braille(self): + def check_translate(self): + if self.test_type != 'translate': return if self.cursorPos is not None:tBrl, temp1, temp2, tBrlCurPos = translate(self.table, self.txt, mode=self.mode, cursorPos=self.cursorPos)
else: @@ -78,7 +90,20 @@ template % ("actual brl:", tBrl), "--- end ---", ] - assert tBrl == self.expectedBrl, "\n".join(report).encode("utf-8") + assert tBrl == self.expectedBrl, u("\n".join(report)) + + def check_backtranslate(self): + if self.test_type != 'backtranslate': return+ backtranslate_output = backTranslateString(self.table, self.expectedBrl, None, mode=self.mode)
+ template = "%-25s '%s'" + report = [ + self.__str__(), + "--- Backtranslate failure: ---", + template % ("expected word:", self.txt),+ template % ("actual backtranslated word:", backtranslate_output),
+ "--- end ---", + ] + assert backtranslate_output == self.txt, u("\n".join(report)) def check_cursor(self): if self.cursorPos == None: return @@ -89,10 +114,11 @@ self.__str__(), "--- Braille Cursor Difference Failure: ---", template % ("received brl:", tBrl),- template % ("BRLCursorAt %d expected %d:" %(tBrlCurPos, self.expectedBrlCursorPos), etBrlCurPosStr), + template % ("BRLCursorAt %d expected %d:" %(tBrlCurPos, self.expectedBrlCursorPos),
+ etBrlCurPosStr), "--- end ---" ]- assert tBrlCurPos == self.expectedBrlCursorPos, "\n".join(report).encode("utf-8") + assert tBrlCurPos == self.expectedBrlCursorPos, u("\n".join(report))
def test_allCases(): harness_dir = "harness" @@ -114,10 +140,10 @@ harnessModule = json.load(f, encoding="UTF-8") f.close() print("Processing %s" %harness) - tableList = [harnessModule['table'].encode('UTF-8')] + tableList = [u(harnessModule['table'])] for test in harnessModule['tests']: bt = BrailleTest(harness, tableList, **test) - yield bt.check_braille + yield bt.check_translate yield bt.check_cursor - + yield bt.check_backtranslate For a description of the software, to download it and links to project pages go to http://www.abilitiessoft.com