<s> import shutil <EOL> import tempfile <EOL> import unittest <EOL> import os <EOL> from stalker import ( db , User , Repository , Status , FilenameTemplate , Structure , <EOL> StatusList , ImageFormat , Project , Type , Task , Version ) <EOL> from anima . repr import Representation <EOL> class RepresentationTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> temp_repo_path = '<STR_LIT>' <EOL> remove_these_files_buffer = [ ] <EOL> @ classmethod <EOL> def create_version ( cls , task , take_name ) : <EOL> """<STR_LIT>""" <EOL> v = Version ( task = task , take_name = take_name ) <EOL> db . DBSession . add ( v ) <EOL> db . DBSession . commit ( ) <EOL> return v <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> """<STR_LIT>""" <EOL> database_url = "<STR_LIT>" <EOL> db . setup ( { '<STR_LIT>' : database_url } ) <EOL> db . init ( ) <EOL> cls . temp_repo_path = tempfile . mkdtemp ( ) <EOL> cls . user1 = User ( <EOL> name = '<STR_LIT>' , <EOL> login = '<STR_LIT>' , <EOL> email = '<STR_LIT>' , <EOL> password = '<STR_LIT>' <EOL> ) <EOL> cls . repo1 = Repository ( <EOL> name = '<STR_LIT>' , <EOL> linux_path = cls . temp_repo_path , <EOL> windows_path = cls . temp_repo_path , <EOL> osx_path = cls . temp_repo_path <EOL> ) <EOL> cls . status_new = Status . query . filter_by ( code = '<STR_LIT>' ) . first ( ) <EOL> cls . status_wip = Status . query . filter_by ( code = '<STR_LIT>' ) . first ( ) <EOL> cls . status_comp = Status . query . filter_by ( code = '<STR_LIT>' ) . first ( ) <EOL> cls . task_template = FilenameTemplate ( <EOL> name = '<STR_LIT>' , <EOL> target_entity_type = '<STR_LIT>' , <EOL> path = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> filename = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ) <EOL> cls . structure = Structure ( <EOL> name = '<STR_LIT>' , <EOL> templates = [ cls . task_template ] <EOL> ) <EOL> cls . project_status_list = StatusList ( <EOL> name = '<STR_LIT>' , <EOL> target_entity_type = '<STR_LIT>' , <EOL> statuses = [ cls . status_new , cls . status_wip , cls . status_comp ] <EOL> ) <EOL> cls . image_format = ImageFormat ( <EOL> name = '<STR_LIT>' , <EOL> width = <NUM_LIT> , <EOL> height = <NUM_LIT> , <EOL> pixel_aspect = <NUM_LIT:1.0> <EOL> ) <EOL> cls . project = Project ( <EOL> name = '<STR_LIT>' , <EOL> code = '<STR_LIT>' , <EOL> repository = cls . repo1 , <EOL> status_list = cls . project_status_list , <EOL> structure = cls . structure , <EOL> image_format = cls . image_format <EOL> ) <EOL> cls . task_status_list = StatusList . query . filter_by ( target_entity_type = '<STR_LIT>' ) . first ( ) <EOL> cls . character_type = Type ( <EOL> name = '<STR_LIT>' , <EOL> code = '<STR_LIT>' , <EOL> target_entity_type = '<STR_LIT>' <EOL> ) <EOL> cls . task1 = Task ( <EOL> name = '<STR_LIT>' , <EOL> project = cls . project <EOL> ) <EOL> cls . task2 = Task ( <EOL> name = '<STR_LIT>' , <EOL> project = cls . project <EOL> ) <EOL> db . DBSession . add_all ( [ <EOL> cls . repo1 , cls . status_new , cls . status_wip , cls . status_comp , <EOL> cls . project_status_list , cls . project , cls . task_status_list , <EOL> cls . task1 , cls . task2 , cls . task_template <EOL> ] ) <EOL> db . DBSession . commit ( ) <EOL> cls . version1 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version2 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version3 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version4 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version5 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version5 . is_published = True <EOL> db . DBSession . commit ( ) <EOL> cls . version6 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version7 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version7 . is_published = True <EOL> db . DBSession . commit ( ) <EOL> cls . version8 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version9 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version10 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version11 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version12 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version13 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version14 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version15 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version16 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version17 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version17 . is_published = True <EOL> cls . version18 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> cls . version19 = cls . create_version ( cls . task1 , '<STR_LIT>' ) <EOL> db . DBSession . commit ( ) <EOL> cls . remove_these_files_buffer = [ ] <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> """<STR_LIT>""" <EOL> db . DBSession . remove ( ) <EOL> shutil . rmtree ( cls . temp_repo_path , ignore_errors = True ) <EOL> for f in cls . remove_these_files_buffer : <EOL> if os . path . isfile ( f ) : <EOL> os . remove ( f ) <EOL> elif os . path . isdir ( f ) : <EOL> shutil . rmtree ( f , True ) <EOL> def test_list_all_lists_all_representations ( self ) : <EOL> """<STR_LIT>""" <EOL> expected_result = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> rep = Representation ( self . version1 ) <EOL> result = rep . list_all ( ) <EOL> self . assertEqual ( sorted ( expected_result ) , sorted ( result ) ) <EOL> def test_list_all_lists_all_representations_from_non_base_version ( self ) : <EOL> """<STR_LIT>""" <EOL> expected_result = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> rep = Representation ( self . version10 ) <EOL> result = rep . list_all ( ) <EOL> self . assertEqual ( sorted ( expected_result ) , sorted ( result ) ) <EOL> def test_find_method_finds_the_given_representation ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( self . version1 ) <EOL> result = rep . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( self . version5 , result ) <EOL> def test_find_method_finds_the_given_repr_from_different_repr ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( self . version4 ) <EOL> result = rep . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( self . version7 , result ) <EOL> def test_find_method_returns_none_for_invalid_repr_name ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( self . version4 ) <EOL> self . assertTrue ( rep . find ( '<STR_LIT>' ) is None ) <EOL> def test_has_any_repr_method_is_working_properly ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( self . version1 ) <EOL> self . assertTrue ( rep . has_any_repr ( ) ) <EOL> rep . version = self . version17 <EOL> self . assertTrue ( rep . has_any_repr ( ) ) <EOL> rep . version = self . version19 <EOL> self . assertFalse ( rep . has_any_repr ( ) ) <EOL> def test_has_repr_method_is_working_properly ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( self . version1 ) <EOL> self . assertTrue ( rep . has_repr ( '<STR_LIT>' ) ) <EOL> rep . version = self . version17 <EOL> self . assertTrue ( rep . has_repr ( '<STR_LIT>' ) ) <EOL> rep . version = self . version19 <EOL> self . assertFalse ( rep . has_repr ( '<STR_LIT>' ) ) <EOL> def test_get_base_take_name_is_working_properly ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( ) <EOL> self . assertEqual ( '<STR_LIT>' , rep . get_base_take_name ( self . version1 ) ) <EOL> self . assertEqual ( '<STR_LIT>' , rep . get_base_take_name ( self . version10 ) ) <EOL> self . assertEqual ( '<STR_LIT>' , rep . get_base_take_name ( self . version12 ) ) <EOL> self . assertEqual ( '<STR_LIT>' , rep . get_base_take_name ( self . version18 ) ) <EOL> def test_version_argument_is_skipped ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( ) <EOL> self . assertTrue ( rep . version is None ) <EOL> def test_version_argument_is_none ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( None ) <EOL> self . assertTrue ( rep . version is None ) <EOL> def test_version_attribute_is_set_to_none ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( self . version1 ) <EOL> self . assertFalse ( rep . version is None ) <EOL> rep . version = None <EOL> self . assertTrue ( rep . version is None ) <EOL> def test_version_argument_is_not_a_version_instance ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( TypeError ) as cm : <EOL> Representation ( '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> str ( cm . exception ) <EOL> ) <EOL> def test_version_attribute_is_not_a_version_instance ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( ) <EOL> with self . assertRaises ( TypeError ) as cm : <EOL> rep . version = '<STR_LIT>' <EOL> self . assertEqual ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> str ( cm . exception ) <EOL> ) <EOL> def test_version_argument_is_working_properly ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( self . version1 ) <EOL> self . assertEqual ( rep . version , self . version1 ) <EOL> def test_version_attribute_is_working_properly ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( self . version1 ) <EOL> self . assertNotEqual ( rep . version , self . version2 ) <EOL> rep . version = self . version2 <EOL> self . assertEqual ( rep . version , self . version2 ) <EOL> def test_is_base_method_is_working_properly ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( self . version1 ) <EOL> self . assertTrue ( rep . is_base ( ) ) <EOL> rep = Representation ( self . version4 ) <EOL> self . assertFalse ( rep . is_base ( ) ) <EOL> def test_is_repr_method_is_working_properly ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( self . version1 ) <EOL> self . assertTrue ( rep . is_repr ( '<STR_LIT>' ) ) <EOL> rep = Representation ( self . version4 ) <EOL> self . assertFalse ( rep . is_repr ( '<STR_LIT>' ) ) <EOL> rep = Representation ( self . version4 ) <EOL> self . assertTrue ( rep . is_repr ( '<STR_LIT>' ) ) <EOL> def test_repr_property_is_working_properly ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = Representation ( self . version1 ) <EOL> self . assertEqual ( rep . repr , '<STR_LIT>' ) <EOL> rep = Representation ( self . version4 ) <EOL> self . assertTrue ( rep . repr , '<STR_LIT>' ) </s>
