Skip to content

Instantly share code, notes, and snippets.

@davidlatwe
Created November 5, 2017 09:48
Show Gist options
  • Save davidlatwe/f1b354e185bf62558aae2826b040fefb to your computer and use it in GitHub Desktop.
Save davidlatwe/f1b354e185bf62558aae2826b040fefb to your computer and use it in GitHub Desktop.
Pyblish Test Case - Enable Publishing Continues with Validation Error
import pyblish.api
import pyblish.util
disk = {}
items = ["John.Boy.Person"]
class CollectInstances(pyblish.api.ContextPlugin):
order = 0
def process(self, context):
for item in items:
name, gender, family = item.split(".")
instance = context.create_instance(name)
instance.data["families"] = [family]
instance.data["gender"] = gender
class ValidateNamingConvention(pyblish.api.InstancePlugin):
order = 1
families = ["Person"]
def process(self, instance):
name = instance.data["name"]
assert name == name.title(), "Sorry, %s should have been %s" % (
name, name.title())
class ValidatePersonIsGirl(pyblish.api.InstancePlugin):
order = 1.4
optional = True
families = ["Person"]
def process(self, instance):
gender = instance.data["gender"]
assert gender == "Girl", "Sorry, Need a Girl but %s is %s" % (
instance, gender)
class ExtractInstances(pyblish.api.InstancePlugin):
order = 2
families = ["Person"]
def process(self, instance):
disk[instance.data["name"]] = instance
pyblish.api.register_plugin(CollectInstances)
pyblish.api.register_plugin(ValidateNamingConvention)
pyblish.api.register_plugin(ValidatePersonIsGirl)
pyblish.api.register_plugin(ExtractInstances)
pyblish.util.publish()
print("John" in disk)
# True
@davidlatwe
Copy link
Author

davidlatwe commented Nov 5, 2017

Test case for https://gist.github.com/davidlatwe/385e69d63cee0f110b5fb1babf696526

Scenario : "John is a boy, but we can accept that John is a girl for now."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment