pymech icon indicating copy to clipboard operation
pymech copied to clipboard

Fix tvtk API and failing tests with `traits.trait_errors.TraitError`

Open ashwinvis opened this issue 2 months ago • 0 comments

The following tests keep failing because some API has changed in tvtk package.

FAILED tests/test_vtk.py::test_writevtk[True] - traits.trait_errors.TraitError: Cannot set the undefined 'copy_global_ids' attribute of a 'PointData' object.
FAILED tests/test_vtk.py::test_writevtk[False] - traits.trait_errors.TraitError: Cannot set the undefined 'copy_global_ids' attribute of a 'PointData' object.
>       writevtk(out_fname, field)

tests/test_vtk.py:30: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.nox/tests-cov-vtk-3-12/lib/python3.12/site-packages/pymech/vtksuite.py:200: in writevtk
    vtk_dataset = hexa2vtk(data)
.nox/tests-cov-vtk-3-12/lib/python3.12/site-packages/pymech/vtksuite.py:162: in hexa2vtk
    dataset.point_data.vectors = v
tvtk_classes/data_set.py:373: in _get_point_data
    ???
tvtk_classes/tvtk_helper.py:65: in wrap_vtk
    ???
tvtk_classes/point_data.py:51: in __init__
    ???
.nox/tests-cov-vtk-3-12/lib/python3.12/site-packages/tvtk/tvtk_base.py:432: in __init__
    self.update_traits()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <tvtk.tvtk_classes.point_data.PointData object at 0x7f120b75a4b0>
obj = None, event = None

    def update_traits(self, obj=None, event=None):
        """Updates all the 'updateable' traits of the object.
    
        The method works by getting the current value from the wrapped
        VTK object.  `self._updateable_traits_` stores a tuple of
        tuples containing the trait name followed by the name of the
        get method to use on the wrapped VTK object.
    
        The `obj` and `event` parameters may be ignored and are not
        used in the function.  They exist only for compatibility with
        the VTK observer callback functions.
    
        """
        if self._in_set or _DISABLE_UPDATE:
            return
        if not hasattr(self, '_updateable_traits_'):
            return
    
        self._in_set = self.DOING_UPDATE
        vtk_obj = self._vtk_obj
    
        # Save the warning state and turn it off!
        warn = vtk.vtkObject.GetGlobalWarningDisplay()
        vtk.vtkObject.GlobalWarningDisplayOff()
    
        for name, getter in self._updateable_traits_:
            if name == 'global_warning_display':
                setattr(self, name, warn)
                continue
    
            try:
                val = getattr(vtk_obj, getter)()
            except (AttributeError, TypeError):
                # Some vtk GetMethod accepts more than 1 arguments
                # FIXME: If we really want to try harder, we could
                # pass an empty array to the Get method, some Get
                # method will populate the array as the return
                # value (e.g. vtkImageConvolve.GetKernel3x3 and alike)
                pass
            else:
                try:
>                   setattr(self, name, val)
E                   traits.trait_errors.TraitError: Cannot set the undefined 'copy_global_ids' attribute of a 'PointData' object.

.nox/tests-cov-vtk-3-12/lib/python3.12/site-packages/tvtk/tvtk_base.py:585: TraitError
----------------------------- Captured stdout call -----------------------------
[08/21/25 07:22:40] WARNING  The module pymech.vtksuite is        vtksuite.py:11
                             experimental in nature and may have                
                             some rough edges. The functions can                
                             also change in the future.                         
[08/21/25 07:22:41] INFO     Renaming                            vtksuite.py:197
                             /tmp/pytest-of-runner/pytest-1/test                
                             _writevtk_True_0/channel3D_0.f00001                
                              with extension .vtp                               
------------------------------ Captured log call -------------------------------
WARNING  pymech:vtksuite.py:11 The module pymech.vtksuite is experimental in nature and may have some rough edges. The functions can also change in the future.
INFO     pymech:vtksuite.py:197 Renaming /tmp/pytest-of-runner/pytest-1/test_writevtk_True_0/channel3D_0.f00001 with extension .vtp
_____________________________ test_writevtk[False] _____________________________

For now, the tests will be marked as xfail.

ashwinvis avatar Nov 09 '25 11:11 ashwinvis