File: BlackBox.py

package info (click to toggle)
paraview 3.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 124,600 kB
  • ctags: 133,728
  • sloc: cpp: 958,817; ansic: 509,658; tcl: 45,787; xml: 23,401; python: 19,574; perl: 3,112; yacc: 1,787; java: 1,517; sh: 665; asm: 471; lex: 400; makefile: 168; objc: 28
file content (90 lines) | stat: -rw-r--r-- 2,817 bytes parent folder | download | duplicates (6)
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
from vtk.util import vtkMethodParser


class Tester:
    def __init__(self, debug=0):
        self.setDebug(debug)
        self.parser = vtkMethodParser.VtkDirMethodParser()
        self.obj = None

    def setDebug(self, val):
        """Sets debug value of the vtkMethodParser.  1 is verbose and
        0 is not.  0 is default."""
        vtkMethodParser.DEBUG = val

    def testParse(self, obj):
        """ Testing if the object is parseable."""
        self.parser.parse_methods(obj)
        self.obj = obj

    def testGetSet(self, obj):
        """ Testing Get/Set methods."""
        if obj != self.obj:
            self.testParse(obj)
        methods = self.parser.get_set_methods()
        toggle = map(lambda x: x[:-2], self.parser.toggle_methods())
        methods.extend(toggle)
        for method in methods:
            setm = "Set%s"%method
            getm = "Get%s"%method
            val = eval("obj.%s()"%getm)
            try:
                apply(eval("obj.%s"%setm), val)
            except TypeError:
                apply(eval("obj.%s"%setm), (val,))

            val1 = eval("obj.%s()"%getm)

            if val1 != val:
                name = obj.GetClassName()
                msg = "Failed test for %(name)s.Get/Set%(method)s\n"\
                      "Before Set, value = %(val)s; "\
                      "After Set, value = %(val1)s"%locals()
                raise AssertionError, msg

    def testBoolean(self, obj):
        """ Testing boolean (On/Off) methods."""
        if obj != self.obj:
            self.testParse(obj)
        methods = self.parser.toggle_methods()
        for method1 in methods:
            method = method1[:-2]
            getm = "Get%s"%method

            orig_val = eval("obj.%s()"%getm)

            # Turn on
            eval("obj.%sOn()"%method)
            val = eval("obj.%s()"%getm)
            
            if val != 1:
                name = obj.GetClassName()
                msg = "Failed test for %(name)s.%(method)sOn\n"\
                      "Result not equal to 1 "%locals()
                raise AssertionError, msg

            # Turn on
            eval("obj.%sOff()"%method)
            val = eval("obj.%s()"%getm)
            
            if val != 0:
                name = obj.GetClassName()
                msg = "Failed test for %(name)s.%(method)sOff\n"\
                      "Result not equal to 0 "%locals()
                raise AssertionError, msg

            # set the value back to the original value.
            eval("obj.Set%s(orig_val)"%method)


    def test(self, obj):
        """Test the given vtk object."""

        # first try parsing the object.
        self.testParse(obj)

        # test the get/set methods
        self.testGetSet(obj)

        # test the boolean methods
        self.testBoolean(obj)