MCPcopy Create free account
hub / github.com/Kitware/VTK / testOverrideWarning

Method testOverrideWarning

Common/Core/Testing/Python/TestSubClass.py:142–160  ·  view source on GitHub ↗

Check if a late call to __init__() modifies the C++ object

(self)

Source from the content-addressed store, hash-verified

140 self.assertTrue(vtkPoints().__class__ == vtkPoints)
141
142 def testOverrideWarning(self):
143 """Check if a late call to __init__() modifies the C++ object"""
144 # check that the object has the correct class
145 vtkImageData.override(vtkImageDataWarning)
146 self.assertTrue(isinstance(vtkImageData(), vtkImageDataWarning))
147 # check object created deep in c++
148 source = vtkImageGridSource()
149 source.SetDataExtent(0, 255, 0, 255, 0, 0)
150 source.SetDataSpacing(0.1, 0.1, 1.0)
151 # calling Update() instantiates the data object in C++
152 source.Update()
153 # calling GetOutput() instantiates the data object in Python,
154 # and reports RuntimeWarning because our override modifies the data
155 with self.assertWarns(RuntimeWarning):
156 data = source.GetOutput()
157 # the custom __init__() method modified the spacing to be (1.0,1.0,1.0),
158 # the purpose of the RuntimeWarning is to let the user know that an odd
159 # modification like this has occurred
160 self.assertEqual(data.GetSpacing(), (1.0, 1.0, 1.0))
161
162if __name__ == "__main__":
163 Testing.main([(TestSubclass, 'test')])

Callers

nothing calls this directly

Calls 6

SetDataExtentMethod · 0.80
SetDataSpacingMethod · 0.80
vtkImageDataFunction · 0.50
UpdateMethod · 0.45
GetOutputMethod · 0.45
GetSpacingMethod · 0.45

Tested by

no test coverage detected