<s> from __future__ import absolute_import , division , print_function <EOL> import pytest <EOL> from mock import MagicMock <EOL> from glue . core import ComponentID <EOL> from glue . config import link_function , link_helper <EOL> from . . link_equation import ( function_label , helper_label , <EOL> LinkEquation , ArgumentWidget ) <EOL> @ link_function ( '<STR_LIT>' , [ '<STR_LIT:y>' ] ) <EOL> def func1 ( x ) : <EOL> return x <EOL> @ link_function ( '<STR_LIT>' , [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> def func2 ( x , z ) : <EOL> return x + z , x - z <EOL> @ link_helper ( '<STR_LIT>' , [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> def helper ( x , y ) : <EOL> return [ x , x , y ] <EOL> def test_function_label ( ) : <EOL> f1 = [ f for f in link_function if f [ <NUM_LIT:0> ] is func1 ] [ <NUM_LIT:0> ] <EOL> f2 = [ f for f in link_function if f [ <NUM_LIT:0> ] is func2 ] [ <NUM_LIT:0> ] <EOL> assert function_label ( f1 ) == "<STR_LIT>" <EOL> assert function_label ( f2 ) == "<STR_LIT>" <EOL> def test_helper_label ( ) : <EOL> f1 = [ h for h in link_helper if h [ <NUM_LIT:0> ] is helper ] [ <NUM_LIT:0> ] <EOL> assert helper_label ( f1 ) == '<STR_LIT>' <EOL> class TestArgumentWidget ( object ) : <EOL> def test_label ( self ) : <EOL> a = ArgumentWidget ( '<STR_LIT:test>' ) <EOL> assert a . label == '<STR_LIT:test>' <EOL> def test_set_label ( self ) : <EOL> a = ArgumentWidget ( '<STR_LIT:test>' ) <EOL> a . label = '<STR_LIT:b>' <EOL> assert a . label == '<STR_LIT:b>' <EOL> def test_drop ( self ) : <EOL> target_id = ComponentID ( '<STR_LIT:test>' ) <EOL> event = MagicMock ( ) <EOL> event . mimeData ( ) . data . return_value = target_id <EOL> a = ArgumentWidget ( '<STR_LIT:test>' ) <EOL> a . dropEvent ( event ) <EOL> assert a . component_id is target_id <EOL> assert a . editor_text == '<STR_LIT:test>' <EOL> def test_drop_invalid ( self ) : <EOL> event = MagicMock ( ) <EOL> event . mimeData ( ) . data . return_value = <NUM_LIT:5> <EOL> a = ArgumentWidget ( '<STR_LIT>' ) <EOL> a . dropEvent ( event ) <EOL> assert a . component_id is None <EOL> def test_clear ( self ) : <EOL> target_id = ComponentID ( '<STR_LIT:test>' ) <EOL> event = MagicMock ( ) <EOL> event . mimeData ( ) . data . return_value = target_id <EOL> a = ArgumentWidget ( '<STR_LIT:test>' ) <EOL> a . dropEvent ( event ) <EOL> assert a . component_id is target_id <EOL> a . clear ( ) <EOL> assert a . component_id is None <EOL> assert a . editor_text == '<STR_LIT>' <EOL> def test_drag_enter_accept ( self ) : <EOL> event = MagicMock ( ) <EOL> event . mimeData ( ) . hasFormat . return_value = True <EOL> a = ArgumentWidget ( '<STR_LIT:x>' ) <EOL> a . dragEnterEvent ( event ) <EOL> event . accept . assert_called_once_with ( ) <EOL> def test_drag_enter_ignore ( self ) : <EOL> event = MagicMock ( ) <EOL> event . mimeData ( ) . hasFormat . return_value = False <EOL> a = ArgumentWidget ( '<STR_LIT:x>' ) <EOL> a . dragEnterEvent ( event ) <EOL> event . ignore . assert_called_once_with ( ) <EOL> class TestLinkEquation ( object ) : <EOL> def setup_method ( self , method ) : <EOL> self . widget = LinkEquation ( ) <EOL> def test_select_function_member ( self ) : <EOL> member = link_function . members [ <NUM_LIT:1> ] <EOL> assert self . widget . function is not member <EOL> self . widget . function = member <EOL> assert self . widget . function is member <EOL> def test_select_function_helper ( self ) : <EOL> member = link_helper . members [ - <NUM_LIT:1> ] <EOL> self . widget . function = member <EOL> assert self . widget . function is member <EOL> def test_select_invalid_function ( self ) : <EOL> with pytest . raises ( KeyError ) as exc : <EOL> def bad ( x ) : <EOL> pass <EOL> self . widget . function = ( bad , None , None ) <EOL> assert exc . value . args [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) <EOL> def test_make_link_function ( self ) : <EOL> widget = LinkEquation ( ) <EOL> f1 = [ f for f in link_function if f [ <NUM_LIT:0> ] is func1 ] [ <NUM_LIT:0> ] <EOL> widget . function = f1 <EOL> x , y = ComponentID ( '<STR_LIT:x>' ) , ComponentID ( '<STR_LIT:y>' ) <EOL> widget . signature = [ x ] , y <EOL> links = widget . links ( ) <EOL> assert len ( links ) == <NUM_LIT:1> <EOL> assert links [ <NUM_LIT:0> ] . get_from_ids ( ) == [ x ] <EOL> assert links [ <NUM_LIT:0> ] . get_to_id ( ) == y <EOL> assert links [ <NUM_LIT:0> ] . get_using ( ) is func1 <EOL> def test_make_link_helper ( self ) : <EOL> widget = LinkEquation ( ) <EOL> f1 = [ f for f in link_helper if f [ <NUM_LIT:0> ] is helper ] [ <NUM_LIT:0> ] <EOL> widget . function = f1 <EOL> x , y = ComponentID ( '<STR_LIT:x>' ) , ComponentID ( '<STR_LIT:y>' ) <EOL> widget . signature = [ x , y ] , None <EOL> links = widget . links ( ) <EOL> assert links == helper ( x , y ) <EOL> def test_links_empty ( self ) : <EOL> assert LinkEquation ( ) . links ( ) == [ ] <EOL> def test_links_empty_helper ( self ) : <EOL> widget = LinkEquation ( ) <EOL> f1 = [ f for f in link_helper if f [ <NUM_LIT:0> ] is helper ] [ <NUM_LIT:0> ] <EOL> widget . function = f1 <EOL> assert widget . is_helper ( ) <EOL> assert widget . links ( ) == [ ] <EOL> def test_clear_inputs ( self ) : <EOL> widget = LinkEquation ( ) <EOL> f1 = [ f for f in link_helper if f [ <NUM_LIT:0> ] is helper ] [ <NUM_LIT:0> ] <EOL> widget . function = f1 <EOL> x , y = ComponentID ( '<STR_LIT:x>' ) , ComponentID ( '<STR_LIT:y>' ) <EOL> widget . signature = [ x , y ] , None <EOL> assert widget . signature == ( [ x , y ] , None ) <EOL> widget . clear_inputs ( ) <EOL> assert widget . signature == ( [ None , None ] , None ) <EOL> def test_signal_connections ( self ) : <EOL> widget = LinkEquation ( ) <EOL> signal = widget . _ui . function . currentIndexChanged <EOL> signal . emit ( <NUM_LIT:5> ) <EOL> signal = widget . _output_widget . editor . textChanged <EOL> signal . emit ( '<STR_LIT>' ) </s>
