<s> from os . path import abspath <EOL> from io import BytesIO <EOL> import copy <EOL> import numpy <EOL> import unittest <EOL> from mayavi . core . engine import Engine <EOL> from mayavi . core . null_engine import NullEngine <EOL> from mayavi . sources . array_source import ArraySource <EOL> from mayavi . modules . outline import Outline <EOL> from mayavi . modules . image_plane_widget import ImagePlaneWidget <EOL> class TestImagePlaneWidget ( unittest . TestCase ) : <EOL> def make_data ( self ) : <EOL> """<STR_LIT>""" <EOL> dims = numpy . array ( ( <NUM_LIT:64> , <NUM_LIT:64> , <NUM_LIT:64> ) , '<STR_LIT:i>' ) <EOL> dx , dy , dz = <NUM_LIT> / ( dims - <NUM_LIT:1> ) <EOL> x = numpy . reshape ( numpy . arange ( - <NUM_LIT> , <NUM_LIT> + dx * <NUM_LIT:0.5> , dx , '<STR_LIT:f>' ) , <EOL> ( dims [ <NUM_LIT:0> ] , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> y = numpy . reshape ( numpy . arange ( - <NUM_LIT> , <NUM_LIT> + dy * <NUM_LIT:0.5> , dy , '<STR_LIT:f>' ) , <EOL> ( <NUM_LIT:1> , dims [ <NUM_LIT:1> ] , <NUM_LIT:1> ) ) <EOL> z = numpy . reshape ( numpy . arange ( - <NUM_LIT> , <NUM_LIT> + dz * <NUM_LIT:0.5> , dz , '<STR_LIT:f>' ) , <EOL> ( <NUM_LIT:1> , <NUM_LIT:1> , dims [ <NUM_LIT:0> ] ) ) <EOL> scalars = numpy . sin ( x * y * z ) / ( x * y * z ) <EOL> return scalars <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> e = NullEngine ( ) <EOL> e . start ( ) <EOL> s = e . new_scene ( ) <EOL> self . e = e <EOL> self . s = s <EOL> d = ArraySource ( ) <EOL> sc = self . make_data ( ) <EOL> d . scalar_data = sc <EOL> e . add_source ( d ) <EOL> o = Outline ( ) <EOL> e . add_module ( o ) <EOL> ipw = ImagePlaneWidget ( ) <EOL> e . add_module ( ipw ) <EOL> ipw_y = ImagePlaneWidget ( ) <EOL> e . add_module ( ipw_y ) <EOL> ipw_y . ipw . plane_orientation = '<STR_LIT>' <EOL> ipw_z = ImagePlaneWidget ( ) <EOL> e . add_module ( ipw_z ) <EOL> ipw_z . ipw . plane_orientation = '<STR_LIT>' <EOL> self . scene = e . current_scene <EOL> return <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> self . e . stop ( ) <EOL> return <EOL> def check ( self ) : <EOL> """<STR_LIT>""" <EOL> s = self . scene <EOL> src = s . children [ <NUM_LIT:0> ] <EOL> i1 , i2 , i3 = src . children [ <NUM_LIT:0> ] . children [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( i1 . ipw . plane_orientation , '<STR_LIT>' ) <EOL> self . assertEqual ( numpy . allclose ( i1 . ipw . center , ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) , True ) <EOL> self . assertEqual ( i2 . ipw . plane_orientation , '<STR_LIT>' ) <EOL> self . assertEqual ( numpy . allclose ( i2 . ipw . center , ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> ) ) , True ) <EOL> self . assertEqual ( i3 . ipw . plane_orientation , '<STR_LIT>' ) <EOL> self . assertEqual ( numpy . allclose ( i3 . ipw . center , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ) ) , True ) <EOL> def test_image_plane_widget ( self ) : <EOL> "<STR_LIT>" <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> self . check ( ) <EOL> def test_deepcopied ( self ) : <EOL> """<STR_LIT>""" <EOL> s = self . scene <EOL> sources = s . children <EOL> s . children = [ ] <EOL> s . children . extend ( sources ) <EOL> self . check ( ) <EOL> sources1 = copy . deepcopy ( sources ) <EOL> s . children [ : ] = sources1 <EOL> self . check ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
