summaryrefslogtreecommitdiff
path: root/test/sailtest.py
blob: 612aba2ba2ef7ca46947055960b582d26f7e70cb (plain)
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
import os
import re
import sys
import subprocess
import datetime

class color:
    NOTICE = '\033[94m'
    PASS = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    END = '\033[0m'


def step(string):
    p = subprocess.Popen(string, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
    out, err = p.communicate()
    status = p.wait()
    if status != 0:
        print("{}Failed{}: {}".format(color.FAIL, color.END, string))
        print('{}stdout{}:'.format(color.NOTICE, color.END))
        print(out)
        print('{}stderr{}:'.format(color.NOTICE, color.END))
        print(err)
        sys.exit(1)

def banner(string):
    print '-' * len(string)
    print string
    print '-' * len(string)

def collect_results(name, tests):
    passes = 0
    failures = 0
    xml = ""

    for test in tests:
        _, status = os.waitpid(tests[test], 0)
        if status != 0:
            failures += 1
            xml += '    <testcase name="{}">\n      <error message="fail">fail</error>\n    </testcase>\n'.format(test)
        else:
            passes += 1
            xml += '    <testcase name="{}"/>\n'.format(test)

    print '{}{} passes and {} failures{}'.format(color.NOTICE, passes, failures, color.END)

    time = datetime.datetime.utcnow()
    suite = '  <testsuite name="{}" tests="{}" failures="{}" timestamp="{}">\n{}  </testsuite>\n'
    xml = suite.format(name, passes + failures, failures, time, xml)
    return xml