mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
changed plugin filter to load presets from directory structure,
added tests
This commit is contained in:
parent
1f748ad0a2
commit
c1de475c58
5 changed files with 150 additions and 21 deletions
0
pype/tests/__init__.py
Normal file
0
pype/tests/__init__.py
Normal file
80
pype/tests/lib.py
Normal file
80
pype/tests/lib.py
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import tempfile
|
||||
import contextlib
|
||||
|
||||
import pyblish
|
||||
import pyblish.cli
|
||||
import pyblish.plugin
|
||||
from pyblish.vendor import six
|
||||
|
||||
|
||||
# Setup
|
||||
HOST = 'python'
|
||||
FAMILY = 'test.family'
|
||||
|
||||
REGISTERED = pyblish.plugin.registered_paths()
|
||||
PACKAGEPATH = pyblish.lib.main_package_path()
|
||||
ENVIRONMENT = os.environ.get("PYBLISHPLUGINPATH", "")
|
||||
PLUGINPATH = os.path.join(PACKAGEPATH, '..', 'tests', 'plugins')
|
||||
|
||||
|
||||
def setup():
|
||||
pyblish.plugin.deregister_all_paths()
|
||||
|
||||
|
||||
def setup_empty():
|
||||
"""Disable all plug-ins"""
|
||||
setup()
|
||||
pyblish.plugin.deregister_all_plugins()
|
||||
pyblish.plugin.deregister_all_paths()
|
||||
pyblish.plugin.deregister_all_hosts()
|
||||
pyblish.plugin.deregister_all_callbacks()
|
||||
pyblish.plugin.deregister_all_targets()
|
||||
pyblish.api.deregister_all_discovery_filters()
|
||||
|
||||
|
||||
def teardown():
|
||||
"""Restore previously REGISTERED paths"""
|
||||
|
||||
pyblish.plugin.deregister_all_paths()
|
||||
for path in REGISTERED:
|
||||
pyblish.plugin.register_plugin_path(path)
|
||||
|
||||
os.environ["PYBLISHPLUGINPATH"] = ENVIRONMENT
|
||||
pyblish.api.deregister_all_plugins()
|
||||
pyblish.api.deregister_all_hosts()
|
||||
pyblish.api.deregister_all_discovery_filters()
|
||||
pyblish.api.deregister_test()
|
||||
pyblish.api.__init__()
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def captured_stdout():
|
||||
"""Temporarily reassign stdout to a local variable"""
|
||||
try:
|
||||
sys.stdout = six.StringIO()
|
||||
yield sys.stdout
|
||||
finally:
|
||||
sys.stdout = sys.__stdout__
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def captured_stderr():
|
||||
"""Temporarily reassign stderr to a local variable"""
|
||||
try:
|
||||
sys.stderr = six.StringIO()
|
||||
yield sys.stderr
|
||||
finally:
|
||||
sys.stderr = sys.__stderr__
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def tempdir():
|
||||
"""Provide path to temporary directory"""
|
||||
try:
|
||||
tempdir = tempfile.mkdtemp()
|
||||
yield tempdir
|
||||
finally:
|
||||
shutil.rmtree(tempdir)
|
||||
41
pype/tests/test_pyblish_filter.py
Normal file
41
pype/tests/test_pyblish_filter.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
from . import lib
|
||||
import pyblish.api
|
||||
import pyblish.util
|
||||
import pyblish.plugin
|
||||
from pype.lib import filter_pyblish_plugins
|
||||
import os
|
||||
|
||||
|
||||
def test_pyblish_plugin_filter(printer, monkeypatch):
|
||||
"""
|
||||
Test if pyblish filter can filter and modify plugins on-the-fly.
|
||||
"""
|
||||
|
||||
lib.setup_empty()
|
||||
monkeypatch.setitem(os.environ, 'PYBLISHPLUGINPATH', '')
|
||||
plugins = pyblish.api.registered_plugins()
|
||||
printer("Test if we have no registered plugins")
|
||||
assert len(plugins) == 0
|
||||
paths = pyblish.api.registered_paths()
|
||||
printer("Test if we have no registered plugin paths")
|
||||
print(paths)
|
||||
|
||||
class MyTestPlugin(pyblish.api.InstancePlugin):
|
||||
my_test_property = 1
|
||||
label = "Collect Renderable Camera(s)"
|
||||
hosts = ["test"]
|
||||
families = ["default"]
|
||||
|
||||
pyblish.api.register_host("test")
|
||||
pyblish.api.register_plugin(MyTestPlugin)
|
||||
pyblish.api.register_discovery_filter(filter_pyblish_plugins)
|
||||
plugins = pyblish.api.discover()
|
||||
|
||||
printer("Test if only one plugin was discovered")
|
||||
assert len(plugins) == 1
|
||||
printer("Test if properties are modified correctly")
|
||||
assert plugins[0].label == "loaded from preset"
|
||||
assert plugins[0].families == ["changed", "by", "preset"]
|
||||
assert plugins[0].optional is True
|
||||
|
||||
lib.teardown()
|
||||
Loading…
Add table
Add a link
Reference in a new issue