[liblouis-liblouisxml] proposal for a test harness

  • From: Mesar Hameed <mesar.hameed@xxxxxxxxx>
  • To: Christian Egli <christian.egli@xxxxxx>
  • Date: Wed, 22 Feb 2012 15:46:45 +0000

Hi Christian,

On Wed 22/02/12,10:15, Christian Egli wrote:
> > I feel that many problems can be found and ironed out if the liblouis
> > had an extensive test harness for the various tables. 
> 
> I'd be happy to work with you on this.

Thanks, this would be great.

> > This is how I personally managed to quickly find a somewhat working 
> > solution.
> 
> Are you saying you have some kind of test harness?

Yes, attached, not sure if it is as flexible as we want it to be, but it did 
the job for me.

1. Create a harness directory at the same level as tables, tools etc.
2. Place the two attached files there.
3. cd harness; python runHarness.py

All the test data is stored in the *_harness.py file.
each table that should be tested should have its own harness file with test 
cases.
Each file specifies the table, and the test cases that should be run against it.
Each test should have:
  A comment explaining the purpose of the test.
  (unicode) text input,
  (ascii braille) expected braille output. 

The expected output for test 3 is deliberately wrong to show you the format for 
when a test fails.

The harness file is simple and should hopefully encourage people to contribute 
tests for their tables.

If you have suggestions for improving or extending this please let me know and 
I will see what can be done.

Thanks.
Mesar
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import sys
import louis
from glob import glob

tablePath = '../tables/'
tables = glob(tablePath + "*")

harnesses = glob('*_harness.py')
for harness in harnesses:
    try:
        harnessModule = __import__(harness[:-3])
    except Exception, e:
        print "Warning: could not import %s" %harness
        print e
        continue
    if not glob(tablePath+ harnessModule.table):
        print "WARNING: unable to locate %s, please check capitalization and 
extension." %harnessModule.table
        continue
    print "Processing %s" %harness
    failed = 0
    table = [tablePath+ harnessModule.table]
    for text, expectedBraille in harnessModule.tests:
        braille = louis.translate(table, text, typeform=None)[0]
        if braille != expectedBraille:
            failed += 1 
            print("--- Failure: ---\n" +
                  "text:\t\t'%s'\n" % text +
                  "expected:\t'%s'\n" % expectedBraille +
                  "received:\t'%s'\n" % braille +
                  "--- end ---")
    print "%d of %d tests failed." %(failed, len(harnessModule.tests))
# -*- coding: UTF-8 -*-

table = 'en-GB-g2.ctb'

tests = [
    (
        # check that "the" is correctly contracted
        u'the cat sat on the mat', 
        u'! cat sat on ! mat'
    ), (
        # Checking "to" is contracted correctly and joined to next word.
        u'to the moon',
        u'6! moon'
    ), (
        # Check that "to" at end of line doesnt get contracted.
        u'he went to',
        u'he went 6',
    )
]

Other related posts: