<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> import unittest <EOL> from vistrails . core . cache . utils import hash_list <EOL> try : <EOL> import hashlib <EOL> sha_hash = hashlib . sha1 <EOL> except ImportError : <EOL> import sha <EOL> sha_hash = sha . new <EOL> class Hasher ( object ) : <EOL> @ staticmethod <EOL> def parameter_signature ( p , constant_hasher_map = { } ) : <EOL> k = ( p . identifier , p . type , p . namespace ) <EOL> custom_hasher = constant_hasher_map . get ( k , None ) <EOL> if custom_hasher : <EOL> return custom_hasher ( p ) <EOL> else : <EOL> hasher = sha_hash ( ) <EOL> u = hasher . update <EOL> u ( p . type ) <EOL> u ( p . identifier ) <EOL> u ( p . namespace or "<STR_LIT>" ) <EOL> u ( p . strValue ) <EOL> u ( p . name ) <EOL> u ( p . evaluatedStrValue ) <EOL> return hasher . digest ( ) <EOL> @ staticmethod <EOL> def function_signature ( function , constant_hasher_map = { } ) : <EOL> hasher = sha_hash ( ) <EOL> u = hasher . update <EOL> u ( function . name ) <EOL> u ( function . returnType ) <EOL> u ( hash_list ( function . params , <EOL> Hasher . parameter_signature , <EOL> constant_hasher_map ) ) <EOL> return hasher . digest ( ) <EOL> @ staticmethod <EOL> def control_param_signature ( control_param , constant_hasher_map = { } ) : <EOL> hasher = sha_hash ( ) <EOL> u = hasher . update <EOL> u ( control_param . name ) <EOL> u ( control_param . value ) <EOL> return hasher . digest ( ) <EOL> @ staticmethod <EOL> def connection_signature ( c ) : <EOL> hasher = sha_hash ( ) <EOL> u = hasher . update <EOL> u ( c . source . name ) <EOL> u ( c . destination . name ) <EOL> return hasher . digest ( ) <EOL> @ staticmethod <EOL> def port_spec_signature ( ps , constant_hasher_map = { } ) : <EOL> hasher = sha_hash ( ) <EOL> u = hasher . update <EOL> u ( ps . type ) <EOL> u ( ps . name ) <EOL> u ( ps . sigstring ) <EOL> u ( '<STR_LIT>' % ps . depth ) <EOL> return hasher . digest ( ) <EOL> @ staticmethod <EOL> def connection_subpipeline_signature ( c , source_sig , dest_sig ) : <EOL> """<STR_LIT>""" <EOL> hasher = sha_hash ( ) <EOL> u = hasher . update <EOL> u ( Hasher . connection_signature ( c ) ) <EOL> u ( source_sig ) <EOL> u ( dest_sig ) <EOL> return hasher . digest ( ) <EOL> @ staticmethod <EOL> def module_signature ( obj , constant_hasher_map = { } ) : <EOL> hasher = sha_hash ( ) <EOL> u = hasher . update <EOL> u ( obj . module_descriptor . name ) <EOL> u ( obj . module_descriptor . package ) <EOL> u ( obj . module_descriptor . namespace or '<STR_LIT>' ) <EOL> u ( obj . module_descriptor . package_version or '<STR_LIT>' ) <EOL> u ( obj . module_descriptor . version or '<STR_LIT>' ) <EOL> u ( hash_list ( obj . functions , Hasher . function_signature , <EOL> constant_hasher_map ) ) <EOL> u ( hash_list ( obj . control_parameters , Hasher . control_param_signature , <EOL> constant_hasher_map ) ) <EOL> u ( hash_list ( obj . port_spec_list , Hasher . port_spec_signature , <EOL> constant_hasher_map ) ) <EOL> return hasher . digest ( ) <EOL> @ staticmethod <EOL> def subpipeline_signature ( module_sig , upstream_sigs ) : <EOL> """<STR_LIT>""" <EOL> hasher = sha_hash ( ) <EOL> hasher . update ( module_sig ) <EOL> upstream_sigs . sort ( ) <EOL> for pipeline_connection_sig in upstream_sigs : <EOL> hasher . update ( pipeline_connection_sig ) <EOL> return hasher . digest ( ) <EOL> @ staticmethod <EOL> def compound_signature ( sig_list ) : <EOL> """<STR_LIT>""" <EOL> hasher = sha_hash ( ) <EOL> for h in sorted ( sig_list ) : <EOL> hasher . update ( h ) <EOL> return hasher . digest ( ) <EOL> class TestCacheHash ( unittest . TestCase ) : <EOL> def test_outputportspec_cache ( self ) : <EOL> """<STR_LIT>""" <EOL> from vistrails import api <EOL> from vistrails . core . vistrail . port_spec import PortSpec <EOL> api . new_vistrail ( ) <EOL> c = api . get_current_controller ( ) <EOL> ps = api . add_module ( <NUM_LIT:0> , <NUM_LIT:0> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> api . change_parameter ( ps . id , '<STR_LIT:source>' , [ '<STR_LIT>' ] ) <EOL> so = api . add_module ( <NUM_LIT:0> , <NUM_LIT:0> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> api . add_port_spec ( ps . id , PortSpec ( name = '<STR_LIT:a>' , type = '<STR_LIT>' , sigstring = '<STR_LIT>' ) ) <EOL> api . add_connection ( ps . id , '<STR_LIT:a>' , so . id , '<STR_LIT:value>' ) <EOL> self . assertEqual ( c . execute_current_workflow ( ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . errors , { } ) <EOL> api . add_port_spec ( ps . id , PortSpec ( name = '<STR_LIT:b>' , type = '<STR_LIT>' , sigstring = '<STR_LIT>' ) ) <EOL> api . add_connection ( ps . id , '<STR_LIT:b>' , so . id , '<STR_LIT:value>' ) <EOL> self . assertEqual ( c . execute_current_workflow ( ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . errors , { } ) </s>
