#1794 - moved to better folder

Implemented comparing published files with expected
Changed approach to userSetup
This commit is contained in:
Petr Kalis 2021-09-03 17:45:32 +02:00
parent 5701cfed2b
commit 7e088d6b97

View file

@ -2,6 +2,7 @@ import pytest
import sys import sys
import os import os
import shutil import shutil
import glob
from tests.lib.testing_wrapper import TestCase from tests.lib.testing_wrapper import TestCase
@ -28,6 +29,8 @@ class TestPublishInMaya(TestCase):
APP_NAME = "{}/{}".format(APP, APP_VARIANT) APP_NAME = "{}/{}".format(APP, APP_VARIANT)
TIMEOUT = 120 # publish timeout
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def last_workfile_path(self, download_test_data): def last_workfile_path(self, download_test_data):
"""Get last_workfile_path from source data. """Get last_workfile_path from source data.
@ -52,22 +55,14 @@ class TestPublishInMaya(TestCase):
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def startup_scripts(self, monkeypatch_session, download_test_data): def startup_scripts(self, monkeypatch_session, download_test_data):
"""Copy""" """Points Maya to userSetup file from input data"""
startup_path = os.path.join(download_test_data, startup_path = os.path.join(download_test_data,
"input", "input",
"startup", "startup")
"userSetup.py") original_pythonpath = os.environ.get("PYTHONPATH")
from openpype.hosts import maya monkeypatch_session.setenv("PYTHONPATH",
maya_dir = os.path.dirname(os.path.abspath(maya.__file__)) "{};{}".format(original_pythonpath,
shutil.move(os.path.join(maya_dir, "startup", "userSetup.py"), startup_path))
os.path.join(maya_dir, "startup", "userSetup.tmp")
)
shutil.copy(startup_path,
os.path.join(maya_dir, "startup", "userSetup.py"))
yield os.path.join(maya_dir, "startup", "userSetup.py")
shutil.move(os.path.join(maya_dir, "startup", "userSetup.tmp"),
os.path.join(maya_dir, "startup", "userSetup.py"))
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def launched_app(self, dbcon, download_test_data, last_workfile_path, def launched_app(self, dbcon, download_test_data, last_workfile_path,
@ -111,11 +106,15 @@ class TestPublishInMaya(TestCase):
def publish_finished(self, dbcon, launched_app): def publish_finished(self, dbcon, launched_app):
"""Dummy fixture waiting for publish to finish""" """Dummy fixture waiting for publish to finish"""
import time import time
time_start = time.time()
while launched_app.poll() is None: while launched_app.poll() is None:
time.sleep(0.5) time.sleep(0.5)
if time.time() - time_start > self.TIMEOUT:
raise ValueError("Timeout reached")
# some clean exit test possible? # some clean exit test possible?
print("Publish finished") print("Publish finished")
yield True
def test_db_asserts(self, dbcon, publish_finished): def test_db_asserts(self, dbcon, publish_finished):
print("test_db_asserts") print("test_db_asserts")
@ -147,59 +146,33 @@ class TestPublishInMaya(TestCase):
"context.ext": "ma"}).count(), \ "context.ext": "ma"}).count(), \
"Not expected no of representations with ext 'abc'" "Not expected no of representations with ext 'abc'"
def test_files(self, dbcon, publish_finished, download_test_data): def test_folder_structure_same(self, dbcon, publish_finished,
print("test_files") download_test_data):
# hero files """Check if expected and published subfolders contain same files.
hero_folder = os.path.join(download_test_data,
self.PROJECT,
self.ASSET,
"publish",
"model",
"modelMain",
"hero")
assert os.path.exists( Compares only presence, not size nor content!
os.path.join(hero_folder, """
"test_project_test_asset_modelMain_hero.ma") published_dir_base = download_test_data
), "test_project_test_asset_modelMain_hero.ma doesn't exist" published_dir = os.path.join(published_dir_base,
self.PROJECT,
self.TASK,
"**")
expected_dir_base = os.path.join(published_dir_base,
"expected")
expected_dir = os.path.join(expected_dir_base,
self.PROJECT,
self.TASK,
"**")
assert os.path.exists( published = set(f.replace(published_dir_base, '') for f in
os.path.join(hero_folder, glob.glob(published_dir, recursive=True) if
"test_project_test_asset_modelMain_hero.abc") f != published_dir_base and os.path.exists(f))
), "test_project_test_asset_modelMain_hero.abc doesn't exist" expected = set(f.replace(expected_dir_base, '') for f in
glob.glob(expected_dir, recursive=True) if
f != expected_dir_base and os.path.exists(f))
# version files not_matched = expected.difference(published)
version_folder = os.path.join(download_test_data, assert not not_matched, "Missing {} files".format(not_matched)
self.PROJECT,
self.ASSET,
"publish",
"model",
"modelMain",
"v001")
assert os.path.exists(
os.path.join(version_folder,
"test_project_test_asset_modelMain_v001.ma")
), "test_project_test_asset_modelMain_v001.ma doesn't exist"
assert os.path.exists(
os.path.join(version_folder,
"test_project_test_asset_modelMain_v001.abc")
), "test_project_test_asset_modelMain_v001.abc doesn't exist"
# workfile files
workfile_folder = os.path.join(download_test_data,
self.PROJECT,
self.ASSET,
"publish",
"workfile",
"workfileTest_task",
"v001")
assert os.path.exists(
os.path.join(workfile_folder,
"test_project_test_asset_workfileTest_task_v001.mb")
), "test_project_test_asset_workfileTest_task_v001.mb doesn't exist"
if __name__ == "__main__": if __name__ == "__main__":