コード例 #1
0
def test_reset():
    """Resetting works the way you'd expect"""

    count = {"#": 0}

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

        def process(self, context):
            context.create_instance("MyInstance")
            count["#"] += 1

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

        def process(self, instance):
            count["#"] += 11

    for plugin in [MyCollector, MyValidator]:
        pyblish.api.register_plugin(plugin)

    ctrl = control.Controller()
    ctrl.reset()

    assert count["#"] == 1
コード例 #2
0
def test_publish_disabled():
    """Only active instances are published"""

    count = {"#": 0}

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

        def process(self, context):
            context.create_instance("A", publish=False)
            context.create_instance("B", publish=True)
            count["#"] += 1

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

        def process(self, instance):
            count["#"] += 10

    for plugin in [MyCollector, MyValidator]:
        pyblish.api.register_plugin(plugin)

    ctrl = control.Controller()
    ctrl.reset()

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

    ctrl.publish()

    assert count["#"] == 11, count
コード例 #3
0
def test_far_negative_orders():
    """Orders may go below 0"""

    count = {"#": 0}

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

    class MyCollector2(pyblish.api.ContextPlugin):
        order = -1

    class MyCollector3(pyblish.api.ContextPlugin):
        order = -1000

    def process(self, context):
        count["#"] += 1

    MyCollector1.process = process
    MyCollector2.process = process
    MyCollector3.process = process

    pyblish.api.register_plugin(MyCollector1)
    pyblish.api.register_plugin(MyCollector2)
    pyblish.api.register_plugin(MyCollector3)

    ctrl = control.Controller()
    ctrl.reset()

    # They all register as Collectors
    assert count["#"] == 3, count
コード例 #4
0
def test_publish_inactive():
    """Only active plugins are published"""

    count = {"#": 0}

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

        def process(self, context):
            print(type(self))
            count["#"] += 1

    class Inactive(pyblish.api.ContextPlugin):
        order = pyblish.api.CollectorOrder
        active = False

        def process(self, context):
            print(type(self))
            count["#"] += 10

    for plugin in [Active, Inactive]:
        pyblish.api.register_plugin(plugin)

    ctrl = control.Controller()
    ctrl.reset()

    assert count["#"] == 1, count
コード例 #5
0
def test_controller_signals():
    """was_finished emitted on completing any process

    Any process, such as resetting, validating,
    actuating and publishing.

    """

    count = {
        "was_reset": 0,
        "was_validated": 0,
        "was_published": 0,
        "was_finished": 0,
    }

    def on_signal(signal):
        count[signal] += 1

    ctrl = control.Controller()

    ctrl.was_reset.connect(lambda: on_signal("was_reset"))
    ctrl.was_validated.connect(lambda: on_signal("was_validated"))
    ctrl.was_published.connect(lambda: on_signal("was_published"))
    ctrl.was_finished.connect(lambda: on_signal("was_finished"))

    ctrl.reset()

    assert_equals(count, {
        "was_reset": 1,
        "was_validated": 0,
        "was_published": 0,
        "was_finished": 1,
    })

    ctrl.validate()

    assert_equals(count, {
        "was_reset": 1,
        "was_validated": 1,
        "was_published": 0,
        "was_finished": 2,
    })

    ctrl.publish()

    assert_equals(count, {
        "was_reset": 1,
        "was_validated": 1,
        "was_published": 1,
        "was_finished": 3,
    })
コード例 #6
0
def test_something():
    """Anything runs"""
    count = {"#": 0}

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

        def process(self, context):
            count["#"] += 1

    pyblish.api.register_plugin(MyCollector)

    ctrl = control.Controller()
    ctrl.reset()

    assert count["#"] == 1
コード例 #7
0
def test_order_20():
    """Orders beyond CVEI should still run"""

    count = {"#": 0}

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

        def process(self, context):
            instance = context.create_instance("MyInstance")
            instance.data["families"] = ["myFamily"]
            count["#"] += 1

    class OldValidator(pyblish.api.Validator):
        """Old-style plug-in, not using InstancePlugin"""

        families = ["myFamily"]
        order = 20

        def process(self, instance):
            count["#"] += 10

    class NewValidator(pyblish.api.InstancePlugin):
        families = ["myFamily"]
        order = 20

        def process(self, instance):
            count["#"] += 100

    pyblish.api.register_plugin(MyCollector)
    pyblish.api.register_plugin(OldValidator)
    pyblish.api.register_plugin(NewValidator)

    ctrl = control.Controller()
    ctrl.reset()

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

    ctrl.publish()

    assert count["#"] == 111, count
コード例 #8
0
def test_publish_families():
    """Only supported families are published"""

    count = {"#": 0}

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

        def process(self, context):
            context.create_instance("MyInstance", families=["myFamily"])
            print(type(self))
            count["#"] += 1

    class Supported(pyblish.api.InstancePlugin):
        order = pyblish.api.ValidatorOrder
        families = ["myFamily"]

        def process(self, instance):
            print(type(self))
            count["#"] += 10

    class Unsupported(pyblish.api.InstancePlugin):
        order = pyblish.api.ValidatorOrder
        families = ["unsupported"]

        def process(self, instance):
            print(type(self))
            count["#"] += 100

    for plugin in [MyCollector, Supported, Unsupported]:
        pyblish.api.register_plugin(plugin)

    ctrl = control.Controller()
    ctrl.reset()

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

    ctrl.publish()

    assert count["#"] == 11, count
コード例 #9
0
def test_logging_nonstring():
    """Logging things that aren't string is fine"""
    count = {"#": 0}

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

        def process(self, context):
            self.log.info({"A dictionary is": "fine"})
            self.log.info(12)
            self.log.info(True)
            self.log.info(1.0)
            self.log.info(["a list"])
            self.log.info(("a", "list"))
            self.log.info(set(["a", "list"]))
            count["#"] += 1

    pyblish.api.register_plugin(MyCollector)

    ctrl = control.Controller()
    ctrl.reset()

    assert count["#"] == 1
コード例 #10
0
def test_publish():
    """Publishing works the way you'd expect"""

    count = {"#": 0}

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

        def process(self, context):
            context.create_instance("MyInstance")
            print(type(self))
            count["#"] += 1

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

        def process(self, instance):
            print(type(self))
            count["#"] += 10

    for plugin in [MyCollector, MyValidator]:
        pyblish.api.register_plugin(plugin)

    ctrl = control.Controller()
    ctrl.reset()

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

    ctrl.publish()

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

    # There are no more items in the queue at this point,
    # so publishing again should do nothing.
    ctrl.publish()

    assert count["#"] == 11, count
コード例 #11
0
ファイル: pyblish_lite_nuke.py プロジェクト: tws0002/Nuke-2
    def __init__(self, parent=None):
        if self._is_initiated:
            return

        controller = control.Controller()
        controller.was_processed.connect(_handle_result)
        super(Window, self).__init__(
            controller, parent)

        self.resize(*settings.WindowSize)
        self.setWindowTitle(settings.WindowTitle)

        with open(e(filetools.module_path("pyblish_lite.css"))) as f:
            css = u(f.read())

            # Make relative paths absolute
            root = util.get_asset("").replace("\\", "/")
            css = css.replace("url(\"", "url(\"%s" % root)
        self.setStyleSheet(css.encode('utf-8'))

        self.setObjectName('PyblishWindow')
        self.setAttribute(Qt.WA_DeleteOnClose, True)

        self._is_initiated = True