Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support- new path type in-plugin-registration by converting to string… #377

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pyblish/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,10 @@ def register_plugin_path(path):

"""

# accept pathlib paths and convert to string
if hasattr(path, "as_posix"):
path = path.as_posix()

normpath = os.path.normpath(path)
if normpath in _registered_paths:
return log.warning("Path already registered: {0}".format(path))
Expand Down
2 changes: 1 addition & 1 deletion pyblish/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

VERSION_MAJOR = 1
VERSION_MINOR = 8
VERSION_PATCH = 9
VERSION_PATCH = 10

version_info = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)
version = '%i.%i.%i' % version_info
Expand Down
39 changes: 39 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import logging

Expand All @@ -13,8 +16,15 @@
raises,
)

try:
import pathlib
except:
pathlib = None

from . import lib

import unittest


@with_setup(lib.setup_empty, lib.teardown)
def test_unique_id():
Expand Down Expand Up @@ -490,6 +500,35 @@ class MyPlugin(pyblish.plugin.Collector):
pyblish.plugin.register_plugin(MyPlugin)


@unittest.skipIf(pathlib is None, "skip when pathlib is not available")
def test_register_plugin_path():
"""test various types of input for plugin path registration"""

# helper function
@with_setup(lib.setup_empty, lib.teardown)
def helper_test_register_plugin_path(path):
pyblish.plugin.register_plugin_path(path)
registered_paths = pyblish.api.registered_paths()
path = os.path.normpath(str(path))
assert path in registered_paths, path + ' not in ' + str(registered_paths) # check if path in here

# create input
input_to_test = []
from pathlib import Path, PurePath, PureWindowsPath, WindowsPath, PosixPath, PurePosixPath
path_types = [Path, PurePath, PureWindowsPath, WindowsPath, PosixPath, PurePosixPath]
for path_type in path_types:
try:
input_to_test.append(path_type('test/folder/path')) # create pathlib input
except NotImplementedError: # PosixPath can't be instantiated on windows and raises NotImplementedError
pass
# input_to_test.append(u"c:\some\special\södär\testpath".encode('utf-8')) # create unicode input
# input_to_test.append(b"c:\\bytes\\are/cool") # create bytestring input

# test all paths from input
for path in input_to_test:
helper_test_register_plugin_path(path)


@mock.patch("pyblish.plugin.__explicit_process")
def test_implicit_explicit_branching(func):
"""Explicit plug-ins are processed by the appropriate function"""
Expand Down