-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
50 lines (43 loc) · 1.31 KB
/
test.py
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
import glob
import yaml
import datetime
import re
#TODO Write test log in markdown and CSV
files = glob.glob('./regex/*.yaml')
today = datetime.date.today()
startTime = datetime.datetime.now()
failCount = 0
for regexDoc in files:
yamlFile = open(regexDoc, 'r')
docData = yaml.load (yamlFile.read())
regexString = docData['regex']
expectedResults = docData['testResults']
expectedSubgroupResults = docData['testSubgroupResults']
p = re.compile(regexString)
iterator = p.finditer(docData['testString'])
subgroupCount = regexString.count('(')
actualResults = []
actualSubgroupResults = []
for match in iterator:
if match:
actualResults.append(match.group())
for subgroup in range(1,subgroupCount + 1):
actualSubgroupResults.append(match.group(subgroup))
print 'Testing regex in:', regexDoc
if expectedResults == actualResults and expectedSubgroupResults == actualSubgroupResults:
print 'Test passed.'
else:
failCount += 1
print 'FAIL'
print 'Expected matches:'
print expectedResults
print 'Actual matches:'
print actualResults
print 'Expected subgroup matches:'
print expectedSubgroupResults
print 'Actual subgroup matches:'
print actualSubgroupResults
testTime = datetime.datetime.now() - startTime
print 'Test complete.'
print 'Failed tests:', failCount
print 'Time elapsed:', testTime