<s> from os . path import abspath <EOL> from io import BytesIO <EOL> import copy <EOL> import unittest <EOL> from mayavi . core . null_engine import NullEngine <EOL> from mayavi . filters . optional import Optional <EOL> from mayavi . filters . user_defined import UserDefined <EOL> from mayavi . filters . api import ( CellToPointData , ExtractVectorNorm , ExtractVectorComponents ) <EOL> from mayavi . modules . api import ScalarCutPlane <EOL> from mayavi . sources . vtk_xml_file_reader import VTKXMLFileReader <EOL> from tvtk . api import tvtk <EOL> from mayavi . tests . common import get_example_data <EOL> class TestUserDefined ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> e = NullEngine ( ) <EOL> e . start ( ) <EOL> e . new_scene ( ) <EOL> self . e = e <EOL> r = VTKXMLFileReader ( ) <EOL> r . initialize ( get_example_data ( '<STR_LIT>' ) ) <EOL> e . add_source ( r ) <EOL> cd = tvtk . CellDerivatives ( ) <EOL> ud = UserDefined ( filter = cd ) <EOL> e . add_filter ( ud ) <EOL> ctp = CellToPointData ( ) <EOL> ctp . filter . pass_cell_data = False <EOL> e . add_filter ( ctp ) <EOL> evn = ExtractVectorNorm ( ) <EOL> e . add_filter ( evn ) <EOL> evc = ExtractVectorComponents ( component = '<STR_LIT>' ) <EOL> o = Optional ( filter = evc ) <EOL> e . add_filter ( o ) <EOL> e . add_module ( ScalarCutPlane ( ) ) <EOL> self . scene = e . current_scene <EOL> s = self . scene <EOL> return <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> self . e . stop ( ) <EOL> return <EOL> def check ( self ) : <EOL> """<STR_LIT>""" <EOL> scene = self . scene <EOL> src = scene . children [ <NUM_LIT:0> ] <EOL> ud = src . children [ <NUM_LIT:0> ] <EOL> o = ud . children [ <NUM_LIT:0> ] . children [ <NUM_LIT:0> ] . children [ <NUM_LIT:0> ] <EOL> mm = o . children [ <NUM_LIT:0> ] <EOL> assert src . get_output_dataset ( ) . point_data . scalars . name == '<STR_LIT>' <EOL> assert src . get_output_dataset ( ) . point_data . vectors . name == '<STR_LIT>' <EOL> expect = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> expect1 = [ x + '<STR_LIT>' for x in expect ] <EOL> expect2 = [ x + '<STR_LIT>' for x in expect ] <EOL> o . enabled = True <EOL> assert o . get_output_dataset ( ) . point_data . scalars . name in expect1 <EOL> assert o . get_output_dataset ( ) . point_data . vectors . name in expect <EOL> assert mm . scalar_lut_manager . data_name in expect1 <EOL> o . enabled = False <EOL> assert o . get_output_dataset ( ) . point_data . scalars . name in expect2 <EOL> assert o . get_output_dataset ( ) . point_data . vectors . name in expect <EOL> assert mm . scalar_lut_manager . data_name in expect2 <EOL> ud . filter . vector_mode = '<STR_LIT>' <EOL> assert o . get_output_dataset ( ) . point_data . scalars . name == '<STR_LIT>' <EOL> assert o . get_output_dataset ( ) . point_data . vectors . name == '<STR_LIT>' <EOL> assert mm . scalar_lut_manager . data_name == '<STR_LIT>' <EOL> o . enabled = True <EOL> assert o . get_output_dataset ( ) . point_data . scalars . name == '<STR_LIT>' <EOL> assert o . get_output_dataset ( ) . point_data . vectors . name == '<STR_LIT>' <EOL> assert mm . scalar_lut_manager . data_name == '<STR_LIT>' <EOL> o . enabled = False <EOL> def test_user_defined ( self ) : <EOL> "<STR_LIT>" <EOL> s = self . scene <EOL> self . check ( ) <EOL> def test_save_and_restore ( self ) : <EOL> """<STR_LIT>""" <EOL> engine = self . e <EOL> scene = self . scene <EOL> f = BytesIO ( ) <EOL> f . name = abspath ( '<STR_LIT>' ) <EOL> engine . save_visualization ( f ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> engine . close_scene ( scene ) <EOL> engine . load_visualization ( f ) <EOL> self . scene = engine . current_scene <EOL> s = self . scene <EOL> self . check ( ) <EOL> def test_deepcopied ( self ) : <EOL> """<STR_LIT>""" <EOL> s = self . scene <EOL> source = s . children . pop ( ) <EOL> s . children . append ( source ) <EOL> cp = source . children [ <NUM_LIT:0> ] . children [ - <NUM_LIT:1> ] <EOL> s = self . scene <EOL> self . check ( ) <EOL> source1 = copy . deepcopy ( source ) <EOL> s . children [ <NUM_LIT:0> ] = source1 <EOL> s = self . scene <EOL> self . check ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
