File: pypetest.py

package info (click to toggle)
vmtk 1.3%2Bdfsg-2.1%2Bdeb9u1
  • links: PTS, VCS
  • area: non-free
  • in suites: stretch
  • size: 8,932 kB
  • sloc: cpp: 82,947; ansic: 31,817; python: 21,462; perl: 381; makefile: 93; ruby: 41; sh: 19
file content (89 lines) | stat: -rw-r--r-- 3,011 bytes parent folder | download | duplicates (2)
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
#!${PYTHON_SHEBANG}

import vtk
import sys

from vmtk import pypes 

pypetest = 'pypeTest'

class pypeTest(pypes.pypeScript):

    def __init__(self):

        pypes.pypeScript.__init__(self)
        
        self.TestName = None
        self.PypeTestLog = ''
        self.TestInput = None
        self.Condition = None
        self.ConditionValue = None
        self.ConditionType = None

        self.SetScriptName('pypetest')
        self.SetScriptDoc('tests a script property against a condition')
        self.SetInputMembers([
            ['TestName','name','str',1,'','name of the test'],
            ['TestInput','i','test',1,'','log'],
            ['Condition','condition','str',1,'["equalto","differentfrom","greaterthan","lessthan","nonnone"]','condition type'],
            ['ConditionValue','value','str',1,'','condition value'],
            ['ConditionType','type','str',1,'["str","int","float","bool"]','condition type']
            ])
        self.SetOutputMembers([
            ['PypeTestLog','log','str',1,'','log']
            ])

    def castValue(self,val):
        if not self.ConditionType:
            self.PrintError('Error: No condition type.')
        if self.ConditionType == 'str':
            return str(val)
        elif self.ConditionType == 'int':
            return int(val)
        elif self.ConditionType == 'float':
            return float(val)
        elif self.ConditionType == 'bool':
            if val == True or val in ['1','True','true']:
                return True
            else:
                return False

    def Execute(self):

        self.PrintLog('Testing')

        if not self.TestName:
            self.PrintError('Error: No test name.')
        if self.TestInput == None:
            self.PrintError('Error: No test input.')
        if not self.Condition:
            self.PrintError('Error: No condition.')

        passed = False
        self.CompareLog = 'failed'

        if self.Condition == 'equalto':
            if self.ConditionValue and self.castValue(self.TestInput) == self.castValue(self.ConditionValue):
                passed = True
        elif self.Condition == 'differentfrom':
            if self.ConditionValue and self.castValue(self.TestInput) != self.castValue(self.ConditionValue):
                passed = True
        elif self.Condition == 'greaterthan':
            if self.ConditionValue and self.castValue(self.TestInput) > self.castValue(self.ConditionValue):
                passed = True
        elif self.Condition == 'lessthan':
            if self.ConditionValue and self.castValue(self.TestInput) < self.castValue(self.ConditionValue):
                passed = True
        elif self.Condition == 'nonnone':
            if self.TestInput != None :
                passed = True

        if passed:
            self.CompareLog = 'passed'

        self.PypeTestLog = "%s.%s" % (self.TestName, self.CompareLog)

if __name__=='__main__':
    main = pypes.pypeMain()
    main.Arguments = sys.argv
    main.Execute()