[go: up one dir, main page]

File: test.py

package info (click to toggle)
ucto 0.35-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,192 kB
  • sloc: cpp: 5,235; xml: 1,226; sh: 409; python: 151; makefile: 44
file content (126 lines) | stat: -rwxr-xr-x 4,936 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
#-*- coding:utf-8 -*-

import glob
import sys
import os

COLORS = [
    'BLACK', 'RED', 'GREEN', 'YELLOW',
    'BLUE', 'MAGENTA', 'CYAN', 'WHITE'
]

exitcode = 0

def color_text(text, color_name, bold=False):
    if color_name in COLORS:
        return "\033[%d;%dm%s\033[0m"  % (int(bold), COLORS.index(color_name) + 30, text)
    sys.stderr.write('ERROR: "%s" is not a valid color.\n' % color_name)
    sys.stderr.write('VALID COLORS: %s.\n' % (', '.join(COLORS)))

def checkVGsummary( id, lang ):
    retcode = os.system('grep "definitely lost" testoutput/' + id + '.' + lang + '.err > testoutput/' + id + '.err.sum')
    retcode = os.system('grep "ERROR SUMMARY" testoutput/' + id + '.' + lang + '.err >> testoutput/' + id + '.err.sum')
    infile = open('testoutput/' + id + '.err.sum',"r")
    while infile:
        line = infile.readline()
        s = line.split()
        if ( len(s) == 0 ):
            break
        num = 0
        for part in s:
            num +=1
            if part == "lost:":
                LOST = int( s[num].replace(',','') )
                break
            if part == "SUMMARY:":
                ERRORS = int( s[num].replace(',','') )
                break
    if ( LOST != 0 or ERRORS != 0 ):
        print( color_text( "OK, but valgrind says:" + str(ERRORS) + " errors, " + str(LOST) + " bytes lost", 'BLUE', True) )
    else:
        print( color_text("OK", 'GREEN', True) )

if len(sys.argv) == 2:
    mask = sys.argv[1]
else:
    mask = '*.txt'

DEBUGLEVEL = 5

if not os.path.isdir('testoutput'):
    os.mkdir('testoutput')

log = ""

if "VG" in os.environ and os.environ["VG"]:
    VG=os.environ["VG"] + " "
    print( "testing with '" + VG + "'. This is slow!",end='' )
else:
    VG=""

for f in glob.glob(mask):
    fields = f.split('.')
    if len(fields) == 3 and fields[-1] == 'txt':
        id = fields[0]
        lang = fields[1]
    else:
        continue

    msg = "Testing: " + id + " (" + lang + ")"
    spaces = " " * (50 - len(msg) )
    print( msg + spaces, end='' )
    if os.path.isfile(id + '.' + lang + '.tok.V'):
        reffile = id + '.' + lang + '.tok.V'
        outputfile = 'testoutput/' + id + '.' + lang + '.tok.V'
        cmd = VG+'../src/.libs/ucto -Q -v -L' + lang + ' ' + f + ' ' + outputfile + ' 2> testoutput/' + id + '.' + lang + '.err'
    elif os.path.isfile(id + '.' + lang + '.tok'):
        reffile = id + '.' + lang + '.tok'
        outputfile = 'testoutput/' + id + '.' + lang + '.tok'
        cmd = VG+'../src/.libs/ucto -Q -L' + lang + ' ' + f + ' ' + outputfile + ' 2> testoutput/' + id + '.' + lang + '.err'
    elif os.path.isfile(id + '.' + lang + '.xml'):
        reffile = id + '.' + lang + '.xml'
        outputfile = 'testoutput/' + id + '.' + lang + '.xml'
        cmd = VG+'../src/.libs/ucto --id="test" -Q -X -L' + lang + ' ' + f + ' ' + outputfile + ' 2> testoutput/' + id + '.' + lang + '.err'
    else:
        print( color_text("MISSING", 'RED', True) )
        exitcode += 1
        continue

    #print cmd
    retcode = os.system(cmd)
    if retcode != 0:
        print( color_text("CRASHED!!!", 'RED', True) )
        if retcode == 2: # lame attempt to bail out on ^C
            break
        exitcode += 1
    else:
        if outputfile[-4:] == ".xml":
            for f2 in (reffile, outputfile):
            #strip the FoLiA version number and the token-annotation declaration (different timestamp)
                os.system("sed -e 's/generator=\".*\"//g' -e 's/version=\".*\"//g' -e 's/datetime=\".*\"//g' -e '/token-annotation/d'  -e '/libfolia/d' "  + f2 + " > " + f2 + ".tmp")
            retcode = os.system('diff -w ' + reffile + '.tmp ' + outputfile  + '.tmp > testoutput/'  + id + '.' + lang + '.diff')
        else:
            retcode = os.system('diff -w ' + outputfile + ' ' + reffile  + ' > testoutput/' + id + '.' + lang + '.diff')
        if retcode == 0:
            if VG:
                checkVGsummary( id, lang )
            else:
                print( color_text("OK", 'GREEN', True) )
                os.system('rm testoutput/' + id + '.' + lang + '.diff')
                os.system('rm testoutput/' + id + '.' + lang + '.err*')
        else:
            print( color_text("FAILED", 'RED', True) )
            exitcode += 1
            log += "testoutput/" + id + '.' + lang + '.diff\n'
            log += "testoutput/" + id + '.' + lang + '.err\n'
            if outputfile[-4:] != ".xml":
                os.system('../src/.libs/ucto -Q -d ' + str(DEBUGLEVEL) + ' -v -L' + lang + ' ' + f + ' ' + outputfile + ' 2> testoutput/' + id + '.' + lang + '.err')
            else:
                os.system('../src/.libs/ucto --id="test" -X -Q -d ' + str(DEBUGLEVEL) + ' -v -L' + lang + ' ' + f + ' ' + outputfile + ' 2> testoutput/' + id + '.' + lang + '.err')

if log:
    print( "--------------------------" )
    print( "Files to inspect:" )
    print( log )
sys.exit(exitcode)