⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blackbox.py

📁 a very goog book
💻 PY
字号:
from vtk.util import vtkMethodParserclass 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)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -