OP-3951 - added tests for validate_sequence_frames

Introduced conftest with dummy environment for basic tests
This commit is contained in:
Petr Kalis 2023-03-23 18:15:11 +01:00
parent e8f9c130bb
commit 0648271ec7
2 changed files with 181 additions and 0 deletions

View file

@ -0,0 +1,38 @@
"""Dummy environment that allows importing Openpype modules and run
tests in parent folder and all subfolders manually from IDE.
This should not get triggered if the tests are running from `runtests` as it
is expected there that environment is handled by OP itself.
This environment should be enough to run simple `BaseTest` where no
external preparation is necessary (eg. no prepared DB, no source files).
These tests might be enough to import and run simple pyblish plugins to
validate logic.
Please be aware that these tests might use values in real databases, so use
`BaseTest` only for logic without side effects or special configuration. For
these there is `tests.lib.testing_classes.ModuleUnitTest` which would setup
proper test DB (but it requires `mongorestore` on the sys.path)
If pyblish plugins require any host dependent communication, it would need
to be mocked.
This setting of env vars is necessary to run before any imports of OP code!
(This is why it is in `conftest.py` file.)
If your test requires any additional env var, copy this file to folder of your
test, it should only that folder.
"""
import os
if not os.environ.get("IS_TEST"): # running tests from cmd or CI
os.environ["AVALON_MONGO"] = "mongodb://localhost:27017"
os.environ["OPENPYPE_MONGO"] = "mongodb://localhost:27017"
os.environ["AVALON_DB"] = "avalon"
os.environ["OPENPYPE_DATABASE_NAME"] = "avalon"
os.environ["AVALON_TIMEOUT"] = '3000'
os.environ["OPENPYPE_DEBUG"] = "3"
os.environ["AVALON_CONFIG"] = "pype"
os.environ["AVALON_ASSET"] = "test_asset"
os.environ["AVALON_PROJECT"] = "test_project"

View file

@ -0,0 +1,143 @@
"""Test Publish_plugins pipeline publish modul, tests API methods
File:
creates temporary directory and downloads .zip file from GDrive
unzips .zip file
uses content of .zip file (MongoDB's dumps) to import to new databases
with use of 'monkeypatch_session' modifies required env vars
temporarily
runs battery of tests checking that site operation for Sync Server
module are working
removes temporary folder
removes temporary databases (?)
"""
import pytest
import logging
from pyblish.api import Instance as PyblishInstance
from tests.lib.testing_classes import BaseTest
from openpype.plugins.publish.validate_sequence_frames import (
ValidateSequenceFrames
)
log = logging.getLogger(__name__)
class TestValidateSequenceFrames(BaseTest):
""" Testing ValidateSequenceFrames plugin
"""
@pytest.fixture
def instance(self):
class Instance(PyblishInstance):
data = {
"frameStart": 1001,
"frameEnd": 1001,
"representations": []
}
yield Instance
@pytest.fixture(scope="module")
def plugin(self):
plugin = ValidateSequenceFrames()
plugin.log = log
yield plugin
def test_validate_sequence_frames_single_frame(self, instance, plugin):
representations = [
{
"ext": "exr",
"files": "Main_beauty.1001.exr",
}
]
instance.data["representations"] = representations
plugin.process(instance)
@pytest.mark.parametrize("files",
["Main_beauty.v001.1001.exr",
"Main_beauty_v001.1001.exr",
"Main_beauty.1001.1001.exr"])
def test_validate_sequence_frames_single_frame_name(self, instance,
plugin,
files):
# tests for names with number inside, caused clique failure before
representations = [
{
"ext": "exr",
"files": files,
}
]
instance.data["representations"] = representations
plugin.process(instance)
@pytest.mark.parametrize("files",
["Main_beauty.1001.v001.exr"])
def test_validate_sequence_frames_single_frame_wrong_name(self, instance,
plugin,
files):
# tests for names with number inside, caused clique failure before
representations = [
{
"ext": "exr",
"files": files,
}
]
instance.data["representations"] = representations
with pytest.raises(ValueError) as excinfo:
plugin.process(instance)
assert ("Invalid frame range: (1, 1) - expected: (1001, 1001)" in
str(excinfo.value))
def test_validate_sequence_frames_multi_frame(self, instance, plugin):
representations = [
{
"ext": "exr",
"files": ["Main_beauty.1001.exr", "Main_beauty.1002.exr",
"Main_beauty.1003.exr"]
}
]
instance.data["representations"] = representations
instance.data["frameEnd"] = 1003
plugin.process(instance)
def test_validate_sequence_frames_multi_frame_missing(self, instance,
plugin):
representations = [
{
"ext": "exr",
"files": ["Main_beauty.1001.exr", "Main_beauty.1002.exr"]
}
]
instance.data["representations"] = representations
instance.data["frameEnd"] = 1003
with pytest.raises(ValueError) as excinfo:
plugin.process(instance)
assert ("Invalid frame range: (1001, 1002) - expected: (1001, 1003)" in
str(excinfo.value))
def test_validate_sequence_frames_multi_frame_hole(self, instance, plugin):
representations = [
{
"ext": "exr",
"files": ["Main_beauty.1001.exr", "Main_beauty.1003.exr"]
}
]
instance.data["representations"] = representations
instance.data["frameEnd"] = 1003
with pytest.raises(AssertionError) as excinfo:
plugin.process(instance)
assert ("Missing frames: [1002]" in str(excinfo.value))
test_case = TestValidateSequenceFrames()