def test_save_as_replaces_file_image_paths(self): """testing if save_as method replaces image paths with REPO relative path """ self.mEnv.save_as(self.version1) # create file node file_node = pm.createNode("file") # set it to a path in the workspace texture_path = os.path.join(pm.workspace.path, ".maya_files/textures/test.jpg") file_node.fileTextureName.set(texture_path) # save a newer version version2 = Version(**self.kwargs) version2.save() self.mEnv.save_as(version2) # now check if the file nodes fileTextureName is converted to a # relative path to the current workspace expected_path = texture_path.replace(os.environ["REPO"], "$REPO") self.assertEqual(file_node.getAttr("fileTextureName"), expected_path)
def test_save_as_replaces_file_image_paths(self): """testing if save_as method replaces image paths with REPO relative path """ self.mEnv.save_as(self.version1) # create file node file_node = pm.createNode("file") # set it to a path in the workspace texture_path = os.path.join( pm.workspace.path, ".maya_files/textures/test.jpg" ) file_node.fileTextureName.set(texture_path) # save a newer version version2 = Version(**self.kwargs) version2.save() self.mEnv.save_as(version2) # now check if the file nodes fileTextureName is converted to a # relative path to the current workspace expected_path = texture_path.replace(os.environ["REPO"], "$REPO") self.assertEqual( file_node.getAttr("fileTextureName"), expected_path )
def test_save_as_references_to_a_version_in_same_workspace_are_replaced_with_abs_path_with_env_variable(self): """testing if the save_as method updates the references paths with an absolute path starting with conf.repository_env_key for references to a version in the same project thus the referenced path is relative """ # create project proj1 = Project("Proj1") proj1.save() proj1.create() # create assets asset1 = Asset(proj1, "Asset 1") asset1.save() # create a version of asset vtype vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers1.save() # save it self.mEnv.save_as(vers1) # new scene pm.newFile(force=True) # create another version with different type vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1) vers2.save() # reference the other version self.mEnv.reference(vers1) # save it self.mEnv.save_as(vers2) # now check if the referenced vers1 starts with $REPO refs = pm.listReferences() # there should be only one ref self.assertTrue(len(refs)==1) # and the path should start with conf.repository_env_key self.assertTrue( refs[0].unresolvedPath().startswith("$" + conf.repository_env_key) )
def test_save_as_references_to_a_version_in_same_workspace_are_replaced_with_abs_path_with_env_variable( self): """testing if the save_as method updates the references paths with an absolute path starting with conf.repository_env_key for references to a version in the same project thus the referenced path is relative """ # create project proj1 = Project("Proj1") proj1.save() proj1.create() # create assets asset1 = Asset(proj1, "Asset 1") asset1.save() # create a version of asset vtype vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers1.save() # save it self.mEnv.save_as(vers1) # new scene pm.newFile(force=True) # create another version with different type vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1) vers2.save() # reference the other version self.mEnv.reference(vers1) # save it self.mEnv.save_as(vers2) # now check if the referenced vers1 starts with $REPO refs = pm.listReferences() # there should be only one ref self.assertTrue(len(refs) == 1) # and the path should start with conf.repository_env_key self.assertTrue( refs[0].unresolvedPath().startswith("$" + conf.repository_env_key))
def test_open_loads_the_references(self): """testing if the open method loads the references """ # create a couple of versions and reference them to each other # and reference them to the the scene and check if maya updates the # Version.references list versionBase = Version(**self.kwargs) versionBase.save() # change the take naem self.kwargs["take_name"] = "Take1" version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "Take2" version2 = Version(**self.kwargs) version2.save() self.kwargs["take_name"] = "Take3" version3 = Version(**self.kwargs) version3.save() # now create scenes with these files self.mEnv.save_as(version1) self.mEnv.save_as(version2) self.mEnv.save_as(version3) # this is the dummy version # create a new scene pm.newFile(force=True) # check if the versionBase.references is an empty list self.assertTrue(versionBase.references == []) # reference the given versions self.mEnv.reference(version1) self.mEnv.reference(version2) # save it as versionBase self.mEnv.save_as(versionBase) # clean scene pm.newFile(force=True) # re-open the file self.mEnv.open_(versionBase, force=True) self.mEnv.post_open(versionBase) # check if the references are loaded ref_data = self.mEnv.get_referenced_versions() for data in ref_data: ref_node = data[1] self.assertTrue(ref_node.isLoaded())
def test_open_loads_the_references(self): """testing if the open method loads the references """ # create a couple of versions and reference them to each other # and reference them to the the scene and check if maya updates the # Version.references list versionBase = Version(**self.kwargs) versionBase.save() # change the take naem self.kwargs["take_name"] = "Take1" version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "Take2" version2 = Version(**self.kwargs) version2.save() self.kwargs["take_name"] = "Take3" version3 = Version(**self.kwargs) version3.save() # now create scenes with these files self.mEnv.save_as(version1) self.mEnv.save_as(version2) self.mEnv.save_as(version3) # this is the dummy version # create a new scene pm.newFile(force=True) # check if the versionBase.references is an empty list self.assertTrue(versionBase.references==[]) # reference the given versions self.mEnv.reference(version1) self.mEnv.reference(version2) # save it as versionBase self.mEnv.save_as(versionBase) # clean scene pm.newFile(force=True) # re-open the file self.mEnv.open_(versionBase, force=True) self.mEnv.post_open(versionBase) # check if the references are loaded ref_data = self.mEnv.get_referenced_versions() for data in ref_data: ref_node = data[1] self.assertTrue(ref_node.isLoaded())
def test_save_as_sets_the_resolution_only_for_first_version(self): """testing if save_as sets the render resolution for the current scene but only for the first version of the asset """ project = self.version1.project width = 1920 height = 1080 pixel_aspect = 1.0 project.width = width project.height = height project.pixel_aspect = pixel_aspect project.save() # save the scene self.mEnv.save_as(self.version1) # check the resolutions dRes = pm.PyNode("defaultResolution") self.assertEqual(dRes.width.get(), width) self.assertEqual(dRes.height.get(), height) self.assertEqual(dRes.pixelAspect.get(), pixel_aspect) # now change the resolution of the maya file new_width = 1280 new_height = 720 new_pixel_aspect = 1.0 dRes.width.set(new_width) dRes.height.set(new_height) dRes.pixelAspect.set(new_pixel_aspect) # save the version again new_version = Version(**self.kwargs) new_version.save() self.mEnv.save_as(new_version) # test if the resolution is not changed self.assertEqual(dRes.width.get(), new_width) self.assertEqual(dRes.height.get(), new_height) self.assertEqual(dRes.pixelAspect.get(), new_pixel_aspect)
def test_reference_creates_references_to_Versions_in_other_workspaces_loaded( self): """testing if reference method creates references to Versions with different VersionType and the reference state will be loaded """ proj1 = Project("Test Project 1") proj1.create() proj1.save() asset1 = Asset(proj1, "Test Asset 1") asset1.save() vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers1.save() vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1) vers2.save() self.mEnv.save_as(vers1) pm.newFile(force=True) self.mEnv.save_as(vers2) # refence vers1 to vers2 self.mEnv.reference(vers1) # now check if the referenced files unresolved path is already starting # with conf.repository_env_key refs = pm.listReferences() # there should be only one reference self.assertEqual(len(refs), 1) # the unresolved path should start with $REPO self.assertTrue( refs[0].unresolvedPath().startswith("$" + conf.repository_env_key)) self.assertTrue(refs[0].isLoaded())
def test_reference_creates_references_to_Versions_in_other_workspaces_loaded(self): """testing if reference method creates references to Versions with different VersionType and the reference state will be loaded """ proj1 = Project("Test Project 1") proj1.create() proj1.save() asset1 = Asset(proj1, "Test Asset 1") asset1.save() vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers1.save() vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1) vers2.save() self.mEnv.save_as(vers1) pm.newFile(force=True) self.mEnv.save_as(vers2) # refence vers1 to vers2 self.mEnv.reference(vers1) # now check if the referenced files unresolved path is already starting # with conf.repository_env_key refs = pm.listReferences() # there should be only one reference self.assertEqual(len(refs), 1) # the unresolved path should start with $REPO self.assertTrue( refs[0].unresolvedPath().startswith("$" + conf.repository_env_key) ) self.assertTrue(refs[0].isLoaded())
def test_save_as_fills_the_referenced_versions_list(self): """testing if the save_as method updates the Version.references list with the current references list from the Maya """ # create a couple of versions and reference them to each other # and reference them to the the scene and check if maya updates the # Version.references list versionBase = Version(**self.kwargs) versionBase.save() # change the take name self.kwargs["take_name"] = "Take1" version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "Take2" version2 = Version(**self.kwargs) version2.save() self.kwargs["take_name"] = "Take3" version3 = Version(**self.kwargs) version3.save() # now create scenes with these files self.mEnv.save_as(version1) self.mEnv.save_as(version2) self.mEnv.save_as(version3) # this is the dummy version # create a new scene pm.newFile(force=True) # check if the versionBase.references is an empty list self.assertTrue(versionBase.references==[]) # reference the given versions self.mEnv.reference(version1) self.mEnv.reference(version2) # save it as versionBase self.mEnv.save_as(versionBase) # now check if versionBase.references is updated self.assertTrue(len(versionBase.references)==2) self.assertTrue(version1 in versionBase.references) self.assertTrue(version2 in versionBase.references)
def test_save_as_fills_the_referenced_versions_list(self): """testing if the save_as method updates the Version.references list with the current references list from the Maya """ # create a couple of versions and reference them to each other # and reference them to the the scene and check if maya updates the # Version.references list versionBase = Version(**self.kwargs) versionBase.save() # change the take name self.kwargs["take_name"] = "Take1" version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "Take2" version2 = Version(**self.kwargs) version2.save() self.kwargs["take_name"] = "Take3" version3 = Version(**self.kwargs) version3.save() # now create scenes with these files self.mEnv.save_as(version1) self.mEnv.save_as(version2) self.mEnv.save_as(version3) # this is the dummy version # create a new scene pm.newFile(force=True) # check if the versionBase.references is an empty list self.assertTrue(versionBase.references == []) # reference the given versions self.mEnv.reference(version1) self.mEnv.reference(version2) # save it as versionBase self.mEnv.save_as(versionBase) # now check if versionBase.references is updated self.assertTrue(len(versionBase.references) == 2) self.assertTrue(version1 in versionBase.references) self.assertTrue(version2 in versionBase.references)
def test_save_as_of_a_scene_with_two_references_to_the_same_version(self): """testing if the case where the current maya scene has two references to the same file is gracefully handled by assigning the version only once """ # create project proj1 = Project("Proj1") proj1.save() proj1.create() # create assets asset1 = Asset(proj1, "Asset 1") asset1.save() # create a version of asset vtype vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers1.save() # save it self.mEnv.save_as(vers1) # new scene pm.newFile(force=True) # create another version with different type vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1) vers2.save() # reference the other version twice self.mEnv.reference(vers1) self.mEnv.reference(vers1) # save it and expect no InvalidRequestError self.mEnv.save_as(vers2) self.mEnv.reference(vers1) vers3 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1) vers3.save() self.mEnv.save_as(vers3)
def test_shots_tableWidget_is_filled_with_Shot_data(self): """testing if the shots_tableWidget is filled with shot data properly """ db.setup() # create a project proj1 = Project('Test Project 1') proj1.save() proj2 = Project('Test Project 2') proj2.save() shot_vtypes = VersionType.query()\ .filter(VersionType.type_for=='Shot')\ .order_by(VersionType.name)\ .all() admin = User.query().first() # seqs for proj1 seq1 = Sequence(proj1, 'Test Seq 1') seq1.save() seq2 = Sequence(proj1, 'Test Seq 2') seq2.save() # seqs for proj2 seq3 = Sequence(proj2, 'Test Seq 3') seq3.save() seq4 = Sequence(proj2, 'Test Seq 4') seq4.save() # shots for seq1 shot1 = Shot(seq1, 1) shot1.save() shot2 = Shot(seq1, 2) shot2.save() shot3 = Shot(seq1, 3) shot3.save() # shots for seq2 shot4 = Shot(seq2, 4) shot4.save() shot5 = Shot(seq2, 5) shot5.save() shot6 = Shot(seq2, 6) shot6.save() # shots for seq3 shot7 = Shot(seq3, 7) shot7.save() shot8 = Shot(seq3, 8) shot8.save() # shots for seq4 shot9 = Shot(seq4, 9) shot9.save() shot10 = Shot(seq4, 10) shot10.save() # versions for shot1 version1 = Version( version_of=shot1, base_name=shot1.code, type=shot_vtypes[0], created_by=admin, status=conf.status_list[0] ) version1.save() version2 = Version( version_of=shot1, base_name=shot1.code, type=shot_vtypes[1], created_by=admin, status=conf.status_list[1] ) version2.save() # versions for shot2 version3 = Version( version_of=shot2, base_name=shot2.code, type=shot_vtypes[2], created_by=admin, status=conf.status_list[2] ) version3.save() version4 = Version( version_of=shot2, base_name=shot2.code, type=shot_vtypes[3], created_by=admin, status=conf.status_list[3], ) version4.save() # versions for shot3 version5 = Version( version_of=shot3, base_name=shot3.code, type=shot_vtypes[4], created_by=admin, status=conf.status_list[4], ) version5.save() version6 = Version( version_of=shot3, base_name=shot3.code, type=shot_vtypes[5], created_by=admin, status=conf.status_list[4], ) version6.save() # versions for shot4 version7 = Version( version_of=shot4, base_name=shot4.code, type=shot_vtypes[5], created_by=admin, status=conf.status_list[4] ) version7.save() version8 = Version( version_of=shot4, base_name=shot4.code, type=shot_vtypes[5], created_by=admin, status=conf.status_list[0] ) version8.save() dialog = status_manager.MainDialog() # self.show_dialog(dialog) # start tests # set the project to project1 dialog.projects_comboBox.setCurrentIndex(0) #self.show_dialog(dialog) # asset1's vtypes[0] vtypes[1] vtypes[2] vtypes[3] self.fail('test is not finished yet!')
def test_assets_tableWidget_is_filled_with_Asset_data(self): """testing if the assets_tableWidget is filled with asset data properly """ db.setup() # create a project proj1 = Project('Test Project 1') proj1.save() proj2 = Project('Test Project 2') proj2.save() asset_vtypes = VersionType.query()\ .filter(VersionType.type_for=='Asset')\ .order_by(VersionType.name)\ .all() admin = User.query().first() asset1 = Asset(proj1, 'Test Asset 1', type='Char') asset1.save() asset2 = Asset(proj1, 'Test Asset 2', type='Prop') asset2.save() asset3 = Asset(proj1, 'Test Asset 3', type='Environment') asset3.save() asset4 = Asset(proj1, 'Test Asset 4', type='Prop') asset4.save() # versions for asset1 version1 = Version( version_of=asset1, base_name=asset1.code, type=asset_vtypes[0], created_by=admin, status=conf.status_list[0] ) version1.save() version2 = Version( version_of=asset1, base_name=asset1.code, type=asset_vtypes[1], created_by=admin, status=conf.status_list[1] ) version2.save() version3 = Version( version_of=asset1, base_name=asset1.code, type=asset_vtypes[2], created_by=admin, status=conf.status_list[2] ) version3.save() # version for asset1 with different takes version4 = Version( version_of=asset1, base_name=asset1.code, type=asset_vtypes[3], created_by=admin, status=conf.status_list[3], take_name='Test_A' ) version4.save() version5 = Version( version_of=asset1, base_name=asset1.code, type=asset_vtypes[4], created_by=admin, status=conf.status_list[4], take_name='Test_A' ) version5.save() version6 = Version( version_of=asset1, base_name=asset1.code, type=asset_vtypes[5], created_by=admin, status=conf.status_list[4], take_name='Test_B' ) version6.save() version7 = Version( version_of=asset1, base_name=asset1.code, type=asset_vtypes[5], created_by=admin, status=conf.status_list[4], take_name='Test_B' ) version7.save() dialog = status_manager.MainDialog() # self.show_dialog(dialog) # start tests # What we should see shoul be: # # +-----------+-------------+--------------+--------+---------------------+ # | Thumbnail | Type | Name | Take | Asset Version Types | # +===========+=============+==============+========+=====================+ # | (IMAGE) | Char | Test Asset 1 | MAIN | ******************* | # +-----------+-------------+--------------+--------+---------------------+ # | (IMAGE) | Char | Test Asset 1 | Test_A | ******************* | # +-----------+-------------+--------------+--------+---------------------+ # | (IMAGE) | Char | Test Asset 1 | Test_B | ******************* | # +-----------+-------------+--------------+--------+---------------------+ # | (IMAGE) | Environment | Test Asset 3 | ---- | ******************* | # +-----------+-------------+--------------+--------+---------------------+ # | (IMAGE) | Prop | Test Asset 2 | ---- | ******************* | # +-----------+-------------+--------------+--------+---------------------+ # | (IMAGE) | Prop | Test Asset 4 | ---- | ******************* | # +-----------+-------------+--------------+--------+---------------------+ # # set the project to project1 dialog.projects_comboBox.setCurrentIndex(0) # asset1's vtypes[0] vtypes[1] vtypes[2] vtypes[3] # set to assets dialog.tabWidget.setCurrentIndex(0) #self.show_dialog(dialog) # expect to see 6 rows self.assertEqual(6, dialog.assets_tableWidget.rowCount()) # expect the assets types listed in the first column # first three should be Char dialog.assets_tableWidget.setCurrentCell(0, 1) self.assertEqual('Char', dialog.assets_tableWidget.currentItem().text()) dialog.assets_tableWidget.setCurrentCell(1, 1) self.assertEqual('Char', dialog.assets_tableWidget.currentItem().text()) dialog.assets_tableWidget.setCurrentCell(2, 1) self.assertEqual('Char', dialog.assets_tableWidget.currentItem().text()) # next should be Environment dialog.assets_tableWidget.setCurrentCell(3, 1) self.assertEqual( 'Environment', dialog.assets_tableWidget.currentItem().text() ) # the next two should be Prop dialog.assets_tableWidget.setCurrentCell(4, 1) self.assertEqual( 'Prop', dialog.assets_tableWidget.currentItem().text() ) dialog.assets_tableWidget.setCurrentCell(5, 1) self.assertEqual( 'Prop', dialog.assets_tableWidget.currentItem().text() )
def test_save_as_in_another_project_updates_paths_correctly(self): """testing if the external paths are updated correctly if the document is created in one maya project but it is saved under another one. """ # create a new scene # save it under one Asset Version with name Asset1 asset1 = Asset(self.project, "Asset 1") asset1.save() self.kwargs["version_of"] = asset1 self.kwargs["base_name"] = asset1.code version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "References1" version_ref1 = Version(**self.kwargs) version_ref1.save() self.kwargs["take_name"] = "References2" version_ref2 = Version(**self.kwargs) version_ref2.save() # save a maya file with this references self.mEnv.save_as(version_ref1) self.mEnv.save_as(version_ref2) # save the original version self.mEnv.save_as(version1) # create a couple of file textures file_texture1 = pm.createNode("file") file_texture2 = pm.createNode("file") path1 = os.path.dirname(version1.path) + "/.maya_files/TEXTURES/a.jpg" path2 = os.path.dirname(version1.path) + "/.maya_files/TEXTURES/b.jpg" # set them to some relative paths file_texture1.fileTextureName.set(path1) file_texture2.fileTextureName.set(path2) # create a couple of references in the same project self.mEnv.reference(version_ref1) self.mEnv.reference(version_ref2) # save again self.mEnv.save_as(version1) # then save it under another Asset with name Asset2 # because with this new system all the Assets folders are a maya # project, the references should be updated correctly asset2 = Asset(self.project, "Asset 2") asset2.save() # create a new Version for Asset 2 self.kwargs["version_of"] = asset2 self.kwargs["base_name"] = asset2.code version2 = Version(**self.kwargs) # now save it under that asset self.mEnv.save_as(version2) # check if the paths are updated self.assertEqual( file_texture1.fileTextureName.get(), "$REPO/TEST_PROJECT/Assets/Asset_1/.maya_files/TEXTURES/a.jpg") self.assertEqual( file_texture2.fileTextureName.get(), "$REPO/TEST_PROJECT/Assets/Asset_1/.maya_files/TEXTURES/b.jpg")
class MayaTester(unittest.TestCase): """Tests the oyProjectManager.environments.mayaEnv.Maya class """ def setUp(self): """setup the tests """ # ----------------------------------------------------------------- # start of the setUp # create the environment variable and point it to a temp directory conf.database_url = "sqlite://" self.temp_config_folder = tempfile.mkdtemp() self.temp_projects_folder = tempfile.mkdtemp() os.environ["OYPROJECTMANAGER_PATH"] = self.temp_config_folder os.environ[conf.repository_env_key] = self.temp_projects_folder # create a test project self.project = Project("Test Project") self.project.create() # create a test asset self.asset1 = Asset(self.project, "Test Asset 1") # version type self.asset_vtypes = VersionType.query()\ .filter(VersionType.type_for == "Asset").all() self.shot_vtypes = VersionType.query()\ .filter(VersionType.type_for == "Shot").all() self.user1 = User(name="Test User 1", email="*****@*****.**") # create a test version self.kwargs = { "version_of":self.asset1, "base_name":self.asset1.code, "type":self.asset_vtypes[0], "created_by":self.user1, "extension":"ma" } self.version1 = Version(**self.kwargs) self.version1.save() # create the environment instance self.mEnv = mayaEnv.Maya() # just renew the scene pm.newFile(force=True) def tearDown(self): """cleanup the test """ # set the db.session to None db.session = None # delete the temp folder shutil.rmtree(self.temp_config_folder) shutil.rmtree(self.temp_projects_folder) # quit maya pm.runtime.Quit() def test_save_as_creates_a_maya_file_at_version_full_path(self): """testing if the save_as creates a maya file at the Version.full_path """ # check the version file doesn't exists self.assertFalse(os.path.exists(self.version1.full_path)) # save the version self.mEnv.save_as(self.version1) # check the file exists self.assertTrue(os.path.exists(self.version1.full_path)) def test_save_as_sets_the_version_extension_to_ma(self): """testing if the save_as method sets the version extension to ma """ self.version1.extension = "" self.mEnv.save_as(self.version1) self.assertEqual(self.version1.extension, ".ma") def test_save_as_sets_the_render_version_string(self): """testing if the save_as method sets the version string in the render settings """ self.mEnv.save_as(self.version1) # now check if the render settings version is the same with the # version.version_number render_version = pm.getAttr("defaultRenderGlobals.renderVersion") self.assertEqual(render_version, "v%03d" % self.version1.version_number) def test_save_as_sets_the_render_format_to_exr_for_mentalray(self): """testing if the save_as method sets the render format to exr """ # load mayatomr plugin pm.loadPlugin("Mayatomr") # set the current renderer to mentalray dRG = pm.PyNode("defaultRenderGlobals") dRG.setAttr('currentRenderer', 'mentalRay') # dirty little maya tricks pm.mel.miCreateDefaultNodes() mrG = pm.PyNode("mentalrayGlobals") self.mEnv.save_as(self.version1) # now check if the render format is correctly set to exr with zip # compression self.assertEqual(dRG.getAttr("imageFormat"), 51) self.assertEqual(dRG.getAttr("imfkey"), "exr") self.assertEqual(mrG.getAttr("imageCompression"), 4) def test_save_as_sets_the_render_file_name_for_Assets(self): """testing if the save_as sets the render file name correctly """ self.mEnv.save_as(self.version1) # check if the path equals to expected_path = self.version1.output_path +\ "/<Layer>/"+ self.version1.project.code + "_" +\ self.version1.base_name +"_" +\ self.version1.take_name +\ "_<Layer>_<RenderPass>_<Version>" image_path = os.path.join( pm.workspace.path, pm.workspace.fileRules['image'] ).replace("\\", "/") expected_path = utils.relpath( image_path, expected_path, ) dRG = pm.PyNode("defaultRenderGlobals") self.assertEqual( expected_path, dRG.getAttr("imageFilePrefix") ) def test_save_as_sets_the_render_file_name_for_Shots(self): """testing if the save_as sets the render file name correctly """ test_seq = Sequence(self.project, "Test Sequence 1") test_seq.save() test_shot = Shot(test_seq, 1) test_shot.save() self.kwargs["type"] = self.shot_vtypes[0] self.kwargs["version_of"] = test_shot self.version1 = Version(**self.kwargs) self.mEnv.save_as(self.version1) # check if the path equals to expected_path = self.version1.output_path + \ "/<Layer>/"+ self.version1.project.code + "_" + \ self.version1.version_of.sequence.code + "_" + \ self.version1.base_name +"_" + \ self.version1.take_name + \ "_<Layer>_<RenderPass>_<Version>" image_path = os.path.join( pm.workspace.path, pm.workspace.fileRules['image'] ).replace("\\", "/") expected_path = utils.relpath( image_path, expected_path, ) dRG = pm.PyNode("defaultRenderGlobals") self.assertEqual( expected_path, dRG.getAttr("imageFilePrefix") ) def test_save_as_replaces_file_image_paths(self): """testing if save_as method replaces image paths with REPO relative path """ self.mEnv.save_as(self.version1) # create file node file_node = pm.createNode("file") # set it to a path in the workspace texture_path = os.path.join( pm.workspace.path, ".maya_files/textures/test.jpg" ) file_node.fileTextureName.set(texture_path) # save a newer version version2 = Version(**self.kwargs) version2.save() self.mEnv.save_as(version2) # now check if the file nodes fileTextureName is converted to a # relative path to the current workspace expected_path = texture_path.replace(os.environ["REPO"], "$REPO") self.assertEqual( file_node.getAttr("fileTextureName"), expected_path ) def test_save_as_sets_the_resolution(self): """testing if save_as sets the render resolution for the current scene """ project = self.version1.project width = 1920 height = 1080 pixel_aspect = 1.0 project.width = width project.height = height project.pixel_aspect = pixel_aspect project.save() # save the scene self.mEnv.save_as(self.version1) # check the resolutions dRes = pm.PyNode("defaultResolution") self.assertEqual(dRes.width.get(), width) self.assertEqual(dRes.height.get(), height) self.assertEqual(dRes.pixelAspect.get(), pixel_aspect) def test_save_as_sets_the_resolution_only_for_first_version(self): """testing if save_as sets the render resolution for the current scene but only for the first version of the asset """ project = self.version1.project width = 1920 height = 1080 pixel_aspect = 1.0 project.width = width project.height = height project.pixel_aspect = pixel_aspect project.save() # save the scene self.mEnv.save_as(self.version1) # check the resolutions dRes = pm.PyNode("defaultResolution") self.assertEqual(dRes.width.get(), width) self.assertEqual(dRes.height.get(), height) self.assertEqual(dRes.pixelAspect.get(), pixel_aspect) # now change the resolution of the maya file new_width = 1280 new_height = 720 new_pixel_aspect = 1.0 dRes.width.set(new_width) dRes.height.set(new_height) dRes.pixelAspect.set(new_pixel_aspect) # save the version again new_version = Version(**self.kwargs) new_version.save() self.mEnv.save_as(new_version) # test if the resolution is not changed self.assertEqual(dRes.width.get(), new_width) self.assertEqual(dRes.height.get(), new_height) self.assertEqual(dRes.pixelAspect.get(), new_pixel_aspect) def test_save_as_fills_the_referenced_versions_list(self): """testing if the save_as method updates the Version.references list with the current references list from the Maya """ # create a couple of versions and reference them to each other # and reference them to the the scene and check if maya updates the # Version.references list versionBase = Version(**self.kwargs) versionBase.save() # change the take name self.kwargs["take_name"] = "Take1" version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "Take2" version2 = Version(**self.kwargs) version2.save() self.kwargs["take_name"] = "Take3" version3 = Version(**self.kwargs) version3.save() # now create scenes with these files self.mEnv.save_as(version1) self.mEnv.save_as(version2) self.mEnv.save_as(version3) # this is the dummy version # create a new scene pm.newFile(force=True) # check if the versionBase.references is an empty list self.assertTrue(versionBase.references==[]) # reference the given versions self.mEnv.reference(version1) self.mEnv.reference(version2) # save it as versionBase self.mEnv.save_as(versionBase) # now check if versionBase.references is updated self.assertTrue(len(versionBase.references)==2) self.assertTrue(version1 in versionBase.references) self.assertTrue(version2 in versionBase.references) def test_save_as_references_to_a_version_in_same_workspace_are_replaced_with_abs_path_with_env_variable(self): """testing if the save_as method updates the references paths with an absolute path starting with conf.repository_env_key for references to a version in the same project thus the referenced path is relative """ # create project proj1 = Project("Proj1") proj1.save() proj1.create() # create assets asset1 = Asset(proj1, "Asset 1") asset1.save() # create a version of asset vtype vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers1.save() # save it self.mEnv.save_as(vers1) # new scene pm.newFile(force=True) # create another version with different type vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1) vers2.save() # reference the other version self.mEnv.reference(vers1) # save it self.mEnv.save_as(vers2) # now check if the referenced vers1 starts with $REPO refs = pm.listReferences() # there should be only one ref self.assertTrue(len(refs)==1) # and the path should start with conf.repository_env_key self.assertTrue( refs[0].unresolvedPath().startswith("$" + conf.repository_env_key) ) def test_save_as_of_a_scene_with_two_references_to_the_same_version(self): """testing if the case where the current maya scene has two references to the same file is gracefully handled by assigning the version only once """ # create project proj1 = Project("Proj1") proj1.save() proj1.create() # create assets asset1 = Asset(proj1, "Asset 1") asset1.save() # create a version of asset vtype vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers1.save() # save it self.mEnv.save_as(vers1) # new scene pm.newFile(force=True) # create another version with different type vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1) vers2.save() # reference the other version twice self.mEnv.reference(vers1) self.mEnv.reference(vers1) # save it and expect no InvalidRequestError self.mEnv.save_as(vers2) self.mEnv.reference(vers1) vers3 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1) vers3.save() self.mEnv.save_as(vers3) def test_save_as_will_not_save_the_file_if_there_are_file_textures_with_local_path(self): """testing if save_as will raise a RuntimeError if there are file textures with local path """ # create a texture file with local path new_texture_file = pm.nt.File() # generate a local path local_file_full_path = os.path.join( tempfile.gettempdir(), "temp.png" ) new_texture_file.fileTextureName.set(local_file_full_path) # now try to save it as a new version and expect a RuntimeError self.assertRaises( RuntimeError, self.mEnv.save_as, self.version1 ) def test_open_updates_the_referenced_versions_list(self): """testing if the open method updates the Version.references list with the current references list from the Maya """ # create a couple of versions and reference them to each other # and reference them to the the scene and check if maya updates the # Version.references list versionBase = Version(**self.kwargs) versionBase.save() # change the take naem self.kwargs["take_name"] = "Take1" version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "Take2" version2 = Version(**self.kwargs) version2.save() self.kwargs["take_name"] = "Take3" version3 = Version(**self.kwargs) version3.save() # now create scenes with these files self.mEnv.save_as(version1) self.mEnv.save_as(version2) self.mEnv.save_as(version3) # this is the dummy version # create a new scene pm.newFile(force=True) # check if the versionBase.references is an empty list self.assertTrue(versionBase.references==[]) # reference the given versions self.mEnv.reference(version1) self.mEnv.reference(version2) # save it as versionBase self.mEnv.save_as(versionBase) # now check if versionBase.references is updated # this part is already tested in save_as self.assertTrue(len(versionBase.references)==2) self.assertTrue(version1 in versionBase.references) self.assertTrue(version2 in versionBase.references) # now remove references ref_data = self.mEnv.get_referenced_versions() for data in ref_data: ref_node = data[1] ref_node.remove() # do a save (not save_as) pm.saveFile() # clean scene pm.newFile(force=True) # open the same asset self.mEnv.open_(versionBase, force=True) # and check the references is updated self.assertEqual(len(versionBase.references), 0) self.assertEqual(versionBase.references, []) def test_open_loads_the_references(self): """testing if the open method loads the references """ # create a couple of versions and reference them to each other # and reference them to the the scene and check if maya updates the # Version.references list versionBase = Version(**self.kwargs) versionBase.save() # change the take naem self.kwargs["take_name"] = "Take1" version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "Take2" version2 = Version(**self.kwargs) version2.save() self.kwargs["take_name"] = "Take3" version3 = Version(**self.kwargs) version3.save() # now create scenes with these files self.mEnv.save_as(version1) self.mEnv.save_as(version2) self.mEnv.save_as(version3) # this is the dummy version # create a new scene pm.newFile(force=True) # check if the versionBase.references is an empty list self.assertTrue(versionBase.references==[]) # reference the given versions self.mEnv.reference(version1) self.mEnv.reference(version2) # save it as versionBase self.mEnv.save_as(versionBase) # clean scene pm.newFile(force=True) # re-open the file self.mEnv.open_(versionBase, force=True) self.mEnv.post_open(versionBase) # check if the references are loaded ref_data = self.mEnv.get_referenced_versions() for data in ref_data: ref_node = data[1] self.assertTrue(ref_node.isLoaded()) def test_save_as_in_another_project_updates_paths_correctly(self): """testing if the external paths are updated correctly if the document is created in one maya project but it is saved under another one. """ # create a new scene # save it under one Asset Version with name Asset1 asset1 = Asset(self.project, "Asset 1") asset1.save() self.kwargs["version_of"] = asset1 self.kwargs["base_name"] = asset1.code version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "References1" version_ref1 = Version(**self.kwargs) version_ref1.save() self.kwargs["take_name"] = "References2" version_ref2 = Version(**self.kwargs) version_ref2.save() # save a maya file with this references self.mEnv.save_as(version_ref1) self.mEnv.save_as(version_ref2) # save the original version self.mEnv.save_as(version1) # create a couple of file textures file_texture1 = pm.createNode("file") file_texture2 = pm.createNode("file") path1 = os.path.dirname(version1.path) + "/.maya_files/TEXTURES/a.jpg" path2 = os.path.dirname(version1.path) + "/.maya_files/TEXTURES/b.jpg" # set them to some relative paths file_texture1.fileTextureName.set(path1) file_texture2.fileTextureName.set(path2) # create a couple of references in the same project self.mEnv.reference(version_ref1) self.mEnv.reference(version_ref2) # save again self.mEnv.save_as(version1) # then save it under another Asset with name Asset2 # because with this new system all the Assets folders are a maya # project, the references should be updated correctly asset2 = Asset(self.project, "Asset 2") asset2.save() # create a new Version for Asset 2 self.kwargs["version_of"] = asset2 self.kwargs["base_name"] = asset2.code version2 = Version(**self.kwargs) # now save it under that asset self.mEnv.save_as(version2) # check if the paths are updated self.assertEqual( file_texture1.fileTextureName.get(), "$REPO/TEST_PROJECT/Assets/Asset_1/.maya_files/TEXTURES/a.jpg" ) self.assertEqual( file_texture2.fileTextureName.get(), "$REPO/TEST_PROJECT/Assets/Asset_1/.maya_files/TEXTURES/b.jpg" ) def test_save_as_sets_the_fps(self): """testing if the save_as method sets the fps value correctly """ # create two projects with different fps values # first create a new scene and save it under the first project # and then save it under the other project # and check if the fps follows the project values project1 = Project("FPS_TEST_PROJECT_1") project1.fps = 24 project1.create() project2 = Project("FPS_TEST_PROJECT_2") project2.fps = 30 project2.save() # create assets asset1 = Asset(project1, "Test Asset 1") asset1.save() asset2 = Asset(project2, "Test Asset 2") asset2.save() # create versions version1 = Version( version_of=asset1, base_name=asset1.code, type=self.asset_vtypes[0], created_by=self.user1 ) version2 = Version( version_of=asset2, base_name=asset2.code, type=self.asset_vtypes[0], created_by=self.user1 ) # save the current scene for asset1 self.mEnv.save_as(version1) # check the fps value self.assertEqual( self.mEnv.get_fps(), 24 ) # now save it for asset2 self.mEnv.save_as(version2) # check the fps value self.assertEqual( self.mEnv.get_fps(), 30 ) def test_reference_creates_references_with_paths_starting_with_repository_env_key(self): """testing if reference method creates references with unresolved paths starting with conf.repository_env_key """ proj1 = Project("Test Project 1") proj1.create() proj1.save() asset1 = Asset(proj1, "Test Asset 1") asset1.save() vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers1.save() vers2 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers2.save() self.mEnv.save_as(vers1) pm.newFile(force=True) self.mEnv.save_as(vers2) # refence vers1 to vers2 self.mEnv.reference(vers1) # now check if the referenced files unresolved path is already starting # with conf.repository_env_key refs = pm.listReferences() # there should be only one reference self.assertEqual(len(refs), 1) # the unresolved path should start with $REPO self.assertTrue( refs[0].unresolvedPath().startswith("$" + conf.repository_env_key) ) self.assertTrue(refs[0].isLoaded()) def test_reference_creates_references_to_Versions_in_other_workspaces_loaded(self): """testing if reference method creates references to Versions with different VersionType and the reference state will be loaded """ proj1 = Project("Test Project 1") proj1.create() proj1.save() asset1 = Asset(proj1, "Test Asset 1") asset1.save() vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers1.save() vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1) vers2.save() self.mEnv.save_as(vers1) pm.newFile(force=True) self.mEnv.save_as(vers2) # refence vers1 to vers2 self.mEnv.reference(vers1) # now check if the referenced files unresolved path is already starting # with conf.repository_env_key refs = pm.listReferences() # there should be only one reference self.assertEqual(len(refs), 1) # the unresolved path should start with $REPO self.assertTrue( refs[0].unresolvedPath().startswith("$" + conf.repository_env_key) ) self.assertTrue(refs[0].isLoaded()) def test_save_as_replaces_imagePlane_filename_with_env_variable(self): """testing if save_as replaces the imagePlane filename with repository environment variable """ # create a camera # create an image plane # set it to something # save the scene # check if the path is replaced with repository environment variable self.fail("test is not implemented yet") def test_save_as_creates_the_workspace_mel_file_in_the_given_path(self): """testing if save_as creates the workspace.mel file in the Asset or Shot root """ # check if the workspace.mel file does not exist yet workspace_mel_full_path = os.path.join( os.path.dirname(self.version1.path), 'workspace.mel' ) self.assertFalse(os.path.exists(workspace_mel_full_path)) self.mEnv.save_as(self.version1) self.assertTrue(os.path.exists(workspace_mel_full_path)) def test_save_as_creates_the_workspace_fileRule_folders(self): """testing if save_as creates the fileRule folders """ # first prove that the folders doesn't exist for key in pm.workspace.fileRules.keys(): file_rule_partial_path = pm.workspace.fileRules[key] file_rule_full_path = os.path.join( os.path.dirname(self.version1.path), file_rule_partial_path ) self.assertFalse(os.path.exists(file_rule_full_path)) self.mEnv.save_as(self.version1) # save_as and now expect the folders to be created for key in pm.workspace.fileRules.keys(): file_rule_partial_path = pm.workspace.fileRules[key] file_rule_full_path = os.path.join( os.path.dirname(self.version1.path), file_rule_partial_path ) self.assertTrue(os.path.exists(file_rule_full_path))
def test_open_updates_the_referenced_versions_list(self): """testing if the open method updates the Version.references list with the current references list from the Maya """ # create a couple of versions and reference them to each other # and reference them to the the scene and check if maya updates the # Version.references list versionBase = Version(**self.kwargs) versionBase.save() # change the take naem self.kwargs["take_name"] = "Take1" version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "Take2" version2 = Version(**self.kwargs) version2.save() self.kwargs["take_name"] = "Take3" version3 = Version(**self.kwargs) version3.save() # now create scenes with these files self.mEnv.save_as(version1) self.mEnv.save_as(version2) self.mEnv.save_as(version3) # this is the dummy version # create a new scene pm.newFile(force=True) # check if the versionBase.references is an empty list self.assertTrue(versionBase.references == []) # reference the given versions self.mEnv.reference(version1) self.mEnv.reference(version2) # save it as versionBase self.mEnv.save_as(versionBase) # now check if versionBase.references is updated # this part is already tested in save_as self.assertTrue(len(versionBase.references) == 2) self.assertTrue(version1 in versionBase.references) self.assertTrue(version2 in versionBase.references) # now remove references ref_data = self.mEnv.get_referenced_versions() for data in ref_data: ref_node = data[1] ref_node.remove() # do a save (not save_as) pm.saveFile() # clean scene pm.newFile(force=True) # open the same asset self.mEnv.open_(versionBase, force=True) # and check the references is updated self.assertEqual(len(versionBase.references), 0) self.assertEqual(versionBase.references, [])
def test_assets_tableWidget_is_filled_with_Asset_data(self): """testing if the assets_tableWidget is filled with asset data properly """ db.setup() # create a project proj1 = Project('Test Project 1') proj1.save() proj2 = Project('Test Project 2') proj2.save() asset_vtypes = VersionType.query()\ .filter(VersionType.type_for=='Asset')\ .order_by(VersionType.name)\ .all() admin = User.query().first() asset1 = Asset(proj1, 'Test Asset 1', type='Char') asset1.save() asset2 = Asset(proj1, 'Test Asset 2', type='Prop') asset2.save() asset3 = Asset(proj1, 'Test Asset 3', type='Environment') asset3.save() asset4 = Asset(proj1, 'Test Asset 4', type='Prop') asset4.save() # versions for asset1 version1 = Version(version_of=asset1, base_name=asset1.code, type=asset_vtypes[0], created_by=admin, status=conf.status_list[0]) version1.save() version2 = Version(version_of=asset1, base_name=asset1.code, type=asset_vtypes[1], created_by=admin, status=conf.status_list[1]) version2.save() version3 = Version(version_of=asset1, base_name=asset1.code, type=asset_vtypes[2], created_by=admin, status=conf.status_list[2]) version3.save() # version for asset1 with different takes version4 = Version(version_of=asset1, base_name=asset1.code, type=asset_vtypes[3], created_by=admin, status=conf.status_list[3], take_name='Test_A') version4.save() version5 = Version(version_of=asset1, base_name=asset1.code, type=asset_vtypes[4], created_by=admin, status=conf.status_list[4], take_name='Test_A') version5.save() version6 = Version(version_of=asset1, base_name=asset1.code, type=asset_vtypes[5], created_by=admin, status=conf.status_list[4], take_name='Test_B') version6.save() version7 = Version(version_of=asset1, base_name=asset1.code, type=asset_vtypes[5], created_by=admin, status=conf.status_list[4], take_name='Test_B') version7.save() dialog = status_manager.MainDialog() # self.show_dialog(dialog) # start tests # What we should see shoul be: # # +-----------+-------------+--------------+--------+---------------------+ # | Thumbnail | Type | Name | Take | Asset Version Types | # +===========+=============+==============+========+=====================+ # | (IMAGE) | Char | Test Asset 1 | MAIN | ******************* | # +-----------+-------------+--------------+--------+---------------------+ # | (IMAGE) | Char | Test Asset 1 | Test_A | ******************* | # +-----------+-------------+--------------+--------+---------------------+ # | (IMAGE) | Char | Test Asset 1 | Test_B | ******************* | # +-----------+-------------+--------------+--------+---------------------+ # | (IMAGE) | Environment | Test Asset 3 | ---- | ******************* | # +-----------+-------------+--------------+--------+---------------------+ # | (IMAGE) | Prop | Test Asset 2 | ---- | ******************* | # +-----------+-------------+--------------+--------+---------------------+ # | (IMAGE) | Prop | Test Asset 4 | ---- | ******************* | # +-----------+-------------+--------------+--------+---------------------+ # # set the project to project1 dialog.projects_comboBox.setCurrentIndex(0) # asset1's vtypes[0] vtypes[1] vtypes[2] vtypes[3] # set to assets dialog.tabWidget.setCurrentIndex(0) #self.show_dialog(dialog) # expect to see 6 rows self.assertEqual(6, dialog.assets_tableWidget.rowCount()) # expect the assets types listed in the first column # first three should be Char dialog.assets_tableWidget.setCurrentCell(0, 1) self.assertEqual('Char', dialog.assets_tableWidget.currentItem().text()) dialog.assets_tableWidget.setCurrentCell(1, 1) self.assertEqual('Char', dialog.assets_tableWidget.currentItem().text()) dialog.assets_tableWidget.setCurrentCell(2, 1) self.assertEqual('Char', dialog.assets_tableWidget.currentItem().text()) # next should be Environment dialog.assets_tableWidget.setCurrentCell(3, 1) self.assertEqual('Environment', dialog.assets_tableWidget.currentItem().text()) # the next two should be Prop dialog.assets_tableWidget.setCurrentCell(4, 1) self.assertEqual('Prop', dialog.assets_tableWidget.currentItem().text()) dialog.assets_tableWidget.setCurrentCell(5, 1) self.assertEqual('Prop', dialog.assets_tableWidget.currentItem().text())
def test_save_as_in_another_project_updates_paths_correctly(self): """testing if the external paths are updated correctly if the document is created in one maya project but it is saved under another one. """ # create a new scene # save it under one Asset Version with name Asset1 asset1 = Asset(self.project, "Asset 1") asset1.save() self.kwargs["version_of"] = asset1 self.kwargs["base_name"] = asset1.code version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "References1" version_ref1 = Version(**self.kwargs) version_ref1.save() self.kwargs["take_name"] = "References2" version_ref2 = Version(**self.kwargs) version_ref2.save() # save a maya file with this references self.mEnv.save_as(version_ref1) self.mEnv.save_as(version_ref2) # save the original version self.mEnv.save_as(version1) # create a couple of file textures file_texture1 = pm.createNode("file") file_texture2 = pm.createNode("file") path1 = os.path.dirname(version1.path) + "/.maya_files/TEXTURES/a.jpg" path2 = os.path.dirname(version1.path) + "/.maya_files/TEXTURES/b.jpg" # set them to some relative paths file_texture1.fileTextureName.set(path1) file_texture2.fileTextureName.set(path2) # create a couple of references in the same project self.mEnv.reference(version_ref1) self.mEnv.reference(version_ref2) # save again self.mEnv.save_as(version1) # then save it under another Asset with name Asset2 # because with this new system all the Assets folders are a maya # project, the references should be updated correctly asset2 = Asset(self.project, "Asset 2") asset2.save() # create a new Version for Asset 2 self.kwargs["version_of"] = asset2 self.kwargs["base_name"] = asset2.code version2 = Version(**self.kwargs) # now save it under that asset self.mEnv.save_as(version2) # check if the paths are updated self.assertEqual( file_texture1.fileTextureName.get(), "$REPO/TEST_PROJECT/Assets/Asset_1/.maya_files/TEXTURES/a.jpg" ) self.assertEqual( file_texture2.fileTextureName.get(), "$REPO/TEST_PROJECT/Assets/Asset_1/.maya_files/TEXTURES/b.jpg" )
def test_open_updates_the_referenced_versions_list(self): """testing if the open method updates the Version.references list with the current references list from the Maya """ # create a couple of versions and reference them to each other # and reference them to the the scene and check if maya updates the # Version.references list versionBase = Version(**self.kwargs) versionBase.save() # change the take naem self.kwargs["take_name"] = "Take1" version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "Take2" version2 = Version(**self.kwargs) version2.save() self.kwargs["take_name"] = "Take3" version3 = Version(**self.kwargs) version3.save() # now create scenes with these files self.mEnv.save_as(version1) self.mEnv.save_as(version2) self.mEnv.save_as(version3) # this is the dummy version # create a new scene pm.newFile(force=True) # check if the versionBase.references is an empty list self.assertTrue(versionBase.references==[]) # reference the given versions self.mEnv.reference(version1) self.mEnv.reference(version2) # save it as versionBase self.mEnv.save_as(versionBase) # now check if versionBase.references is updated # this part is already tested in save_as self.assertTrue(len(versionBase.references)==2) self.assertTrue(version1 in versionBase.references) self.assertTrue(version2 in versionBase.references) # now remove references ref_data = self.mEnv.get_referenced_versions() for data in ref_data: ref_node = data[1] ref_node.remove() # do a save (not save_as) pm.saveFile() # clean scene pm.newFile(force=True) # open the same asset self.mEnv.open_(versionBase, force=True) # and check the references is updated self.assertEqual(len(versionBase.references), 0) self.assertEqual(versionBase.references, [])
def test_shots_tableWidget_is_filled_with_Shot_data(self): """testing if the shots_tableWidget is filled with shot data properly """ db.setup() # create a project proj1 = Project('Test Project 1') proj1.save() proj2 = Project('Test Project 2') proj2.save() shot_vtypes = VersionType.query()\ .filter(VersionType.type_for=='Shot')\ .order_by(VersionType.name)\ .all() admin = User.query().first() # seqs for proj1 seq1 = Sequence(proj1, 'Test Seq 1') seq1.save() seq2 = Sequence(proj1, 'Test Seq 2') seq2.save() # seqs for proj2 seq3 = Sequence(proj2, 'Test Seq 3') seq3.save() seq4 = Sequence(proj2, 'Test Seq 4') seq4.save() # shots for seq1 shot1 = Shot(seq1, 1) shot1.save() shot2 = Shot(seq1, 2) shot2.save() shot3 = Shot(seq1, 3) shot3.save() # shots for seq2 shot4 = Shot(seq2, 4) shot4.save() shot5 = Shot(seq2, 5) shot5.save() shot6 = Shot(seq2, 6) shot6.save() # shots for seq3 shot7 = Shot(seq3, 7) shot7.save() shot8 = Shot(seq3, 8) shot8.save() # shots for seq4 shot9 = Shot(seq4, 9) shot9.save() shot10 = Shot(seq4, 10) shot10.save() # versions for shot1 version1 = Version(version_of=shot1, base_name=shot1.code, type=shot_vtypes[0], created_by=admin, status=conf.status_list[0]) version1.save() version2 = Version(version_of=shot1, base_name=shot1.code, type=shot_vtypes[1], created_by=admin, status=conf.status_list[1]) version2.save() # versions for shot2 version3 = Version(version_of=shot2, base_name=shot2.code, type=shot_vtypes[2], created_by=admin, status=conf.status_list[2]) version3.save() version4 = Version( version_of=shot2, base_name=shot2.code, type=shot_vtypes[3], created_by=admin, status=conf.status_list[3], ) version4.save() # versions for shot3 version5 = Version( version_of=shot3, base_name=shot3.code, type=shot_vtypes[4], created_by=admin, status=conf.status_list[4], ) version5.save() version6 = Version( version_of=shot3, base_name=shot3.code, type=shot_vtypes[5], created_by=admin, status=conf.status_list[4], ) version6.save() # versions for shot4 version7 = Version(version_of=shot4, base_name=shot4.code, type=shot_vtypes[5], created_by=admin, status=conf.status_list[4]) version7.save() version8 = Version(version_of=shot4, base_name=shot4.code, type=shot_vtypes[5], created_by=admin, status=conf.status_list[0]) version8.save() dialog = status_manager.MainDialog() # self.show_dialog(dialog) # start tests # set the project to project1 dialog.projects_comboBox.setCurrentIndex(0) #self.show_dialog(dialog) # asset1's vtypes[0] vtypes[1] vtypes[2] vtypes[3] self.fail('test is not finished yet!')
class MayaTester(unittest.TestCase): """Tests the oyProjectManager.environments.mayaEnv.Maya class """ def setUp(self): """setup the tests """ # ----------------------------------------------------------------- # start of the setUp # create the environment variable and point it to a temp directory conf.database_url = "sqlite://" self.temp_config_folder = tempfile.mkdtemp() self.temp_projects_folder = tempfile.mkdtemp() os.environ["OYPROJECTMANAGER_PATH"] = self.temp_config_folder os.environ[conf.repository_env_key] = self.temp_projects_folder # create a test project self.project = Project("Test Project") self.project.create() # create a test asset self.asset1 = Asset(self.project, "Test Asset 1") # version type self.asset_vtypes = VersionType.query()\ .filter(VersionType.type_for == "Asset").all() self.shot_vtypes = VersionType.query()\ .filter(VersionType.type_for == "Shot").all() self.user1 = User(name="Test User 1", email="*****@*****.**") # create a test version self.kwargs = { "version_of": self.asset1, "base_name": self.asset1.code, "type": self.asset_vtypes[0], "created_by": self.user1, "extension": "ma" } self.version1 = Version(**self.kwargs) self.version1.save() # create the environment instance self.mEnv = mayaEnv.Maya() # just renew the scene pm.newFile(force=True) def tearDown(self): """cleanup the test """ # set the db.session to None db.session = None # delete the temp folder shutil.rmtree(self.temp_config_folder) shutil.rmtree(self.temp_projects_folder) # quit maya pm.runtime.Quit() def test_save_as_creates_a_maya_file_at_version_full_path(self): """testing if the save_as creates a maya file at the Version.full_path """ # check the version file doesn't exists self.assertFalse(os.path.exists(self.version1.full_path)) # save the version self.mEnv.save_as(self.version1) # check the file exists self.assertTrue(os.path.exists(self.version1.full_path)) def test_save_as_sets_the_version_extension_to_ma(self): """testing if the save_as method sets the version extension to ma """ self.version1.extension = "" self.mEnv.save_as(self.version1) self.assertEqual(self.version1.extension, ".ma") def test_save_as_sets_the_render_version_string(self): """testing if the save_as method sets the version string in the render settings """ self.mEnv.save_as(self.version1) # now check if the render settings version is the same with the # version.version_number render_version = pm.getAttr("defaultRenderGlobals.renderVersion") self.assertEqual(render_version, "v%03d" % self.version1.version_number) def test_save_as_sets_the_render_format_to_exr_for_mentalray(self): """testing if the save_as method sets the render format to exr """ # load mayatomr plugin pm.loadPlugin("Mayatomr") # set the current renderer to mentalray dRG = pm.PyNode("defaultRenderGlobals") dRG.setAttr('currentRenderer', 'mentalRay') # dirty little maya tricks pm.mel.miCreateDefaultNodes() mrG = pm.PyNode("mentalrayGlobals") self.mEnv.save_as(self.version1) # now check if the render format is correctly set to exr with zip # compression self.assertEqual(dRG.getAttr("imageFormat"), 51) self.assertEqual(dRG.getAttr("imfkey"), "exr") self.assertEqual(mrG.getAttr("imageCompression"), 4) def test_save_as_sets_the_render_file_name_for_Assets(self): """testing if the save_as sets the render file name correctly """ self.mEnv.save_as(self.version1) # check if the path equals to expected_path = self.version1.output_path +\ "/<Layer>/"+ self.version1.project.code + "_" +\ self.version1.base_name +"_" +\ self.version1.take_name +\ "_<Layer>_<RenderPass>_<Version>" image_path = os.path.join(pm.workspace.path, pm.workspace.fileRules['image']).replace( "\\", "/") expected_path = utils.relpath( image_path, expected_path, ) dRG = pm.PyNode("defaultRenderGlobals") self.assertEqual(expected_path, dRG.getAttr("imageFilePrefix")) def test_save_as_sets_the_render_file_name_for_Shots(self): """testing if the save_as sets the render file name correctly """ test_seq = Sequence(self.project, "Test Sequence 1") test_seq.save() test_shot = Shot(test_seq, 1) test_shot.save() self.kwargs["type"] = self.shot_vtypes[0] self.kwargs["version_of"] = test_shot self.version1 = Version(**self.kwargs) self.mEnv.save_as(self.version1) # check if the path equals to expected_path = self.version1.output_path + \ "/<Layer>/"+ self.version1.project.code + "_" + \ self.version1.version_of.sequence.code + "_" + \ self.version1.base_name +"_" + \ self.version1.take_name + \ "_<Layer>_<RenderPass>_<Version>" image_path = os.path.join(pm.workspace.path, pm.workspace.fileRules['image']).replace( "\\", "/") expected_path = utils.relpath( image_path, expected_path, ) dRG = pm.PyNode("defaultRenderGlobals") self.assertEqual(expected_path, dRG.getAttr("imageFilePrefix")) def test_save_as_replaces_file_image_paths(self): """testing if save_as method replaces image paths with REPO relative path """ self.mEnv.save_as(self.version1) # create file node file_node = pm.createNode("file") # set it to a path in the workspace texture_path = os.path.join(pm.workspace.path, ".maya_files/textures/test.jpg") file_node.fileTextureName.set(texture_path) # save a newer version version2 = Version(**self.kwargs) version2.save() self.mEnv.save_as(version2) # now check if the file nodes fileTextureName is converted to a # relative path to the current workspace expected_path = texture_path.replace(os.environ["REPO"], "$REPO") self.assertEqual(file_node.getAttr("fileTextureName"), expected_path) def test_save_as_sets_the_resolution(self): """testing if save_as sets the render resolution for the current scene """ project = self.version1.project width = 1920 height = 1080 pixel_aspect = 1.0 project.width = width project.height = height project.pixel_aspect = pixel_aspect project.save() # save the scene self.mEnv.save_as(self.version1) # check the resolutions dRes = pm.PyNode("defaultResolution") self.assertEqual(dRes.width.get(), width) self.assertEqual(dRes.height.get(), height) self.assertEqual(dRes.pixelAspect.get(), pixel_aspect) def test_save_as_sets_the_resolution_only_for_first_version(self): """testing if save_as sets the render resolution for the current scene but only for the first version of the asset """ project = self.version1.project width = 1920 height = 1080 pixel_aspect = 1.0 project.width = width project.height = height project.pixel_aspect = pixel_aspect project.save() # save the scene self.mEnv.save_as(self.version1) # check the resolutions dRes = pm.PyNode("defaultResolution") self.assertEqual(dRes.width.get(), width) self.assertEqual(dRes.height.get(), height) self.assertEqual(dRes.pixelAspect.get(), pixel_aspect) # now change the resolution of the maya file new_width = 1280 new_height = 720 new_pixel_aspect = 1.0 dRes.width.set(new_width) dRes.height.set(new_height) dRes.pixelAspect.set(new_pixel_aspect) # save the version again new_version = Version(**self.kwargs) new_version.save() self.mEnv.save_as(new_version) # test if the resolution is not changed self.assertEqual(dRes.width.get(), new_width) self.assertEqual(dRes.height.get(), new_height) self.assertEqual(dRes.pixelAspect.get(), new_pixel_aspect) def test_save_as_fills_the_referenced_versions_list(self): """testing if the save_as method updates the Version.references list with the current references list from the Maya """ # create a couple of versions and reference them to each other # and reference them to the the scene and check if maya updates the # Version.references list versionBase = Version(**self.kwargs) versionBase.save() # change the take name self.kwargs["take_name"] = "Take1" version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "Take2" version2 = Version(**self.kwargs) version2.save() self.kwargs["take_name"] = "Take3" version3 = Version(**self.kwargs) version3.save() # now create scenes with these files self.mEnv.save_as(version1) self.mEnv.save_as(version2) self.mEnv.save_as(version3) # this is the dummy version # create a new scene pm.newFile(force=True) # check if the versionBase.references is an empty list self.assertTrue(versionBase.references == []) # reference the given versions self.mEnv.reference(version1) self.mEnv.reference(version2) # save it as versionBase self.mEnv.save_as(versionBase) # now check if versionBase.references is updated self.assertTrue(len(versionBase.references) == 2) self.assertTrue(version1 in versionBase.references) self.assertTrue(version2 in versionBase.references) def test_save_as_references_to_a_version_in_same_workspace_are_replaced_with_abs_path_with_env_variable( self): """testing if the save_as method updates the references paths with an absolute path starting with conf.repository_env_key for references to a version in the same project thus the referenced path is relative """ # create project proj1 = Project("Proj1") proj1.save() proj1.create() # create assets asset1 = Asset(proj1, "Asset 1") asset1.save() # create a version of asset vtype vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers1.save() # save it self.mEnv.save_as(vers1) # new scene pm.newFile(force=True) # create another version with different type vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1) vers2.save() # reference the other version self.mEnv.reference(vers1) # save it self.mEnv.save_as(vers2) # now check if the referenced vers1 starts with $REPO refs = pm.listReferences() # there should be only one ref self.assertTrue(len(refs) == 1) # and the path should start with conf.repository_env_key self.assertTrue( refs[0].unresolvedPath().startswith("$" + conf.repository_env_key)) def test_save_as_of_a_scene_with_two_references_to_the_same_version(self): """testing if the case where the current maya scene has two references to the same file is gracefully handled by assigning the version only once """ # create project proj1 = Project("Proj1") proj1.save() proj1.create() # create assets asset1 = Asset(proj1, "Asset 1") asset1.save() # create a version of asset vtype vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers1.save() # save it self.mEnv.save_as(vers1) # new scene pm.newFile(force=True) # create another version with different type vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1) vers2.save() # reference the other version twice self.mEnv.reference(vers1) self.mEnv.reference(vers1) # save it and expect no InvalidRequestError self.mEnv.save_as(vers2) self.mEnv.reference(vers1) vers3 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1) vers3.save() self.mEnv.save_as(vers3) def test_save_as_will_not_save_the_file_if_there_are_file_textures_with_local_path( self): """testing if save_as will raise a RuntimeError if there are file textures with local path """ # create a texture file with local path new_texture_file = pm.nt.File() # generate a local path local_file_full_path = os.path.join(tempfile.gettempdir(), "temp.png") new_texture_file.fileTextureName.set(local_file_full_path) # now try to save it as a new version and expect a RuntimeError self.assertRaises(RuntimeError, self.mEnv.save_as, self.version1) def test_open_updates_the_referenced_versions_list(self): """testing if the open method updates the Version.references list with the current references list from the Maya """ # create a couple of versions and reference them to each other # and reference them to the the scene and check if maya updates the # Version.references list versionBase = Version(**self.kwargs) versionBase.save() # change the take naem self.kwargs["take_name"] = "Take1" version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "Take2" version2 = Version(**self.kwargs) version2.save() self.kwargs["take_name"] = "Take3" version3 = Version(**self.kwargs) version3.save() # now create scenes with these files self.mEnv.save_as(version1) self.mEnv.save_as(version2) self.mEnv.save_as(version3) # this is the dummy version # create a new scene pm.newFile(force=True) # check if the versionBase.references is an empty list self.assertTrue(versionBase.references == []) # reference the given versions self.mEnv.reference(version1) self.mEnv.reference(version2) # save it as versionBase self.mEnv.save_as(versionBase) # now check if versionBase.references is updated # this part is already tested in save_as self.assertTrue(len(versionBase.references) == 2) self.assertTrue(version1 in versionBase.references) self.assertTrue(version2 in versionBase.references) # now remove references ref_data = self.mEnv.get_referenced_versions() for data in ref_data: ref_node = data[1] ref_node.remove() # do a save (not save_as) pm.saveFile() # clean scene pm.newFile(force=True) # open the same asset self.mEnv.open_(versionBase, force=True) # and check the references is updated self.assertEqual(len(versionBase.references), 0) self.assertEqual(versionBase.references, []) def test_open_loads_the_references(self): """testing if the open method loads the references """ # create a couple of versions and reference them to each other # and reference them to the the scene and check if maya updates the # Version.references list versionBase = Version(**self.kwargs) versionBase.save() # change the take naem self.kwargs["take_name"] = "Take1" version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "Take2" version2 = Version(**self.kwargs) version2.save() self.kwargs["take_name"] = "Take3" version3 = Version(**self.kwargs) version3.save() # now create scenes with these files self.mEnv.save_as(version1) self.mEnv.save_as(version2) self.mEnv.save_as(version3) # this is the dummy version # create a new scene pm.newFile(force=True) # check if the versionBase.references is an empty list self.assertTrue(versionBase.references == []) # reference the given versions self.mEnv.reference(version1) self.mEnv.reference(version2) # save it as versionBase self.mEnv.save_as(versionBase) # clean scene pm.newFile(force=True) # re-open the file self.mEnv.open_(versionBase, force=True) self.mEnv.post_open(versionBase) # check if the references are loaded ref_data = self.mEnv.get_referenced_versions() for data in ref_data: ref_node = data[1] self.assertTrue(ref_node.isLoaded()) def test_save_as_in_another_project_updates_paths_correctly(self): """testing if the external paths are updated correctly if the document is created in one maya project but it is saved under another one. """ # create a new scene # save it under one Asset Version with name Asset1 asset1 = Asset(self.project, "Asset 1") asset1.save() self.kwargs["version_of"] = asset1 self.kwargs["base_name"] = asset1.code version1 = Version(**self.kwargs) version1.save() self.kwargs["take_name"] = "References1" version_ref1 = Version(**self.kwargs) version_ref1.save() self.kwargs["take_name"] = "References2" version_ref2 = Version(**self.kwargs) version_ref2.save() # save a maya file with this references self.mEnv.save_as(version_ref1) self.mEnv.save_as(version_ref2) # save the original version self.mEnv.save_as(version1) # create a couple of file textures file_texture1 = pm.createNode("file") file_texture2 = pm.createNode("file") path1 = os.path.dirname(version1.path) + "/.maya_files/TEXTURES/a.jpg" path2 = os.path.dirname(version1.path) + "/.maya_files/TEXTURES/b.jpg" # set them to some relative paths file_texture1.fileTextureName.set(path1) file_texture2.fileTextureName.set(path2) # create a couple of references in the same project self.mEnv.reference(version_ref1) self.mEnv.reference(version_ref2) # save again self.mEnv.save_as(version1) # then save it under another Asset with name Asset2 # because with this new system all the Assets folders are a maya # project, the references should be updated correctly asset2 = Asset(self.project, "Asset 2") asset2.save() # create a new Version for Asset 2 self.kwargs["version_of"] = asset2 self.kwargs["base_name"] = asset2.code version2 = Version(**self.kwargs) # now save it under that asset self.mEnv.save_as(version2) # check if the paths are updated self.assertEqual( file_texture1.fileTextureName.get(), "$REPO/TEST_PROJECT/Assets/Asset_1/.maya_files/TEXTURES/a.jpg") self.assertEqual( file_texture2.fileTextureName.get(), "$REPO/TEST_PROJECT/Assets/Asset_1/.maya_files/TEXTURES/b.jpg") def test_save_as_sets_the_fps(self): """testing if the save_as method sets the fps value correctly """ # create two projects with different fps values # first create a new scene and save it under the first project # and then save it under the other project # and check if the fps follows the project values project1 = Project("FPS_TEST_PROJECT_1") project1.fps = 24 project1.create() project2 = Project("FPS_TEST_PROJECT_2") project2.fps = 30 project2.save() # create assets asset1 = Asset(project1, "Test Asset 1") asset1.save() asset2 = Asset(project2, "Test Asset 2") asset2.save() # create versions version1 = Version(version_of=asset1, base_name=asset1.code, type=self.asset_vtypes[0], created_by=self.user1) version2 = Version(version_of=asset2, base_name=asset2.code, type=self.asset_vtypes[0], created_by=self.user1) # save the current scene for asset1 self.mEnv.save_as(version1) # check the fps value self.assertEqual(self.mEnv.get_fps(), 24) # now save it for asset2 self.mEnv.save_as(version2) # check the fps value self.assertEqual(self.mEnv.get_fps(), 30) def test_reference_creates_references_with_paths_starting_with_repository_env_key( self): """testing if reference method creates references with unresolved paths starting with conf.repository_env_key """ proj1 = Project("Test Project 1") proj1.create() proj1.save() asset1 = Asset(proj1, "Test Asset 1") asset1.save() vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers1.save() vers2 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers2.save() self.mEnv.save_as(vers1) pm.newFile(force=True) self.mEnv.save_as(vers2) # refence vers1 to vers2 self.mEnv.reference(vers1) # now check if the referenced files unresolved path is already starting # with conf.repository_env_key refs = pm.listReferences() # there should be only one reference self.assertEqual(len(refs), 1) # the unresolved path should start with $REPO self.assertTrue( refs[0].unresolvedPath().startswith("$" + conf.repository_env_key)) self.assertTrue(refs[0].isLoaded()) def test_reference_creates_references_to_Versions_in_other_workspaces_loaded( self): """testing if reference method creates references to Versions with different VersionType and the reference state will be loaded """ proj1 = Project("Test Project 1") proj1.create() proj1.save() asset1 = Asset(proj1, "Test Asset 1") asset1.save() vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1) vers1.save() vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1) vers2.save() self.mEnv.save_as(vers1) pm.newFile(force=True) self.mEnv.save_as(vers2) # refence vers1 to vers2 self.mEnv.reference(vers1) # now check if the referenced files unresolved path is already starting # with conf.repository_env_key refs = pm.listReferences() # there should be only one reference self.assertEqual(len(refs), 1) # the unresolved path should start with $REPO self.assertTrue( refs[0].unresolvedPath().startswith("$" + conf.repository_env_key)) self.assertTrue(refs[0].isLoaded()) def test_save_as_replaces_imagePlane_filename_with_env_variable(self): """testing if save_as replaces the imagePlane filename with repository environment variable """ # create a camera # create an image plane # set it to something # save the scene # check if the path is replaced with repository environment variable self.fail("test is not implemented yet") def test_save_as_creates_the_workspace_mel_file_in_the_given_path(self): """testing if save_as creates the workspace.mel file in the Asset or Shot root """ # check if the workspace.mel file does not exist yet workspace_mel_full_path = os.path.join( os.path.dirname(self.version1.path), 'workspace.mel') self.assertFalse(os.path.exists(workspace_mel_full_path)) self.mEnv.save_as(self.version1) self.assertTrue(os.path.exists(workspace_mel_full_path)) def test_save_as_creates_the_workspace_fileRule_folders(self): """testing if save_as creates the fileRule folders """ # first prove that the folders doesn't exist for key in pm.workspace.fileRules.keys(): file_rule_partial_path = pm.workspace.fileRules[key] file_rule_full_path = os.path.join( os.path.dirname(self.version1.path), file_rule_partial_path) self.assertFalse(os.path.exists(file_rule_full_path)) self.mEnv.save_as(self.version1) # save_as and now expect the folders to be created for key in pm.workspace.fileRules.keys(): file_rule_partial_path = pm.workspace.fileRules[key] file_rule_full_path = os.path.join( os.path.dirname(self.version1.path), file_rule_partial_path) self.assertTrue(os.path.exists(file_rule_full_path))