Exemple #1
0
def test_asset():
    """Using asset over instance works fine"""
    context = pyblish.plugin.Context()

    asseta = context.create_asset("MyAssetA", family="myFamily")
    assetb = context.create_asset("MyAssetB", family="myFamily")

    assert_true(asseta in context)
    assert_true(assetb in context)
Exemple #2
0
def test_asset():
    """Using asset over instance works fine"""
    context = pyblish.plugin.Context()

    asseta = context.create_asset("MyAssetA", family="myFamily")
    assetb = context.create_asset("MyAssetB", family="myFamily")

    assert_true(asseta in context)
    assert_true(assetb in context)
Exemple #3
0
def test_unique_id():
    """Plug-ins and instances have a unique id"""

    class MyPlugin(pyblish.plugin.Selector):
        pass

    assert_true(hasattr(MyPlugin, "id"))

    instance = pyblish.plugin.Instance("MyInstance")
    assert_true(hasattr(instance, "id"))
Exemple #4
0
def test_unique_id():
    """Plug-ins and instances have a unique id"""

    class MyPlugin(pyblish.plugin.Selector):
        pass

    assert_true(hasattr(MyPlugin, "id"))

    instance = pyblish.plugin.Instance("MyInstance")
    assert_true(hasattr(instance, "id"))
Exemple #5
0
def test_legacy():
    """Legacy is determined by existing process_* methods"""
    class LegacyPlugin(pyblish.plugin.Selector):
        def process_context(self, context):
            pass

    class NotLegacyPlugin(pyblish.plugin.Selector):
        def process(self, context):
            pass

    assert_true(hasattr(LegacyPlugin, "__pre11__"))
    assert_equals(LegacyPlugin.__pre11__, True)
    assert_true(hasattr(NotLegacyPlugin, "__pre11__"))
    assert_equals(NotLegacyPlugin.__pre11__, False)
Exemple #6
0
def test_legacy():
    """Legacy is determined by existing process_* methods"""
    class LegacyPlugin(pyblish.plugin.Selector):
        def process_context(self, context):
            pass

    class NotLegacyPlugin(pyblish.plugin.Selector):
        def process(self, context):
            pass

    assert_true(hasattr(LegacyPlugin, "__pre11__"))
    assert_equals(LegacyPlugin.__pre11__, True)
    assert_true(hasattr(NotLegacyPlugin, "__pre11__"))
    assert_equals(NotLegacyPlugin.__pre11__, False)
Exemple #7
0
def test_discover_globals():
    """Modules imported in a plug-in are preserved in it's methods"""

    import types

    module = types.ModuleType("myplugin")
    code = """
import pyblish.api
import threading

local_variable_is_present = 5


class MyPlugin(pyblish.api.Plugin):
    def module_is_present(self):
        return True if threading else False

    def local_variable_is_present(self):
        return True if local_variable_is_present else False

    def process(self, context):
        return True if context else False

"""

    exec code in module.__dict__
    MyPlugin = pyblish.plugin.plugins_from_module(module)[0]
    assert MyPlugin.id == "MyPlugin"

    assert_true(MyPlugin().process(True))
    assert_true(MyPlugin().module_is_present())
    assert_true(MyPlugin().local_variable_is_present())

    try:
        tempdir = tempfile.mkdtemp()
        tempplugin = os.path.join(tempdir, "my_plugin.py")
        with open(tempplugin, "w") as f:
            f.write(code)

        pyblish.api.register_plugin_path(tempdir)
        plugins = pyblish.api.discover()

    finally:
        shutil.rmtree(tempdir)

    assert len(plugins) == 1

    MyPlugin = plugins[0]

    assert_true(MyPlugin().process(True))
    assert_true(MyPlugin().module_is_present())
    assert_true(MyPlugin().local_variable_is_present())