Skip to content

Commit

Permalink
Merge pull request #292 from pscadding/master
Browse files Browse the repository at this point in the history
Feature - Added callback pluginProcessed
  • Loading branch information
mottosso authored Aug 18, 2016
2 parents 4c22714 + b2327e0 commit 9a56cf2
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ danielottosson2@gmail.com
https://github.com/davidmartinezanim
https://github.com/tokejepsen
https://github.com/bigroy
https://github.com/mkolar
https://github.com/mkolar
https://github.com/pscadding
7 changes: 5 additions & 2 deletions pyblish/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,12 @@ def process(plugin, context, instance=None, action=None):
"""

if issubclass(plugin, (ContextPlugin, InstancePlugin)):
return __explicit_process(plugin, context, instance, action)
result = __explicit_process(plugin, context, instance, action)
else:
return __implicit_process(plugin, context, instance, action)
result = __implicit_process(plugin, context, instance, action)

lib.emit("pluginProcessed", result=result)
return result


def __explicit_process(plugin, context, instance=None, action=None):
Expand Down
76 changes: 76 additions & 0 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,79 @@ def on_validated(context):
pyblish.util.validate()

assert count["#"] == 1, count

@with_setup(lib.setup_empty)
def test_plugin_processed_event():
"""pluginProcessed is emitted upon a plugin being processed, regardless of its success"""

class MyContextCollector(pyblish.api.ContextPlugin):
order = pyblish.api.CollectorOrder

def process(self, context):
context.create_instance("A")

class CheckInstancePass(pyblish.api.InstancePlugin):
order = pyblish.api.ValidatorOrder

def process(self, instance):
pass

class CheckInstanceFail(pyblish.api.InstancePlugin):
order = pyblish.api.ValidatorOrder

def process(self, instance):
raise Exception("Test Fail")

pyblish.api.register_plugin(MyContextCollector)
pyblish.api.register_plugin(CheckInstancePass)
pyblish.api.register_plugin(CheckInstanceFail)


count = {"#": 0}

def on_processed(result):
assert isinstance(result, dict)
count["#"] += 1

pyblish.api.register_callback("pluginProcessed", on_processed)
pyblish.util.publish()

assert count["#"] == 3, count

@with_setup(lib.setup_empty)
def test_plugin_failed_event():
"""pluginFailed is emitted upon a plugin failing for any reason"""

class MyContextCollector(pyblish.api.ContextPlugin):
order = pyblish.api.CollectorOrder
def process(self, context):
context.create_instance("A")

class CheckInstancePass(pyblish.api.InstancePlugin):
order = pyblish.api.ValidatorOrder
def process(self, instance):
pass

class CheckInstanceFail(pyblish.api.InstancePlugin):
order = pyblish.api.ValidatorOrder
def process(self, instance):
raise Exception("Test Fail")

pyblish.api.register_plugin(MyContextCollector)
pyblish.api.register_plugin(CheckInstancePass)
pyblish.api.register_plugin(CheckInstanceFail)

count = {"#": 0}

def on_failed(plugin, context, instance, error):
assert issubclass(plugin, pyblish.api.InstancePlugin) #plugin == CheckInstanceFail
assert isinstance(context, pyblish.api.Context)
assert isinstance(instance, pyblish.api.Instance)
assert isinstance(error, Exception)

count["#"] += 1

pyblish.api.register_callback("pluginFailed", on_failed)
pyblish.util.publish()

assert count["#"] == 1, count

0 comments on commit 9a56cf2

Please sign in to comment.