def test_subset_match(): """Plugin.match = api.Subset works as expected""" count = {"#": 0} class MyPlugin(api.InstancePlugin): families = ["a", "b"] match = api.Subset def process(self, instance): count["#"] += 1 context = api.Context() context.create_instance("not_included_1", families=["a"]) context.create_instance("not_included_1", families=["x"]) context.create_instance("included_1", families=["a", "b"]) context.create_instance("included_2", families=["a", "b", "c"]) util.publish(context, plugins=[MyPlugin]) assert_equals(count["#"], 2) instances = logic.instances_by_plugin(context, MyPlugin) assert_equals(list(i.name for i in instances), ["included_1", "included_2"])
def test_multiple_instance_util_publish(): """Multiple instances work with util.publish() This also ensures it operates correctly with an InstancePlugin collector. """ count = {"#": 0} class MyContextCollector(api.ContextPlugin): order = api.CollectorOrder def process(self, context): context.create_instance("A") context.create_instance("B") count["#"] += 1 class MyInstancePluginCollector(api.InstancePlugin): order = api.CollectorOrder + 0.1 def process(self, instance): count["#"] += 1 api.register_plugin(MyContextCollector) api.register_plugin(MyInstancePluginCollector) # Ensure it runs without errors util.publish() assert count["#"] == 3
def test_subset_exact(): """Plugin.match = api.Exact works as expected""" count = {"#": 0} class MyPlugin(api.InstancePlugin): families = ["a", "b"] match = api.Exact def process(self, instance): count["#"] += 1 context = api.Context() context.create_instance("not_included_1", families=["a"]) context.create_instance("not_included_1", families=["x"]) context.create_instance("not_included_3", families=["a", "b", "c"]) instance = context.create_instance("included_1", families=["a", "b"]) # Discard the solo-family member, which defaults to `default`. # # When using multiple families, it is common not to bother modifying # `family`, and in the future this member needn't be there at all and # may/should be removed. But till then, for complete clarity, it might # be worth removing this explicitly during the creation of instances # if instead choosing to use the `families` key. instance.data.pop("family") util.publish(context, plugins=[MyPlugin]) assert_equals(count["#"], 1) instances = logic.instances_by_plugin(context, MyPlugin) assert_equals(list(i.name for i in instances), ["included_1"])
def test_subset_exact(): """Plugin.match = api.Exact works as expected""" count = {"#": 0} class MyPlugin(api.InstancePlugin): families = ["a", "b"] match = api.Exact def process(self, instance): count["#"] += 1 context = api.Context() context.create_instance("not_included_1", families=["a"]) context.create_instance("not_included_1", families=["x"]) context.create_instance("not_included_3", families=["a", "b", "c"]) instance = context.create_instance("included_1", families=["a", "b"]) # Discard the solo-family member, which defaults to `default`. # # When using multiple families, it is common not to bother modifying `family`, # and in the future this member needn't be there at all and may/should be # removed. But till then, for complete clarity, it might be worth removing # this explicitly during the creation of instances if instead choosing to # use the `families` key. instance.data.pop("family") util.publish(context, plugins=[MyPlugin]) assert_equals(count["#"], 1) instances = logic.instances_by_plugin(context, MyPlugin) assert_equals(list(i.name for i in instances), ["included_1"])
def test_publishing_explicit_targets_with_global(): """Publishing with explicit and globally registered targets works""" count = {"#": 0} class Plugin1(api.ContextPlugin): targets = ["custom"] def process(self, context): count["#"] += 1 class Plugin2(api.ContextPlugin): targets = ["foo"] def process(self, context): count["#"] += 10 api.register_target("foo") api.register_target("custom") api.register_plugin(Plugin1) api.register_plugin(Plugin2) util.publish(targets=["custom"]) assert count["#"] == 1, count assert api.registered_targets() == ["foo", "custom"] api.deregister_all_targets()
def test_per_session_targets(): """Register targets per session works""" util.publish(targets=["custom"]) registered_targets = api.registered_targets() assert registered_targets == [], registered_targets
def filemenu_handler(event): if event == "publish": try: pyblish_maya.show() except: exc_type, exc_value, exc_traceback = sys.exc_info() message = "".join(traceback.format_exception( exc_type, exc_value, exc_traceback)) sys.stderr.write("Tried launching GUI, but failed.\n") sys.stderr.write("Message was:") sys.stderr.write(message) sys.stderr.write("Publishing in headless mode instead.\n") util.publish()
def test_publishing_explicit_targets(): """Publishing with explicit targets works""" count = {"#": 0} class plugin(api.ContextPlugin): targets = ["custom"] def process(self, context): count["#"] += 1 api.register_plugin(plugin) util.publish(targets=["custom"]) assert count["#"] == 1, count
def test_publishing_targets(): """Publishing with targets works""" count = {"#": 0} class plugin(api.ContextPlugin): targets = ["custom"] def process(self, context): count["#"] += 1 api.register_plugin(plugin) util.publish(targets=["custom"]) assert count["#"] == 1, count
def process_targets_royalrender_silent(): register_process_plugins() register_process_royalrender_plugins() context = util.publish(targets=["process", "process.royalrender"]) feedback_context(context)
def test_extracted_traceback_contains_correct_backtrace(): api.register_plugin_path(os.path.dirname(__file__)) context = api.Context() context.create_instance('test instance') plugins = api.discover() plugins = [p for p in plugins if p.__name__ in ('FailingExplicitPlugin', 'FailingImplicitPlugin')] util.publish(context, plugins) for result in context.data['results']: assert result["error"].traceback[0] == plugins[0].__module__ formatted_tb = result['error'].formatted_traceback assert formatted_tb.startswith('Traceback (most recent call last):\n') assert formatted_tb.endswith('\nException: A test exception\n') assert 'File "{0}",'.format(plugins[0].__module__) in formatted_tb
def publish(): """Shorthand to publish from within host""" from pyblish import util return util.publish()
def process_targets_local_silent(): register_process_plugins() context = util.publish(targets=["process", "process.local"]) feedback_context(context)