def scene(): """Yield fixture for a mock scene.""" maya.cmds.file(new=True, f=True) jelly = PipelineHelper.getAsset('biff_jelly', zefir.STAGES.FX_SIMULATION, '999', '0010') generic_asset = PipelineHelper.getAsset('fx_generic_asset', zefir.STAGES.FX_SIMULATION, '999', '0010') fire_candles = PipelineHelper.getAsset('firecandles', zefir.STAGES.FX_SIMULATION, '999', '0010') scene = Scene(assets=[jelly, generic_asset, fire_candles]) yield scene
def test_add_remove_assets(self, mvc, scene): """Test adding and removing assets.""" model, _, controller = mvc controller.add_assets([]) # Test add empty assert not len(model.assets) controller.add_assets(scene.assets) # Test add assets assert len(model.assets) == len(scene.assets) # Test add non fx sim asset camera = PipelineHelper.getAsset('camera', zefir.STAGES.CAMERA_ANIMATION_DATA, '635', '0170') controller.add_assets([camera]) assert len(model.assets) == len(scene.assets) controller.remove_assets([]) # Test removing no assets assert len(model.assets) == len(scene.assets) controller.remove_assets([asset.name for asset in scene.assets[:1]]) # Test removing one asset assert len(model.assets) == len(scene.assets[1:]) controller.remove_assets([asset.name for asset in scene.assets[1:]]) # Test removing all assets assert len(model.assets) == 0 controller.remove_assets(scene.assets) # Test removing non loaded assets assert len(model.assets) == 0
def test_init(self, mvc): """Test tool initialization.""" model, _, controller = mvc assert model.assets == {} assert model.user == PipelineHelper.getCurrentUser() assert controller.valid
def test_commit_locally(self, mvc, scene, mocker): """Test committing data locally.""" model, view, controller = mvc controller.add_assets([scene.assets[0]]) asset_name = scene.assets[0].name data = model.assets[asset_name] data.commit_to_fx_cache = True data.generate_alembic_from_geos = True seq, shot = 999, 10 mocker.patch.object(PipelineHelper, 'getCurrentSeqShot', mocker.MagicMock(return_value=(seq, shot))) frame_in, frame_out = 10, 20 mocker.patch.object( PipelineHelper, 'getShotFrameRange', mocker.MagicMock(return_value=(frame_in, frame_out))) cache_path = '/home/mathiasc/tmp' mocker.patch.object(PipelineHelper, 'getCachePath', mocker.MagicMock(return_value=cache_path)) existing_alembic_mock = mocker.MagicMock(return_value="Overwrite") mocker.patch.object(view, 'dialog', existing_alembic_mock) context_mock = mocker.MagicMock() mocker.patch.object(PipelineHelper, 'getContext', mocker.MagicMock(return_value=context_mock)) maya_commit_mock = mocker.MagicMock() maya_commit_mock.create_new_revision = mocker.MagicMock( return_value=maya_commit_mock) mocker.patch( 'nwave.effects.tools.nwFenixCommitter.Controller.MayaCommit', new=mocker.MagicMock(return_value=maya_commit_mock)) component_mock = mocker.MagicMock() context_mock.find_shot_instance_component.return_value = component_mock # Test locked fx cache component component_mock.is_locked = True component_mock.locking_user = mocker.MagicMock(common_name='nobody') assert not controller.commit_locally(data) component_mock.is_locked = False box = mc.polyCube()[0] box = mc.parent(box, PipelineHelper.getAssetEffectsNode(scene.assets[0])) maya_commit_mock.reset_mock() assert controller.commit_locally(data) # Test commit to fx_cache and alembic_anim assert maya_commit_mock.commit.call_count == 2
def test_commit_sanity_no_effects_node(self, mvc, scene, mocker): """Test data verfication prior to committing.""" model, _, controller = mvc controller.add_assets([scene.assets[0]]) asset_name = scene.assets[0].name data = model.assets[asset_name] # Test no effect node (import asset, delete effect node, run method) effects_node = PipelineHelper.getAssetEffectsNode(data.asset) ref_file = mc.referenceQuery(effects_node, f=True) mc.file(ref_file, importReference=True) mc.delete(effects_node) assert not controller.commit_sanity_check(data)
def test_get_alembic_effect_meshes(self, mvc, scene): """Test getting meshes in effects group.""" _, _, controller = mvc # Test add non fx sim asset camera = PipelineHelper.getAsset('camera', zefir.STAGES.CAMERA_ANIMATION_DATA, '635', '0170') with pytest.raises(ValueError): controller.get_alembic_from_geo_meshes(camera) # Test error when no effects node scene.assets[0].import_from_reference() effects_node = scene.assets[0].get_effects_node() mc.delete(effects_node.longName()) with pytest.raises(ValueError): controller.get_alembic_from_geo_meshes(scene.assets[0]) # Test reporting of shape deform scene.assets[1].import_from_reference() box = mc.polyCube()[0] mc.rename(mc.listRelatives(box, shapes=True)[0], 'boxShapeDeformed') effects_node = scene.assets[1].get_effects_node() mc.parent(box, str(effects_node)) assert controller.get_alembic_from_geo_meshes(scene.assets[1]) is None # Test no geo nodes scene.assets[2].import_from_reference() assert controller.get_alembic_from_geo_meshes(scene.assets[2]) is None # Test geo nodes effects_node = scene.assets[2].get_effects_node() nodes = [mc.polyCube()[0], mc.polySphere()[0]] mc.parent(nodes, str(effects_node)) assert controller.get_alembic_from_geo_meshes(scene.assets[2]) == [ mc.listRelatives(node, shapes=True, fullPath=True)[0] for node in nodes ]
def test_commit_sanity_duplicate_name(self, mvc, scene, mocker): """Test data verfication prior to committing.""" model, _, controller = mvc controller.add_assets([scene.assets[0]]) asset_name = scene.assets[0].name data = model.assets[asset_name] # Test duplicate node names (create 2 boxes with same name in different # groups, parent groups under effect node, run method) top_parent = mc.group(em=True) sub_parent_1 = mc.group(em=True) sub_parent_1 = mc.parent(sub_parent_1, top_parent) sub_parent_2 = mc.group(em=True) sub_parent_2 = mc.parent(sub_parent_2, top_parent) box_1 = mc.polyCube()[0] box_1 = mc.parent(box_1, sub_parent_1) box_1 = mc.rename(box_1, 'pCube1') box_2 = mc.polyCube()[0] box_2 = mc.parent(box_2, sub_parent_2) box_2 = mc.rename(box_2, 'pCube1') effects_node = PipelineHelper.getAssetEffectsNode(data.asset) mc.parent(top_parent, effects_node) assert not controller.commit_sanity_check(data)
def test_generate_effect_alembic(self, mvc, scene, mocker): """Test generating clean geometries via an alembic cache.""" model, view, controller = mvc seq, shot = 999, 10 mocker.patch.object(PipelineHelper, 'getCurrentSeqShot', mocker.MagicMock(return_value=(seq, shot))) frame_in, frame_out = 10, 20 mocker.patch.object( PipelineHelper, 'getShotFrameRange', mocker.MagicMock(return_value=(frame_in, frame_out))) existing_alembic_mock = mocker.MagicMock(return_value="Overwrite") mocker.patch.object(view, 'dialog', existing_alembic_mock) mocker.spy(controller, 'cache_geometries') mocker.spy(controller, 'export_alembic') mocker.spy(controller, 'update_geometries') mocker.spy(controller, 'remove_alembic_file') controller.add_assets([scene.assets[0]]) asset = model.assets[scene.assets[0].name] controller.generate_effect_alembic(asset) # Test cache command frame range assert model.frame_in == frame_in assert model.frame_out == frame_out mo_blur_in, mo_blur_out = get_setting_value( MOTION_BLUR_SAMPLES_SETTING, asset.asset.get_maya_commit()) assert model.motion_blur_in == mo_blur_in assert model.motion_blur_out == mo_blur_out # test no geo in in effects group assert not controller.export_alembic.called effects_node = PipelineHelper.getAssetEffectsNode(scene.assets[0]) box = mc.polyCube()[0] box = mc.parent(box, effects_node) controller.generate_effect_alembic(asset) # test alembic export assert controller.export_alembic.called args = controller.export_alembic.call_args[0] assert len(args) == 3 path, nodes, local_space = args # Test output path assert PipelineHelper.getCachePath(seq, shot) in path assert 'alembic' in path assert asset.asset.name[:asset.asset.name.find(':')] in path # Test geo nodes assert mc.listRelatives(box, shapes=True, fullPath=True)[0] in nodes # Test local space assert asset.use_local_space_for_alembic == local_space # Test alembic import assert controller.update_geometries.called # Test cache geo assert controller.cache_geometries.called # test exisiting alembic options existing_alembic_mock.return_value = 'Re-use' controller.export_alembic.reset_mock() controller.update_geometries.reset_mock() controller.cache_geometries.reset_mock() assert controller.generate_effect_alembic(asset) assert not controller.export_alembic.called assert not controller.cache_geometries.called assert controller.update_geometries.called existing_alembic_mock.return_value = 'Overwrite' controller.export_alembic.reset_mock() controller.update_geometries.reset_mock() controller.remove_alembic_file.reset_mock() controller.cache_geometries.reset_mock() assert controller.generate_effect_alembic(asset) assert controller.export_alembic.called assert controller.update_geometries.called assert controller.remove_alembic_file.called assert controller.cache_geometries.called existing_alembic_mock.return_value = 'Cancel' controller.export_alembic.reset_mock() controller.update_geometries.reset_mock() controller.remove_alembic_file.reset_mock() controller.cache_geometries.reset_mock() assert not controller.generate_effect_alembic(asset) assert not controller.export_alembic.called assert not controller.update_geometries.called assert not controller.remove_alembic_file.called assert not controller.cache_geometries.called existing_alembic_mock.return_value = '' controller.export_alembic.reset_mock() controller.update_geometries.reset_mock() controller.remove_alembic_file.reset_mock() controller.cache_geometries.reset_mock() assert not controller.generate_effect_alembic(asset) assert not controller.export_alembic.called assert not controller.update_geometries.called assert not controller.remove_alembic_file.called assert not controller.cache_geometries.called