| 1 |
|
| 2 |
from __future__ import print_function |
| 3 |
from __future__ import absolute_import |
| 4 |
|
| 5 |
import sys |
| 6 |
|
| 7 |
from CifFile import ReadCif,CifFile |
| 8 |
|
| 9 |
def runtests(scantype,calling_method): |
| 10 |
"""Scantype is flex or standard, calling method is either |
| 11 |
to construct a CifFile object or using ReadCif""" |
| 12 |
test_table = [ |
| 13 |
["ciftest1", "OK"], |
| 14 |
["ciftest2", "OK"], |
| 15 |
["ciftest3", "OK"], |
| 16 |
["ciftest4", "OK"], |
| 17 |
] |
| 18 |
|
| 19 |
for filename, testresult in test_table: |
| 20 |
try: |
| 21 |
calling_method(filename,scantype=scantype,grammar="2.0") |
| 22 |
except: |
| 23 |
stype,svalue,sinfo = sys.exc_info() |
| 24 |
if testresult == 'OK': |
| 25 |
print("%s causes error where none expected" % filename) |
| 26 |
print("%s\n%s" % (repr(stype),svalue)) |
| 27 |
else: |
| 28 |
if stype in testresult: |
| 29 |
print("%s passes" % filename) |
| 30 |
else: |
| 31 |
print("Unexpected exception %s for %s" % (repr(stype),filename)) |
| 32 |
else: |
| 33 |
if testresult == 'OK': |
| 34 |
print("%s passes" % filename) |
| 35 |
else: |
| 36 |
print("%s: Expected %s, got nothing" % (filename,repr(testresult))) |
| 37 |
if __name__ == "__main__": |
| 38 |
print("Testing interpreted tokenizer+ReadCif") |
| 39 |
runtests("standard",ReadCif) |
| 40 |
print("Testing compiled tokenizer+ReadCif",ReadCif) |
| 41 |
runtests("flex",ReadCif) |
| 42 |
print("Testing interpreted tokenizer+CifFile") |
| 43 |
runtests("standard",CifFile) |
| 44 |
print("Testing compiled tokenizer+CifFile") |
| 45 |
runtests("flex",CifFile) |