Skip to content

Commit

Permalink
Merge pull request #4 from ynput/chore/changes_for_automatic_tests
Browse files Browse the repository at this point in the history
Tests: Copied publish_in_test to AE
  • Loading branch information
kalisp authored Jul 12, 2024
2 parents 26e14f5 + 20a0747 commit b587295
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
10 changes: 10 additions & 0 deletions client/ayon_aftereffects/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ def get_launch_hook_paths(self, app):
os.path.join(AFTEREFFECTS_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_aftereffects.api.lib import publish_in_test

publish_in_test(log, close_plugin_name)


def get_launch_script_path():
return os.path.join(
Expand Down
7 changes: 3 additions & 4 deletions client/ayon_aftereffects/api/launch_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@ def main(*subprocess_args):
launcher = ProcessLauncher(subprocess_args)
launcher.start()

if os.environ.get("HEADLESS_PUBLISH"):
if is_in_tests():
manager = AddonsManager()
webpublisher_addon = manager["webpublisher"]
aftereffects_addon = manager["aftereffects"]

launcher.execute_in_main_thread(
functools.partial(
webpublisher_addon.headless_publish,
aftereffects_addon.publish_in_test,
log,
"CloseAE",
is_in_tests()
)
)

Expand Down
43 changes: 43 additions & 0 deletions client/ayon_aftereffects/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import contextlib
import logging
import pyblish

import ayon_api

Expand Down Expand Up @@ -162,3 +163,45 @@ def set_settings(frames, resolution, comp_ids=None, print_msg=True):
fps, width, height)
if print_msg:
stub.print_msg(msg)


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 b587295

Please sign in to comment.