<s> from anima . env import empty_reference_resolution <EOL> from anima . env . base import EnvironmentBase <EOL> from anima . testing import count_calls <EOL> class TestEnvironment ( EnvironmentBase ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> representations = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> test_data = { } <EOL> def __init__ ( self , name = '<STR_LIT>' ) : <EOL> EnvironmentBase . __init__ ( self , name = name ) <EOL> for f in dir ( self ) : <EOL> if callable ( f ) : <EOL> self . test_data [ f . __name__ ] = { "<STR_LIT>" : <NUM_LIT:0> , "<STR_LIT:data>" : None } <EOL> self . _version = None <EOL> @ count_calls <EOL> def export_as ( self , version ) : <EOL> pass <EOL> @ count_calls <EOL> def save_as ( self , version ) : <EOL> pass <EOL> @ count_calls <EOL> def open ( self , version , force = False , representation = None , <EOL> reference_depth = <NUM_LIT:0> , skip_update_check = False ) : <EOL> self . _version = version <EOL> return self . check_referenced_versions ( ) <EOL> @ count_calls <EOL> def reference ( self , version ) : <EOL> pass <EOL> @ count_calls <EOL> def import_ ( self , version ) : <EOL> pass <EOL> @ count_calls <EOL> def get_last_version ( self ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> @ count_calls <EOL> def get_current_version ( self ) : <EOL> return self . _version <EOL> @ count_calls <EOL> def get_referenced_versions ( self ) : <EOL> return self . _version . inputs <EOL> @ count_calls <EOL> def check_referenced_versions ( self ) : <EOL> """<STR_LIT>""" <EOL> dfs_version_references = [ ] <EOL> version = self . get_current_version ( ) <EOL> resolution_dictionary = empty_reference_resolution ( <EOL> root = self . get_referenced_versions ( ) <EOL> ) <EOL> for v in version . walk_hierarchy ( ) : <EOL> dfs_version_references . append ( v ) <EOL> dfs_version_references . pop ( <NUM_LIT:0> ) <EOL> for v in reversed ( dfs_version_references ) : <EOL> to_be_updated_list = [ ] <EOL> for ref_v in v . inputs : <EOL> if not ref_v . is_latest_published_version ( ) : <EOL> to_be_updated_list . append ( ref_v ) <EOL> if to_be_updated_list : <EOL> action = '<STR_LIT>' <EOL> latest_published_version = v . latest_published_version <EOL> if latest_published_version and not v . is_latest_published_version ( ) : <EOL> if all ( [ ref_v . latest_published_version <EOL> in latest_published_version . inputs <EOL> for ref_v in to_be_updated_list ] ) : <EOL> action = '<STR_LIT>' <EOL> else : <EOL> action = '<STR_LIT>' <EOL> else : <EOL> if v . is_latest_published_version ( ) : <EOL> action = '<STR_LIT>' <EOL> else : <EOL> action = '<STR_LIT>' <EOL> if any ( rev_v in resolution_dictionary [ '<STR_LIT>' ] or <EOL> rev_v in resolution_dictionary [ '<STR_LIT>' ] <EOL> for rev_v in v . inputs ) : <EOL> action = '<STR_LIT>' <EOL> resolution_dictionary [ action ] . append ( v ) <EOL> return resolution_dictionary <EOL> @ count_calls <EOL> def update_first_level_versions ( self , reference_resolution ) : <EOL> """<STR_LIT>""" <EOL> latest = [ ] <EOL> for version in self . _version . inputs : <EOL> latest_published_version = version . latest_published_version <EOL> latest . append ( latest_published_version ) <EOL> self . _version . inputs = latest <EOL> @ count_calls <EOL> def update_versions ( self , reference_resolution ) : <EOL> """<STR_LIT>""" <EOL> new_versions = [ ] <EOL> from stalker import Version <EOL> current_version = self . get_current_version ( ) <EOL> for version in reference_resolution [ '<STR_LIT>' ] : <EOL> local_reference_resolution = self . open ( version , force = True ) <EOL> new_version = Version ( <EOL> task = version . task , <EOL> take_name = version . take_name , <EOL> parent = version , <EOL> description = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> new_version . is_published = True <EOL> for v in self . _version . inputs : <EOL> new_version . inputs . append ( v . latest_published_version ) <EOL> new_versions . append ( new_version ) <EOL> current_version_after_create = self . get_current_version ( ) <EOL> if current_version : <EOL> if current_version != current_version_after_create : <EOL> self . open ( current_version ) <EOL> reference_resolution [ '<STR_LIT>' ] . extend ( <EOL> reference_resolution [ '<STR_LIT>' ] <EOL> ) <EOL> self . update_first_level_versions ( reference_resolution ) <EOL> return new_versions </s>
