Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Testing: adding support for synthetic workfile in nuke integration tests #5278

Closed
wants to merge 7 commits into from
Closed
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
3 changes: 3 additions & 0 deletions openpype/lib/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -1770,10 +1770,13 @@ def _prepare_last_workfile(data, workdir, modules_manager):
task_type = data["task_type"]

start_last_workfile = data.get("start_last_workfile")

if start_last_workfile is None:
start_last_workfile = should_start_last_workfile(
project_name, app.host_name, task_name, task_type
)
elif start_last_workfile is True:
log.info("Opening of last workfile was forced by user")
else:
log.info("Opening of last workfile was disabled by user")

Expand Down
Empty file added tests/integration/__init__.py
Empty file.
Empty file.
Empty file.
100 changes: 93 additions & 7 deletions tests/integration/hosts/nuke/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@
import pytest
import re

from tests.lib.testing_classes import ModuleUnitTest
from tests.lib.testing_classes import (
HostFixtures,
PublishTest,
AppLaunchTest,
DeadlinePublishTest
)
from openpype.lib.local_settings import get_openpype_username
from openpype.pipeline.workfile import (
get_workfile_template_key,
get_last_workfile,
get_workdir_with_workdir_data
)
from openpype.pipeline import HOST_WORKFILE_EXTENSIONS
from openpype.pipeline.template_data import get_template_data


class NukeHostFixtures(HostFixtures):
class NukeStaticTestHostFixtures(HostFixtures):
@pytest.fixture(scope="module")
def last_workfile_path(self, download_test_data, output_folder_url):
"""Get last_workfile_path from source data.
Expand Down Expand Up @@ -47,22 +57,98 @@ def last_workfile_path(self, download_test_data, output_folder_url):
@pytest.fixture(scope="module")
def startup_scripts(self, monkeypatch_session, download_test_data):
"""Points Nuke to userSetup file from input data"""
print("Using startup scripts from input data")
startup_path = os.path.join(download_test_data,
"input",
"startup")
original_nuke_path = os.environ.get("NUKE_PATH", "")
monkeypatch_session.setenv("NUKE_PATH",
"{}{}{}".format(startup_path,
os.pathsep,
original_nuke_path))
new_nuke_path = os.pathsep.join([startup_path, original_nuke_path])

print("Setting Nuke path to: {}".format(new_nuke_path))
monkeypatch_session.setenv("NUKE_PATH", new_nuke_path)

@pytest.fixture(scope="module")
def skip_compare_folders(self):
yield []

class NukeLocalPublishTestClass(NukeHostFixtures, PublishTest):

class NukeSyntheticHostFixtures(NukeStaticTestHostFixtures, ModuleUnitTest):

@pytest.fixture(scope="module")
def startup_scripts(self, monkeypatch_session):
"""Points Nuke to userSetup file from input data"""
print("Using startup scripts from input data")
test_host_dir = os.path.dirname(os.path.abspath(__file__))
startup_path = os.path.join(test_host_dir, "startup")
original_nuke_path = os.environ.get("NUKE_PATH", "")
new_nuke_path = os.pathsep.join([startup_path, original_nuke_path])

print("Setting Nuke path to: {}".format(new_nuke_path))
monkeypatch_session.setenv("NUKE_PATH", new_nuke_path)

@pytest.fixture(scope="module")
def last_workfile_path(
self, project_settings, project_anatomy,
system_settings, project_doc, asset_doc
):
"""Get last_workfile_path from template.
"""
print("Using last workfile path from template")

host_name = "nuke"
extensions = HOST_WORKFILE_EXTENSIONS.get(host_name)
anatomy = project_anatomy

workdir_data = get_template_data(
project_doc, asset_doc, self.TASK, host_name, system_settings
)

workdir = get_workdir_with_workdir_data(
workdir_data,
anatomy.project_name,
anatomy,
project_settings=project_settings
)

project_settings = project_settings
task_type = workdir_data["task"]["type"]
template_key = get_workfile_template_key(
task_type,
host_name,
self.PROJECT,
project_settings=project_settings
)
# Find last workfile
file_template = str(anatomy.templates[template_key]["file"])

workdir_data.update({
"version": 1,
"user": get_openpype_username(),
"ext": extensions[0]
})

last_workfile_path = get_last_workfile(
workdir, file_template, workdir_data, extensions, True
)

yield last_workfile_path

@pytest.fixture(scope="module")
def disable_workfile_tool_start(self, monkeypatch_session):
"""Disable workfile tool start."""
print("Disabling workfile tool on start")
monkeypatch_session.setenv("OPENPYPE_WORKFILE_TOOL_ON_START", "0")


class NukeLocalSyntheticTestClass(NukeSyntheticHostFixtures, AppLaunchTest):
"""Testing class for local publishes."""


class NukeLocalPublishTestClass(NukeStaticTestHostFixtures, PublishTest):
"""Testing class for local publishes."""


class NukeDeadlinePublishTestClass(NukeHostFixtures, DeadlinePublishTest):
class NukeDeadlinePublishTestClass(
NukeStaticTestHostFixtures, DeadlinePublishTest
):
"""Testing class for Deadline publishes."""
34 changes: 34 additions & 0 deletions tests/integration/hosts/nuke/startup/init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os
import nuke
from openpype.pipeline import registered_host
from openpype.lib import Logger
from openpype.hosts.nuke.api.lib import WorkfileSettings

log = Logger().get_logger(__name__)


def script_create():
log.info("_______ Callback started _______")

last_workfile_path = os.getenv("AVALON_LAST_WORKFILE")
log.info("Nuke script created: {}".format(last_workfile_path))

host = registered_host()

# set workfile properties
workfile_settings = WorkfileSettings()
workfile_settings.set_context_settings()


# save workfile
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many blank lines (2)

host.save_file(last_workfile_path)


def close_script():
log.info("_______ Closing script _______")
nuke.scriptExit()


nuke.addOnUserCreate(script_create, nodeClass="Root")
nuke.removeOnCreate(script_create, nodeClass="Root")
nuke.addOnScriptSave(close_script)
72 changes: 72 additions & 0 deletions tests/integration/hosts/nuke/test_workfile_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import os
import logging
from tests.integration.hosts.nuke.lib import NukeLocalSyntheticTestClass

log = logging.getLogger("test_workfile_create")


class TestWorkfileCreate(NukeLocalSyntheticTestClass):
"""Basic test case for publishing in Nuke

Uses generic TestCase to prepare fixtures for test data, testing DBs,
env vars.

!!!
It expects modified path in WriteNode,
use '[python {nuke.script_directory()}]' instead of regular root
dir (eg. instead of `c:/projects`).
Access file path by selecting WriteNode group, CTRL+Enter, update file
input
!!!

Opens Nuke, run publish on prepared workile.

Then checks content of DB (if subset, version, representations were
created.
Checks tmp folder if all expected files were published.

How to run:
(in cmd with activated {OPENPYPE_ROOT}/.venv)
{OPENPYPE_ROOT}/.venv/Scripts/python.exe {OPENPYPE_ROOT}/start.py
runtests ../tests/integration/hosts/nuke # noqa: E501

To check log/errors from launched app's publish process keep PERSIST
to True and check `test_openpype.logs` collection.
"""
# https://drive.google.com/file/d/1SUurHj2aiQ21ZIMJfGVBI2KjR8kIjBGI/view?usp=sharing # noqa: E501
TEST_FILES = [
("1SUurHj2aiQ21ZIMJfGVBI2KjR8kIjBGI", "test_Nuke_publish.zip", "")
]

APP_GROUP = "nuke"

TIMEOUT = 50 # publish timeout

# could be overwritten by command line arguments
# keep empty to locate latest installed variant or explicit
APP_VARIANT = ""
PERSIST = True # True - keep test_db, test_openpype, outputted test files
TEST_DATA_FOLDER = r"C:\CODE\__PYPE\__unit_testing_data\test_nuke_workfile"

def test_workfile_created(
self, last_workfile_path,
disable_workfile_tool_start,
testing_in_host_finished
):
"""Testing whether workfile was created with hosts workio."""
print("test_workfile_created")

expected_dir, _ = os.path.split(last_workfile_path)

# check if workfile directory was created
assert os.path.exists(expected_dir)

# check if workfile was created
assert os.path.exists(last_workfile_path)

# check if workfile is not empty
assert os.path.getsize(last_workfile_path) > 0


if __name__ == "__main__":
test_case = TestWorkfileCreate()
Loading
Loading