mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
OP-2042 - adding persist, app_variant to cli
This commit is contained in:
parent
00d9681d56
commit
6e9c9c087c
5 changed files with 85 additions and 28 deletions
|
|
@ -360,9 +360,18 @@ def run(script):
|
|||
"--test_data_folder",
|
||||
help="Unzipped directory path of test file",
|
||||
default=None)
|
||||
def runtests(folder, mark, pyargs, test_data_folder):
|
||||
@click.option("-s",
|
||||
"--persist",
|
||||
help="Persist test DB and published files after test end",
|
||||
default=None)
|
||||
@click.option("-a",
|
||||
"--app_variant",
|
||||
help="Provide specific app variant for test, empty for latest",
|
||||
default=None)
|
||||
def runtests(folder, mark, pyargs, test_data_folder, persist, app_variant):
|
||||
"""Run all automatic tests after proper initialization via start.py"""
|
||||
PypeCommands().run_tests(folder, mark, pyargs, test_data_folder)
|
||||
PypeCommands().run_tests(folder, mark, pyargs, test_data_folder,
|
||||
persist, app_variant)
|
||||
|
||||
|
||||
@main.command()
|
||||
|
|
|
|||
|
|
@ -341,7 +341,8 @@ class PypeCommands:
|
|||
def validate_jsons(self):
|
||||
pass
|
||||
|
||||
def run_tests(self, folder, mark, pyargs, test_data_folder):
|
||||
def run_tests(self, folder, mark, pyargs,
|
||||
test_data_folder, persist, app_variant):
|
||||
"""
|
||||
Runs tests from 'folder'
|
||||
|
||||
|
|
@ -350,6 +351,10 @@ class PypeCommands:
|
|||
mark (str): label to run tests marked by it (slow etc)
|
||||
pyargs (str): package path to test
|
||||
test_data_folder (str): url to unzipped folder of test data
|
||||
persist (bool): True if keep test db and published after test
|
||||
end
|
||||
app_variant (str): variant (eg 2020 for AE), empty if use
|
||||
latest installed version
|
||||
"""
|
||||
print("run_tests")
|
||||
if folder:
|
||||
|
|
@ -366,9 +371,15 @@ class PypeCommands:
|
|||
if pyargs:
|
||||
args.extend(["--pyargs", pyargs])
|
||||
|
||||
if test_data_folder:
|
||||
if persist:
|
||||
args.extend(["--test_data_folder", test_data_folder])
|
||||
|
||||
if persist:
|
||||
args.extend(["--persist", persist])
|
||||
|
||||
if app_variant:
|
||||
args.extend(["--app_variant", app_variant])
|
||||
|
||||
print("run_tests args: {}".format(args))
|
||||
import pytest
|
||||
pytest.main(args)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# adds command line arguments for 'runtests' as a fixtures
|
||||
import pytest
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption(
|
||||
"--test_data_folder", action="store", default=None,
|
||||
help="Provide url of a folder of unzipped test file"
|
||||
)
|
||||
|
||||
parser.addoption(
|
||||
"--persist", action="store", default=None,
|
||||
help="True - keep test_db, test_openpype, outputted test files"
|
||||
)
|
||||
|
||||
parser.addoption(
|
||||
"--app_variant", action="store", default=None,
|
||||
help="Keep empty to locate latest installed variant or explicit"
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def test_data_folder(request):
|
||||
return request.config.getoption("--test_data_folder")
|
||||
return request.config.getoption("--test_data_folder")
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def persist(request):
|
||||
return request.config.getoption("--persist")
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def app_variant(request):
|
||||
return request.config.getoption("--app_variant")
|
||||
|
|
|
|||
|
|
@ -27,22 +27,23 @@ class TestPublishInNuke(PublishTest):
|
|||
To check log/errors from launched app's publish process keep PERSIST
|
||||
to True and check `test_openpype.logs` collection.
|
||||
"""
|
||||
PERSIST = True # True - keep test_db, test_openpype, outputted test files
|
||||
|
||||
# https://drive.google.com/file/d/1SUurHj2aiQ21ZIMJfGVBI2KjR8kIjBGI/view?usp=sharing # noqa: E501
|
||||
TEST_FILES = [
|
||||
("1SUurHj2aiQ21ZIMJfGVBI2KjR8kIjBGI", "test_Nuke_publish.zip", "")
|
||||
]
|
||||
|
||||
APP = "nuke"
|
||||
# keep empty to locate latest installed variant or explicit
|
||||
APP_VARIANT = ""
|
||||
|
||||
TIMEOUT = 120 # publish timeout
|
||||
|
||||
TEST_DATA_FOLDER = "C:\\Users\\petrk\\AppData\\Local\\Temp\\tmpbfh976y6" # provide existing folder with test data
|
||||
# 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 = None
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def last_workfile_path(self, download_test_data):
|
||||
def last_workfile_path(self, download_test_data, output_folder_url):
|
||||
"""Get last_workfile_path from source data.
|
||||
|
||||
"""
|
||||
|
|
@ -99,7 +100,7 @@ class TestPublishInNuke(PublishTest):
|
|||
"name": "workfileTest_task"}), \
|
||||
"workfileTest_task subset must be present"
|
||||
|
||||
assert 10 == dbcon.count_documents({"type": "representation"}), \
|
||||
assert 4 == dbcon.count_documents({"type": "representation"}), \
|
||||
"Not expected no of representations"
|
||||
|
||||
reprs = dbcon.count_documents({"type": "representation",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import pytest
|
|||
import tempfile
|
||||
import shutil
|
||||
import glob
|
||||
import platform
|
||||
|
||||
from tests.lib.db_handler import DBHandler
|
||||
from tests.lib.file_handler import RemoteFileHandler
|
||||
|
|
@ -58,7 +59,8 @@ class ModuleUnitTest(BaseTest):
|
|||
m.undo()
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def download_test_data(self, test_data_folder):
|
||||
def download_test_data(self, test_data_folder, persist=False):
|
||||
test_data_folder = test_data_folder or self.TEST_DATA_FOLDER
|
||||
if test_data_folder:
|
||||
print("Using existing folder {}".format(test_data_folder))
|
||||
yield test_data_folder
|
||||
|
|
@ -78,7 +80,8 @@ class ModuleUnitTest(BaseTest):
|
|||
print("Temporary folder created:: {}".format(tmpdir))
|
||||
yield tmpdir
|
||||
|
||||
if not self.PERSIST:
|
||||
persist = persist or self.PERSIST
|
||||
if not persist:
|
||||
print("Removing {}".format(tmpdir))
|
||||
shutil.rmtree(tmpdir)
|
||||
|
||||
|
|
@ -188,14 +191,28 @@ class PublishTest(ModuleUnitTest):
|
|||
"""
|
||||
|
||||
APP = ""
|
||||
APP_VARIANT = "" # keep empty to locate latest installed variant
|
||||
|
||||
TIMEOUT = 120 # publish timeout
|
||||
|
||||
@property
|
||||
def app_name(self):
|
||||
if self.APP_VARIANT:
|
||||
return "{}/{}".format(self.APP, self.APP_VARIANT)
|
||||
# could be overwritten by command line arguments
|
||||
# command line value takes precedence
|
||||
|
||||
# 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 = None # use specific folder of unzipped test file
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def app_name(self, app_variant):
|
||||
"""Returns calculated value for ApplicationManager. Eg.(nuke/12-2)"""
|
||||
from openpype.lib import ApplicationManager
|
||||
app_variant = app_variant or self.APP_VARIANT
|
||||
|
||||
application_manager = ApplicationManager()
|
||||
if not app_variant:
|
||||
app_variant = find_variant_key(application_manager, self.APP)
|
||||
|
||||
yield "{}/{}".format(self.APP, app_variant)
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def last_workfile_path(self, download_test_data):
|
||||
|
|
@ -203,6 +220,7 @@ class PublishTest(ModuleUnitTest):
|
|||
|
||||
@pytest.fixture(scope="module")
|
||||
def startup_scripts(self, monkeypatch_session, download_test_data):
|
||||
""""Adds init scripts (like userSetup) to expected location"""
|
||||
raise NotImplementedError
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
|
@ -270,12 +288,6 @@ class PublishTest(ModuleUnitTest):
|
|||
if app_args:
|
||||
data["app_args"] = app_args
|
||||
|
||||
variant = self.APP_VARIANT
|
||||
if not variant:
|
||||
variant = find_variant_key(application_manager, self.APP)
|
||||
|
||||
app_name = "{}/{}".format(self.APP, variant)
|
||||
|
||||
app_process = application_manager.launch(app_name, **data)
|
||||
yield app_process
|
||||
|
||||
|
|
@ -295,13 +307,13 @@ class PublishTest(ModuleUnitTest):
|
|||
yield True
|
||||
|
||||
def test_folder_structure_same(self, dbcon, publish_finished,
|
||||
download_test_data):
|
||||
download_test_data, output_folder_url):
|
||||
"""Check if expected and published subfolders contain same files.
|
||||
|
||||
Compares only presence, not size nor content!
|
||||
"""
|
||||
published_dir_base = download_test_data
|
||||
published_dir = os.path.join(published_dir_base,
|
||||
published_dir = os.path.join(output_folder_url,
|
||||
self.PROJECT,
|
||||
self.TASK,
|
||||
"**")
|
||||
|
|
@ -311,7 +323,8 @@ class PublishTest(ModuleUnitTest):
|
|||
self.PROJECT,
|
||||
self.TASK,
|
||||
"**")
|
||||
|
||||
print("Comparing published:'{}' : expected:'{}'".format(published_dir,
|
||||
expected_dir))
|
||||
published = set(f.replace(published_dir_base, '') for f in
|
||||
glob.glob(published_dir, recursive=True) if
|
||||
f != published_dir_base and os.path.exists(f))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue