<s> from __future__ import absolute_import , division , print_function <EOL> import numpy as np <EOL> from mock import MagicMock , patch <EOL> from glue . core import Data , DataCollection <EOL> from glue . app . qt import GlueApplication <EOL> from glue . core . tests . util import simple_session <EOL> from . . data_viewer import DataViewer <EOL> from glue . viewers . histogram . qt import HistogramWidget <EOL> from glue . viewers . image . qt import ImageWidget <EOL> from glue . viewers . scatter . qt import ScatterWidget <EOL> def setup_function ( func ) : <EOL> import os <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:True>' <EOL> class BaseTestDataViewer ( object ) : <EOL> ndim = <NUM_LIT:1> <EOL> def test_unregister_on_close ( self ) : <EOL> session = simple_session ( ) <EOL> hub = session . hub <EOL> w = self . widget_cls ( session ) <EOL> w . register_to_hub ( hub ) <EOL> with patch . object ( DataViewer , '<STR_LIT>' ) as unregister : <EOL> w . close ( ) <EOL> unregister . assert_called_once_with ( hub ) <EOL> def test_single_draw_call_on_create ( self ) : <EOL> d = Data ( x = np . random . random ( ( <NUM_LIT:2> , ) * self . ndim ) ) <EOL> dc = DataCollection ( [ d ] ) <EOL> app = GlueApplication ( dc ) <EOL> try : <EOL> from glue . viewers . common . qt . mpl_widget import MplCanvas <EOL> draw = MplCanvas . draw <EOL> MplCanvas . draw = MagicMock ( ) <EOL> app . new_data_viewer ( self . widget_cls , data = d ) <EOL> selfs = [ c [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] for c in MplCanvas . draw . call_arg_list ] <EOL> assert len ( set ( selfs ) ) == len ( selfs ) <EOL> finally : <EOL> MplCanvas . draw = draw <EOL> def test_close_on_last_layer_remove ( self ) : <EOL> d1 = Data ( x = np . random . random ( ( <NUM_LIT:2> , ) * self . ndim ) ) <EOL> d2 = Data ( y = np . random . random ( ( <NUM_LIT:2> , ) * self . ndim ) ) <EOL> dc = DataCollection ( [ d1 , d2 ] ) <EOL> app = GlueApplication ( dc ) <EOL> with patch . object ( self . widget_cls , '<STR_LIT>' ) as close : <EOL> w = app . new_data_viewer ( self . widget_cls , data = d1 ) <EOL> w . add_data ( d2 ) <EOL> dc . remove ( d1 ) <EOL> dc . remove ( d2 ) <EOL> assert close . call_count >= <NUM_LIT:1> <EOL> def test_viewer_size ( self , tmpdir ) : <EOL> d1 = Data ( x = np . random . random ( ( <NUM_LIT:2> , ) * self . ndim ) ) <EOL> d2 = Data ( x = np . random . random ( ( <NUM_LIT:2> , ) * self . ndim ) ) <EOL> dc = DataCollection ( [ d1 , d2 ] ) <EOL> app = GlueApplication ( dc ) <EOL> w = app . new_data_viewer ( self . widget_cls , data = d1 ) <EOL> w . viewer_size = ( <NUM_LIT> , <NUM_LIT> ) <EOL> filename = tmpdir . join ( '<STR_LIT>' ) . strpath <EOL> app . save_session ( filename , include_data = True ) <EOL> app2 = GlueApplication . restore_session ( filename ) <EOL> for viewer in app2 . viewers : <EOL> assert viewer [ <NUM_LIT:0> ] . viewer_size == ( <NUM_LIT> , <NUM_LIT> ) <EOL> app . close ( ) <EOL> app2 . close ( ) <EOL> class TestDataViewerScatter ( BaseTestDataViewer ) : <EOL> widget_cls = ScatterWidget <EOL> class TestDataViewerImage ( BaseTestDataViewer ) : <EOL> ndim = <NUM_LIT:2> <EOL> widget_cls = ImageWidget <EOL> class TestDataViewerHistogram ( BaseTestDataViewer ) : <EOL> widget_cls = HistogramWidget </s>
