<s> from __future__ import division <EOL> import urllib <EOL> from vistrails . core . mashup import conv_from_bool , conv_to_bool , convert_symbols <EOL> from vistrails . db . domain import DBMashupComponent <EOL> import unittest <EOL> from vistrails . db . domain import IdScope <EOL> import copy <EOL> class Component ( DBMashupComponent ) : <EOL> def __init__ ( self , id , vttype , param_id , parent_vttype , parent_id , mid , <EOL> type , value , p_pos , pos , strvaluelist , minVal = "<STR_LIT:0>" , <EOL> maxVal = "<STR_LIT:1>" , stepSize = "<STR_LIT:1>" , parent = '<STR_LIT>' , seq = <NUM_LIT:0> , widget = "<STR_LIT:text>" ) : <EOL> """<STR_LIT>""" <EOL> DBMashupComponent . __init__ ( self , id , param_id , vttype , parent_vttype , <EOL> parent_id , p_pos , mid , pos , type , value , <EOL> minVal , maxVal , stepSize , strvaluelist , <EOL> widget , seq , parent ) <EOL> if isinstance ( seq , bool ) : <EOL> self . seq = seq <EOL> id = DBMashupComponent . db_id <EOL> vttype = DBMashupComponent . db_vttype <EOL> vtid = DBMashupComponent . db_vtid <EOL> vtparent_type = DBMashupComponent . db_vtparent_type <EOL> vtparent_id = DBMashupComponent . db_vtparent_id <EOL> vtmid = DBMashupComponent . db_vtmid <EOL> vtpos = DBMashupComponent . db_vtpos <EOL> pos = DBMashupComponent . db_pos <EOL> type = DBMashupComponent . db_type <EOL> minVal = DBMashupComponent . db_minVal <EOL> maxVal = DBMashupComponent . db_maxVal <EOL> stepSize = DBMashupComponent . db_stepSize <EOL> parent = DBMashupComponent . db_parent <EOL> widget = DBMashupComponent . db_widget <EOL> strvaluelist = DBMashupComponent . db_strvaluelist <EOL> def _get_seq ( self ) : <EOL> return conv_to_bool ( self . db_seq ) <EOL> def _set_seq ( self , s ) : <EOL> self . db_seq = conv_from_bool ( s ) <EOL> seq = property ( _get_seq , _set_seq ) <EOL> def _get_val ( self ) : <EOL> self . db_val = convert_symbols ( self . db_val ) <EOL> return self . db_val <EOL> def _set_val ( self , v ) : <EOL> self . db_val = v <EOL> val = property ( _get_val , _set_val ) <EOL> def _get_valuelist ( self ) : <EOL> self . strvaluelist = convert_symbols ( self . strvaluelist ) <EOL> data = self . strvaluelist . split ( '<STR_LIT:U+002C>' ) <EOL> result = [ ] <EOL> for d in data : <EOL> result . append ( urllib . unquote_plus ( d ) ) <EOL> return result <EOL> def _set_valuelist ( self , valuelist ) : <EOL> q = [ ] <EOL> for v in valuelist : <EOL> q . append ( urllib . quote_plus ( v ) ) <EOL> self . strvaluelist = "<STR_LIT:U+002C>" . join ( q ) <EOL> valueList = property ( _get_valuelist , _set_valuelist ) <EOL> @ staticmethod <EOL> def convert ( _component ) : <EOL> _component . __class__ = Component <EOL> def __copy__ ( self ) : <EOL> return Component . do_copy ( self ) <EOL> def do_copy ( self , new_ids = False , id_scope = None , id_remap = None ) : <EOL> """<STR_LIT>""" <EOL> cp = DBMashupComponent . do_copy ( self , new_ids , id_scope , id_remap ) <EOL> Component . convert ( cp ) <EOL> return cp <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( "<STR_LIT>" % <EOL> ( self . id , <EOL> self . vttype , <EOL> self . vtid , <EOL> self . vtparent_type , <EOL> self . vtparent_id , <EOL> self . vtmid , <EOL> self . vtpos , <EOL> self . type , <EOL> self . pos , <EOL> self . val , <EOL> self . minVal , <EOL> self . maxVal , <EOL> self . stepSize , <EOL> self . strvaluelist , <EOL> self . parent , <EOL> self . seq , <EOL> self . widget , <EOL> id ( self ) ) ) <EOL> def __eq__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if type ( self ) != type ( other ) : <EOL> return False <EOL> if self . vttype != other . vttype : <EOL> return False <EOL> if self . vtid != other . vtid : <EOL> return False <EOL> if self . vtparent_type != other . vtparent_type : <EOL> return False <EOL> if self . vtparent_id != other . vtparent_id : <EOL> return False <EOL> if self . vtmid != other . vtmid : <EOL> return False <EOL> if self . vtpos != other . vtpos : <EOL> return False <EOL> if self . type != other . type : <EOL> return False <EOL> if self . pos != other . pos : <EOL> return False <EOL> if self . val != other . val : <EOL> return False <EOL> if self . minVal != other . minVal : <EOL> return False <EOL> if self . maxVal != other . maxVal : <EOL> return False <EOL> if self . stepSize != other . stepSize : <EOL> return False <EOL> if self . strvaluelist != other . strvaluelist : <EOL> return False <EOL> if self . parent != other . parent : <EOL> return False <EOL> if self . seq != other . seq : <EOL> return False <EOL> if self . widget != other . widget : <EOL> return False <EOL> return True <EOL> def __ne__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return not self . __eq__ ( other ) <EOL> class TestComponent ( unittest . TestCase ) : <EOL> def create_component ( self , id_scope = IdScope ( ) ) : <EOL> c = Component ( id = id_scope . getNewId ( '<STR_LIT>' ) , <EOL> vttype = '<STR_LIT>' , param_id = <NUM_LIT:15> L , <EOL> parent_vttype = '<STR_LIT>' , parent_id = <NUM_LIT:3> L , mid = <NUM_LIT:4> L , <EOL> type = '<STR_LIT>' , value = '<STR_LIT:test>' , p_pos = <NUM_LIT:0> , pos = <NUM_LIT:1> , <EOL> strvaluelist = '<STR_LIT>' , widget = "<STR_LIT:text>" ) <EOL> return c <EOL> def test_copy ( self ) : <EOL> id_scope = IdScope ( ) <EOL> c1 = self . create_component ( id_scope ) <EOL> c2 = copy . copy ( c1 ) <EOL> self . assertEqual ( c1 , c2 ) <EOL> self . assertEqual ( c1 . id , c2 . id ) <EOL> c3 = c2 . do_copy ( True , id_scope , { } ) <EOL> self . assertEqual ( c1 , c3 ) <EOL> self . assertNotEqual ( c1 . id , c3 . id ) <EOL> def test_valuelist ( self ) : <EOL> c1 = self . create_component ( ) <EOL> c1 . strvaluelist = "<STR_LIT>" <EOL> self . assertEqual ( [ '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:3>' ] , c1 . valueList ) <EOL> c1 . valueList = [ '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:3>' ] <EOL> self . assertEqual ( c1 . strvaluelist , "<STR_LIT>" ) <EOL> def test_str ( self ) : <EOL> c1 = self . create_component ( ) <EOL> str ( c1 ) </s>
