Skip to content

Commit

Permalink
Merge pull request #189 from mottosso/master
Browse files Browse the repository at this point in the history
Minor tweaks
  • Loading branch information
mottosso committed Jun 4, 2015
2 parents 1120820 + 3fc6ec2 commit 4efd8b7
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 18 deletions.
14 changes: 6 additions & 8 deletions pyblish/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def process(func, plugins, context, test=None):
A result per complete process. If test fails,
a TestFailed exception is returned, containing the
variables used in the test. Finally, any exception
thrown by `process` is yielded. Note that this is
thrown by `func` is yielded. Note that this is
considered a bug in *your* code as you are the one
supplying it.
Expand Down Expand Up @@ -130,22 +130,20 @@ def gen(plugin, instances):
continue

for instance in gen(plugin, instances):
print plugin, instance
if instance is None and "instance" in args:
continue

print "Made it"
# Provide introspection
self.next_instance = instance

try:
result = func(plugin, context, instance)

except Exception:
# If this happens, there is a bug
traceback.print_exc()
trace = traceback.format_exc()
assert False, trace
except Exception as exc:
# Any exception occuring within the function
# you pass is yielded, you are expected to
# handle it.
yield exc

else:
# Make note of the order at which
Expand Down
56 changes: 53 additions & 3 deletions tests/test_di.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ def process(self, context):
assert_equals(count["#"], 2)


@with_setup(lib.setup_empty, lib.teardown)
def test_unavailable_service():
"""Asking for unavailable service throws exception"""

Expand All @@ -199,6 +198,21 @@ def func(arg1, arg2):
assert_raises(KeyError, provider.invoke, func)


def test_unavailable_service_logic():
"""Asking for unavailable service ..?"""

class SelectUnavailable(pyblish.api.Selector):
def process(self, unavailable):
print "HHOH"
self.log.critical("Test")

for result in pyblish.logic.process(
func=pyblish.plugin.process,
plugins=[SelectUnavailable],
context=pyblish.api.Context()):
assert_true(isinstance(result["error"], KeyError))


@with_setup(lib.setup_empty, lib.teardown)
def test_test_failure():
"""Failing the test yields an exception"""
Expand Down Expand Up @@ -226,8 +240,8 @@ def process(self, context):
context=context))

assert_equals(len(triggered), 1)
assert type(triggered[0]) == ValidateFailure
assert isinstance(results[-1], Exception)
assert_equals(type(triggered[0]), ValidateFailure)
assert_true(isinstance(results[-1], Exception))


@with_setup(lib.setup_empty, lib.teardown)
Expand Down Expand Up @@ -314,3 +328,39 @@ def process(self, asset):
print result

assert_equals(count["#"], 3)


@with_setup(lib.setup_empty, lib.teardown)
def test_di_testing():
"""DI simplifies testing"""

instances = list()

class SelectCharacters(pyblish.api.Validator):
def process(self, context, host):
for char in host.ls("*_char"):
instance = context.create_instance(char, family="character")
instance.add(host.listRelatives(char))
instances.append(instance.name)

class HostMock(object):
def ls(self, query):
return ["bobby_char", "rocket_char"]

def listRelatives(self, node):
if node == "bobby_char":
return ["arm", "leg"]
if node == "rocket_char":
return ["propeller"]
return []

pyblish.api.register_service("host", HostMock())

for result in pyblish.logic.process(
func=pyblish.plugin.process,
plugins=[SelectCharacters],
context=pyblish.api.Context()):
assert_equals(result["error"], None)

assert_equals(len(instances), 2)
assert_equals(instances, ["bobby_char", "rocket_char"])
14 changes: 7 additions & 7 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ def process(self, context):
count["#"] += 1

context = pyblish.api.Context()
# for result in pyblish.logic.process(
# func=pyblish.plugin.process,
# plugins=[SelectMany, ValidateContext],
# context=context):
# pass
for result in pyblish.logic.process(
func=pyblish.plugin.process,
plugins=[SelectMany, ValidateContext],
context=context):
pass

# assert_equals(count["#"], 1)
assert_equals(count["#"], 1)

# count["#"] = 0
count["#"] = 0

# When families are wildcard, it does process
class ValidateContext(pyblish.api.Validator):
Expand Down

0 comments on commit 4efd8b7

Please sign in to comment.