-
Notifications
You must be signed in to change notification settings - Fork 2
/
checks.py
70 lines (57 loc) · 3.13 KB
/
checks.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from command import Command
# preRun commands
def checkTargetName(target, supportedTargets):
""" Returns if the current target is supported by the test or not. """
if (isinstance(supportedTargets, str)):
unsupportedTargets = (supportedTargets, )
if (target.name() not in supportedTargets):
return "Not applicable for target %s, the test is only valid for: %s" % (target.name(), ", ".join(supportedTargets))
def disableForTarget(target, unsupportedTargets):
""" Disables the test if the target matches any of the submitted. """
if (isinstance(unsupportedTargets, str)):
unsupportedTargets = (unsupportedTargets, )
if (target.name() in unsupportedTargets):
return "Not applicable for target %s" % (target.name())
# postRun commands
def assertOutput(output, expected, fromEnd = True):
""" Checks that the output is the expected one. If partial is true, the check passes even if the actual output only contains the expected text. """
if (fromEnd):
if (output[-len(expected):] != expected):
return "Expected string not found at the end of the output:\nOutput: %s\nExpected: %s " % (output,expected)
else:
if (output != expected):
return "Expected string not identical with formatted output:\nOutput: %s\nExpected: %s " % (output,expected)
def assertOutputIsOnlyTrue(output, fromEnd = True):
""" Checks that the output consists only of TRUE values and nothing else. Does not care how many true values it sees. """
if (fromEnd):
o = output.split(" ")
i = len(o) - 1
while (i>=0):
if (o[i].strip() == "FALSE"):
return "Expected only trailing TRUE values, but FALSE found:\n%s" % output
if (o[i] != "TRUE"):
break
i -= 1
else:
if ("".join(output.split("TRUE")).strip()):
return "Expected result of only TRUE values, but following result was found:\n%s" % output
def assertNoWarning(testErr):
""" Returns true if the test did not produce any warning, which means the error ouput is empty. """
if (testErr):
return "Expected no warings, but stderr contains: %s" % testErr
def assertWarning(testErr, expected = False):
""" Checks if there is a warning reported by the execution. If the epected argument is not specified, any warning will do, otherwise the expected contents of the warning is checked. """
if (expected):
if (testErr.find("Warning") == -1 or testErr.find(expected) == -1):
return "Expected warning %s, but the following stderr found: %s" % (expected, testErr if (testErr) else "(empty)")
else:
if (testErr.find("Warning") == -1):
return "Expected warning, but the following stderr found: %s" % (testErr if (testErr) else "(empty)")
def assertError(testErr, expected = False):
""" Checks if there is an error reported by the execution. If the epected argument is not specified, any error will do, otherwise the expected contents of the warning is checked. """
if (expected):
if (testErr.find("Error") == -1 or testErr.find(expected) == -1):
return "Expected error %s, but the following stderr found: %s" % (expected, testErr if (testErr) else "(empty)")
else:
if (testErr.find("Error") == -1):
return "Expected error, but the following stderr found: %s" % (testErr if (testErr) else "(empty)")