<s> """<STR_LIT>""" <EOL> from os . path import abspath <EOL> from io import BytesIO <EOL> import copy <EOL> import numpy <EOL> from traits . api import TraitError <EOL> from common import TestCase <EOL> class TestArraySource ( TestCase ) : <EOL> def check_input_validation ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> obj . scalar_data = numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) , '<STR_LIT:d>' ) <EOL> obj . scalar_data = numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ) , '<STR_LIT:d>' ) <EOL> obj . scalar_data = None <EOL> obj . vector_data = numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> ) , '<STR_LIT:d>' ) <EOL> obj . vector_data = numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> ) , '<STR_LIT:d>' ) <EOL> obj . vector_data = None <EOL> self . assertRaises ( TraitError , setattr , obj , '<STR_LIT>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> self . assertRaises ( TraitError , setattr , obj , '<STR_LIT>' , <EOL> numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> ) , '<STR_LIT:d>' ) ) <EOL> obj . scalar_data = None <EOL> self . assertRaises ( TraitError , setattr , obj , '<STR_LIT>' , [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ] ) <EOL> self . assertRaises ( TraitError , setattr , obj , '<STR_LIT>' , <EOL> numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:1> ) , '<STR_LIT:d>' ) ) <EOL> obj . vector_data = None <EOL> obj . scalar_data = numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) , '<STR_LIT:d>' ) <EOL> self . assertRaises ( TraitError , setattr , obj , '<STR_LIT>' , <EOL> numpy . zeros ( ( <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:3> ) , '<STR_LIT:d>' ) ) <EOL> obj . vector_data = numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> ) , '<STR_LIT:d>' ) <EOL> self . assertRaises ( TraitError , setattr , obj , '<STR_LIT>' , <EOL> numpy . zeros ( ( <NUM_LIT:4> , <NUM_LIT:3> ) , '<STR_LIT:i>' ) ) <EOL> self . assertRaises ( TraitError , setattr , obj , '<STR_LIT>' , <EOL> numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ) , '<STR_LIT:i>' ) ) <EOL> obj . scalar_data = numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) , '<STR_LIT:f>' ) <EOL> obj . scalar_data = obj . vector_data = None <EOL> def make_2d_data ( self ) : <EOL> s = numpy . array ( [ [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:3> ] ] , '<STR_LIT:d>' ) <EOL> v = numpy . array ( [ [ [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] ] , [ [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] ] ] , '<STR_LIT:d>' ) <EOL> tps = numpy . transpose <EOL> s , v = tps ( s ) , tps ( v , ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> ) ) <EOL> return s , v <EOL> def make_3d_data ( self ) : <EOL> s = numpy . array ( [ [ [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:3> ] ] , <EOL> [ [ <NUM_LIT:4> , <NUM_LIT:5> ] , [ <NUM_LIT:6> , <NUM_LIT:7> ] ] ] , '<STR_LIT:d>' ) <EOL> v = numpy . array ( [ [ [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] ] , <EOL> [ [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> ] ] ] , <EOL> [ [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] ] , <EOL> [ [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] ] ] ] , '<STR_LIT:d>' ) <EOL> tps = numpy . transpose <EOL> s , v = tps ( s ) , tps ( v , ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:3> ) ) <EOL> return s , v <EOL> def check ( self ) : <EOL> script = self . script <EOL> s = script . engine . current_scene <EOL> d1 , d2 = s . children <EOL> s1 , v1 = d1 . children [ <NUM_LIT:0> ] . children [ <NUM_LIT:1> : ] <EOL> expect = list ( self . make_2d_data ( ) ) <EOL> tps = numpy . transpose <EOL> expect [ <NUM_LIT:0> ] = tps ( expect [ <NUM_LIT:0> ] ) <EOL> expect [ <NUM_LIT:1> ] = tps ( expect [ <NUM_LIT:1> ] , ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> ) ) <EOL> sc1 = s1 . actor . mapper . input . point_data . scalars . to_array ( ) <EOL> assert numpy . allclose ( sc1 . flatten ( ) , expect [ <NUM_LIT:0> ] . flatten ( ) ) <EOL> vec1 = s1 . actor . mapper . input . point_data . vectors . to_array ( ) <EOL> assert numpy . allclose ( vec1 . flatten ( ) , expect [ <NUM_LIT:1> ] . flatten ( ) ) <EOL> s2 , v2 = d2 . children [ <NUM_LIT:0> ] . children [ <NUM_LIT:1> : ] <EOL> expect = list ( self . make_3d_data ( ) ) <EOL> tps = numpy . transpose <EOL> expect [ <NUM_LIT:0> ] = tps ( expect [ <NUM_LIT:0> ] ) <EOL> expect [ <NUM_LIT:1> ] = tps ( expect [ <NUM_LIT:1> ] , ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:3> ) ) <EOL> sc2 = s2 . actor . mapper . input . point_data . scalars . to_array ( ) <EOL> assert numpy . allclose ( sc2 . flatten ( ) , expect [ <NUM_LIT:0> ] . flatten ( ) ) <EOL> vec2 = s2 . actor . mapper . input . point_data . vectors . to_array ( ) <EOL> assert numpy . allclose ( vec2 . flatten ( ) , expect [ <NUM_LIT:1> ] . flatten ( ) ) <EOL> def test ( self ) : <EOL> self . main ( ) <EOL> def do ( self ) : <EOL> script = self . script <EOL> from mayavi . sources . array_source import ArraySource <EOL> from mayavi . modules . outline import Outline <EOL> from mayavi . modules . surface import Surface <EOL> from mayavi . modules . vectors import Vectors <EOL> s = self . new_scene ( ) <EOL> d = ArraySource ( ) <EOL> self . check_input_validation ( d ) <EOL> sc , vec = self . make_2d_data ( ) <EOL> d . origin = ( - <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> d . scalar_data = sc <EOL> d . vector_data = vec <EOL> script . add_source ( d ) <EOL> o = Outline ( ) <EOL> script . add_module ( o ) <EOL> s = Surface ( ) <EOL> script . add_module ( s ) <EOL> v = Vectors ( ) <EOL> script . add_module ( v ) <EOL> d = ArraySource ( ) <EOL> sc , vec = self . make_3d_data ( ) <EOL> d . scalar_data = sc <EOL> d . vector_data = vec <EOL> script . add_source ( d ) <EOL> o = Outline ( ) <EOL> script . add_module ( o ) <EOL> s = Surface ( ) <EOL> script . add_module ( s ) <EOL> v = Vectors ( ) <EOL> script . add_module ( v ) <EOL> s . scene . z_plus_view ( ) <EOL> c = s . scene . camera <EOL> c . azimuth ( - <NUM_LIT:30> ) <EOL> c . elevation ( <NUM_LIT:30> ) <EOL> self . check ( ) <EOL> bg = s . scene . background <EOL> f = BytesIO ( ) <EOL> f . name = abspath ( '<STR_LIT>' ) <EOL> script . save_visualization ( f ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> engine = script . engine <EOL> engine . close_scene ( s ) <EOL> script . load_visualization ( f ) <EOL> s = engine . current_scene <EOL> s . scene . z_plus_view ( ) <EOL> c = s . scene . camera <EOL> c . azimuth ( - <NUM_LIT:30> ) <EOL> c . elevation ( <NUM_LIT:30> ) <EOL> s . scene . background = bg <EOL> self . check ( ) <EOL> sources = s . children <EOL> s . children = [ ] <EOL> s . children . extend ( sources ) <EOL> s . scene . reset_zoom ( ) <EOL> self . check ( ) <EOL> sources1 = copy . deepcopy ( sources ) <EOL> s . children [ : ] = sources <EOL> s . scene . reset_zoom ( ) <EOL> self . check ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> t = TestArraySource ( ) <EOL> t . test ( ) </s>
