Skip to content

Commit

Permalink
Merge pull request #167 from mottosso/master
Browse files Browse the repository at this point in the history
1.0.14
  • Loading branch information
mottosso committed Mar 27, 2015
2 parents 0b84e58 + 5ae5d2b commit 512c8cc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ pyblish Changelog

This contains all major version changes between pyblish releases.

Version 1.0.14
--------------

- Added pyblish.api.version
- Matched verbosity level from processing context as the processing of instances.
- Processing logic change; processing of plug-in *without* compatible instances will now *not* yield anything; previously it yielded a pair of (None, None).

Version 1.0.13
--------------

Expand Down
5 changes: 3 additions & 2 deletions pyblish/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"initializing configuration")

config = pyblish.config

version = pyblish.version

__all__ = [
# Base objects
Expand All @@ -84,13 +84,14 @@
"plugins_by_host",
"instances_by_plugin",
"sort_plugins",
"format_filename",

# Configuration
"config",
"version",

# Decorators
"log",
"format_filename",

# Exceptions
"PyblishError",
Expand Down
14 changes: 8 additions & 6 deletions pyblish/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,20 @@ def process(self, context, instances=None):
self.process_context(context)

except Exception as err:
self.log.error("Could not process context: "
"%s: %s" % (context, err))
try:
_, _, exc_tb = sys.exc_info()
err.traceback = traceback.extract_tb(
exc_tb)[-1]
except:
pass

yield None, err

finally:
compatible_instances = instances_by_plugin(
instances=context, plugin=self)

if not compatible_instances:
yield None, None

else:
if compatible_instances:
for instance in compatible_instances:
# Limit instances to those specified in `instances`
if instances is not None and \
Expand Down
49 changes: 48 additions & 1 deletion pyblish/tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from pyblish.tests.lib import (
setup_full, teardown)
from pyblish.vendor.nose.tools import with_setup
from pyblish.vendor.nose.tools import *

# Setup
HOST = 'python'
Expand Down Expand Up @@ -81,5 +81,52 @@ def test_limited_to_instances():
if name == "Instance02":
assert inst.data('validated', False) is False


def test_failing_context():
"""Context processing yields identical information to instances"""

class SelectFailure(pyblish.api.Selector):
def process_context(self, context):
raise pyblish.api.SelectionError("I was programmed to fail")

ctx = pyblish.api.Context()

for instance, error in SelectFailure().process(ctx):
assert_true(error is not None)
assert_true(hasattr(error, "traceback"))
assert_true(error.traceback is not None)


def test_failing_validator():
"""All plug-ins yield both context and instance exceptions"""
class ValidateFailure(pyblish.api.Validator):
families = ["test"]

def process_context(self, context):
raise pyblish.api.ValidationError("context failed")

def process_instance(self, instance):
raise pyblish.api.ValidationError("instance failed")

ctx = pyblish.api.Context()
instance = ctx.create_instance("MyInstance")
instance.set_data("family", "test")

# Context is always processed first
processor = ValidateFailure().process(ctx)
instance, error = processor.next()
assert_equal(error.message, "context failed")
assert_true(hasattr(error, "traceback"))

# Next up is the instance
instance, error = processor.next()
assert_equal(error.message, "instance failed")
assert_true(hasattr(error, "traceback"))
assert_equal(instance.name, "MyInstance")

# Nothing else is yeilded
assert_raises(StopIteration, processor.next)


if __name__ == '__main__':
test_add_remove_instances()

0 comments on commit 512c8cc

Please sign in to comment.