Skip to content

Commit

Permalink
Merge pull request #6 from ynput/chore/changes_for_automatic_tests
Browse files Browse the repository at this point in the history
Updates to run Photoshop in automatic tests
  • Loading branch information
kalisp authored Jul 16, 2024
2 parents 5a5c52c + c436f75 commit b666c56
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
9 changes: 9 additions & 0 deletions client/ayon_photoshop/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ def get_launch_hook_paths(self, app):
os.path.join(PHOTOSHOP_ADDON_ROOT, "hooks")
]

def publish_in_test(self, log, close_plugin_name=None):
"""Runs publish in an opened host with a context.
Close Python process at the end.
"""

from ayon_photoshop.api.lib import publish_in_test

publish_in_test(log, close_plugin_name)


def get_launch_script_path():
return os.path.join(
Expand Down
56 changes: 55 additions & 1 deletion client/ayon_photoshop/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import sys
import contextlib
import traceback
import functools
import pyblish

from ayon_core.lib import env_value_to_bool, Logger, is_in_tests
from ayon_core.addon import AddonsManager
Expand Down Expand Up @@ -34,7 +36,18 @@ def main(*subprocess_args):
launcher = ProcessLauncher(subprocess_args)
launcher.start()

if env_value_to_bool("HEADLESS_PUBLISH"):
if is_in_tests():
manager = AddonsManager()
photoshop_addon = manager["photoshop"]

launcher.execute_in_main_thread(
functools.partial(
photoshop_addon.publish_in_test,
log,
"ClosePS",
)
)
elif env_value_to_bool("HEADLESS_PUBLISH"):
manager = AddonsManager()
webpublisher_addon = manager["webpublisher"]
launcher.execute_in_main_thread(
Expand Down Expand Up @@ -82,3 +95,44 @@ def maintained_visibility(layers=None):
for layer in layers:
stub().set_visible(layer.id, visibility[layer.id])
pass


def find_close_plugin(close_plugin_name, log):
if close_plugin_name:
plugins = pyblish.api.discover()
for plugin in plugins:
if plugin.__name__ == close_plugin_name:
return plugin

log.debug("Close plugin not found, app might not close.")


def publish_in_test(log, close_plugin_name=None):
"""Loops through all plugins, logs to console. Used for tests.
Args:
log (Logger)
close_plugin_name (Optional[str]): Name of plugin with responsibility
to close application.
"""

# Error exit as soon as any error occurs.
error_format = "Failed {plugin.__name__}: {error} -- {error.traceback}"
close_plugin = find_close_plugin(close_plugin_name, log)

for result in pyblish.util.publish_iter():
for record in result["records"]:
# Why do we log again? pyblish logger is logging to stdout...
log.info("{}: {}".format(result["plugin"].label, record.msg))

if not result["error"]:
continue

# QUESTION We don't break on error?
error_message = error_format.format(**result)
log.error(error_message)
if close_plugin: # close host app explicitly after error
context = pyblish.api.Context()
try:
close_plugin().process(context)
except Exception as exp:
print(exp)

0 comments on commit b666c56

Please sign in to comment.