Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching python unittest to pytest framework #1739

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ build-backend = "setuptools.build_meta"
build-verbosity = "1"

test-command = "python -m PyOpenColorIOTests.OpenColorIOTestSuite"
test-requires = ["numpy"]
test-requires = ["numpy", "pytest"]

manylinux-x86_64-image = "manylinux2014"
manylinux-i686-image = "manylinux2014"
Expand Down
117 changes: 3 additions & 114 deletions tests/python/OpenColorIOTestSuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright Contributors to the OpenColorIO Project.

import logging
import unittest
import pytest
import os
import sys

Expand Down Expand Up @@ -44,118 +44,7 @@
os.environ["TEST_DATAFILES_DIR"] = os.path.join(here, 'data', 'files')
sys.path.insert(0, here)

import PyOpenColorIO as OCIO

import AllocationTransformTest
import BakerTest
import BuiltinConfigRegistryTest
import BuiltinTransformRegistryTest
import BuiltinTransformTest
import CDLTransformTest
import ColorSpaceHelpersTest
import ColorSpaceTest
import ColorSpaceTransformTest
import ConfigTest
import ConstantsTest
import ContextTest
import CPUProcessorTest
import DisplayViewHelpersTest
import DisplayViewTransformTest
import ExponentTransformTest
import ExponentWithLinearTransformTest
import ExposureContrastTransformTest
import FileRulesTest
import FileTransformTest
import FixedFunctionTransformTest
import FormatMetadataTest
import GpuShaderDescTest
import GradingDataTest
import GradingPrimaryTransformTest
import GradingRGBCurveTransformTest
import GradingToneTransformTest
import GroupTransformTest
import LegacyViewingPipelineTest
import LogCameraTransformTest
import LogTransformTest
import LookTest
import LookTransformTest
import Lut1DTransformTest
import Lut3DTransformTest
import MatrixTransformTest
import MixingHelpersTest
import NamedTransformTest
import OCIOZArchiveTest
import OpenColorIOTest
import ProcessorTest
import RangeTransformTest
import TransformsTest
import ViewingRulesTest
import ViewTransformTest

def suite():
"""Load unittest.TestCase objects from *Test.py files within ./tests/Python

:return: unittest test suite of TestCase objects.
:rtype: unittest.TestSuite
"""

# top level directory cached on loader instance
suite = unittest.TestSuite()
loader = unittest.TestLoader()

suite.addTest(loader.loadTestsFromModule(AllocationTransformTest))
suite.addTest(loader.loadTestsFromModule(BakerTest))
suite.addTest(loader.loadTestsFromModule(BuiltinConfigRegistryTest))
suite.addTest(loader.loadTestsFromModule(BuiltinTransformRegistryTest))
suite.addTest(loader.loadTestsFromModule(BuiltinTransformTest))
suite.addTest(loader.loadTestsFromModule(CDLTransformTest))
suite.addTest(loader.loadTestsFromModule(ColorSpaceHelpersTest))
suite.addTest(loader.loadTestsFromModule(ColorSpaceTest))
suite.addTest(loader.loadTestsFromModule(ColorSpaceTransformTest))
suite.addTest(loader.loadTestsFromModule(ConfigTest))
suite.addTest(loader.loadTestsFromModule(ConstantsTest))
suite.addTest(loader.loadTestsFromModule(ContextTest))
suite.addTest(loader.loadTestsFromModule(CPUProcessorTest))
suite.addTest(loader.loadTestsFromModule(DisplayViewHelpersTest))
suite.addTest(loader.loadTestsFromModule(DisplayViewTransformTest))
suite.addTest(loader.loadTestsFromModule(ExponentTransformTest))
suite.addTest(loader.loadTestsFromModule(ExponentWithLinearTransformTest))
suite.addTest(loader.loadTestsFromModule(ExposureContrastTransformTest))
suite.addTest(loader.loadTestsFromModule(FileTransformTest))
suite.addTest(loader.loadTestsFromModule(FileRulesTest))
suite.addTest(loader.loadTestsFromModule(FixedFunctionTransformTest))
suite.addTest(loader.loadTestsFromModule(FormatMetadataTest))
suite.addTest(loader.loadTestsFromModule(GpuShaderDescTest))
suite.addTest(loader.loadTestsFromModule(GradingDataTest))
suite.addTest(loader.loadTestsFromModule(GradingPrimaryTransformTest))
suite.addTest(loader.loadTestsFromModule(GradingRGBCurveTransformTest))
suite.addTest(loader.loadTestsFromModule(GradingToneTransformTest))
suite.addTest(loader.loadTestsFromModule(GroupTransformTest))
suite.addTest(loader.loadTestsFromModule(LegacyViewingPipelineTest))
suite.addTest(loader.loadTestsFromModule(LogCameraTransformTest))
suite.addTest(loader.loadTestsFromModule(LogTransformTest))
suite.addTest(loader.loadTestsFromModule(LookTest))
suite.addTest(loader.loadTestsFromModule(LookTransformTest))
suite.addTest(loader.loadTestsFromModule(Lut1DTransformTest))
suite.addTest(loader.loadTestsFromModule(Lut3DTransformTest))
suite.addTest(loader.loadTestsFromModule(MatrixTransformTest))
suite.addTest(loader.loadTestsFromModule(MixingHelpersTest))
suite.addTest(loader.loadTestsFromModule(NamedTransformTest))
suite.addTest(loader.loadTestsFromModule(OCIOZArchiveTest))
suite.addTest(loader.loadTestsFromModule(OpenColorIOTest))
suite.addTest(loader.loadTestsFromModule(ProcessorTest))
suite.addTest(loader.loadTestsFromModule(RangeTransformTest))
suite.addTest(loader.loadTestsFromModule(TransformsTest))
suite.addTest(loader.loadTestsFromModule(ViewingRulesTest))
suite.addTest(loader.loadTestsFromModule(ViewTransformTest))

return suite


if __name__ == '__main__':
runner = unittest.TextTestRunner(verbosity=2)
test_suite = suite()
result = runner.run(test_suite)
if result.wasSuccessful() == False:
sys.exit(1)
sys.exit(0)
exit_code = pytest.main([os.path.dirname(__file__)])
sys.exit(exit_code)
1 change: 1 addition & 0 deletions tests/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
numpy
pytest
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import unittest

import PyOpenColorIO as OCIO
from TransformsBaseTest import TransformsBaseTest
from test_TransformsBase import TransformsBaseTest


class AllocationTransformTest(unittest.TestCase, TransformsBaseTest):
class TestAllocationTransform(unittest.TestCase, TransformsBaseTest):
TEST_ALLOCATION = OCIO.ALLOCATION_LG2
TEST_VARS = [0, 1]
TEST_DIRECTION = OCIO.TRANSFORM_DIR_INVERSE
Expand Down
2 changes: 1 addition & 1 deletion tests/python/BakerTest.py → tests/python/test_Baker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import copy, unittest, os, sys
import PyOpenColorIO as OCIO

class BakerTest(unittest.TestCase):
class TestBaker(unittest.TestCase):

SIMPLE_PROFILE = """ocio_profile_version: 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import PyOpenColorIO as OCIO

class BuiltinConfigRegistryTest(unittest.TestCase):
class TestBuiltinConfigRegistry(unittest.TestCase):
# BuiltinRegistry singleton.
REGISTRY = None

Expand All @@ -27,7 +27,7 @@ def test_builtin_config_iterable(self):
self.assertIsInstance(name, STRING_TYPES)
self.assertIsInstance(self.REGISTRY[name], STRING_TYPES)
all_names.append(name)

# All names were iterated over, and __len__ and list() behave.
self.assertEqual(len(all_names), len(self.REGISTRY))
self.assertListEqual(all_names, list(self.REGISTRY))
Expand All @@ -38,7 +38,7 @@ def test_builtin_config_iterable(self):

# Iterator size is available.
self.assertEqual(len(iterator), len(self.REGISTRY))

# Iterator supports range-based loop and indexing.
values = list(iterator)
for i in range(len(iterator)):
Expand Down Expand Up @@ -83,7 +83,7 @@ def test_get_builtin_configs(self):

# Iterator size is available.
self.assertEqual(len(iterator), len(self.REGISTRY))

# Iterator supports range-based loop and indexing.
values = list(iterator)
for i in range(len(iterator)):
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_get_builtin_configs(self):
self.assertEqual(values[0][0], "cg-config-v1.0.0_aces-v1.3_ocio-v2.1")
# UI name
self.assertEqual(
values[0][1],
values[0][1],
("Academy Color Encoding System - CG Config [COLORSPACES v1.0.0] [ACES v1.3] "
"[OCIO v2.1]"))
# isRecommended
Expand All @@ -128,20 +128,20 @@ def test_get_builtin_configs(self):
self.assertEqual(values[1][0], "studio-config-v1.0.0_aces-v1.3_ocio-v2.1")
# UI name
self.assertEqual(
values[1][1],
values[1][1],
("Academy Color Encoding System - Studio Config [COLORSPACES v1.0.0] [ACES v1.3] "
"[OCIO v2.1]"))
# isRecommended
self.assertEqual(values[1][2], True)

def test_multi_reference(self):
# Registry is a singleton. Make sure multiple Python
# Registry is a singleton. Make sure multiple Python
# instances can be held.
instances = []
for i in range(10):
instances.append(OCIO.BuiltinConfigRegistry())

# Other instances should still function after deleting one. The
# Other instances should still function after deleting one. The
# underlying C++ object is not deleted.
instance_0 = instances.pop(0)
self.assertEqual(len(instances), 9)
Expand All @@ -151,7 +151,7 @@ def test_multi_reference(self):
with self.assertRaises(NameError):
len(instance_0)

# Test underlying C++ reference validity by accessing registry
# Test underlying C++ reference validity by accessing registry
# data for each instance.
for instance in instances:
self.assertGreaterEqual(len(instance), 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import unittest

import PyOpenColorIO as OCIO
from TransformsBaseTest import TransformsBaseTest
from test_TransformsBase import TransformsBaseTest


class BuiltinTransformTest(unittest.TestCase, TransformsBaseTest):
class TestBuiltinTransform(unittest.TestCase, TransformsBaseTest):
# BuiltinTransformRegistry singleton
REGISTRY = None

Expand Down Expand Up @@ -61,7 +61,7 @@ def test_constructor_keyword(self):

self.assertEqual(builtin_tr1.getStyle(), self.EXAMPLE_STYLE)
self.assertEqual(builtin_tr1.getDescription(), self.EXAMPLE_DESC)
self.assertEqual(builtin_tr1.getDirection(),
self.assertEqual(builtin_tr1.getDirection(),
OCIO.TRANSFORM_DIR_FORWARD)

# Keyword args out of order
Expand All @@ -70,17 +70,17 @@ def test_constructor_keyword(self):

self.assertEqual(builtin_tr2.getStyle(), self.EXAMPLE_STYLE)
self.assertEqual(builtin_tr2.getDescription(), self.EXAMPLE_DESC)
self.assertEqual(builtin_tr2.getDirection(),
self.assertEqual(builtin_tr2.getDirection(),
OCIO.TRANSFORM_DIR_FORWARD)

def test_constructor_positional(self):
# Positional args
builtin_tr = OCIO.BuiltinTransform(self.EXAMPLE_STYLE,
builtin_tr = OCIO.BuiltinTransform(self.EXAMPLE_STYLE,
OCIO.TRANSFORM_DIR_FORWARD)

self.assertEqual(builtin_tr.getStyle(), self.EXAMPLE_STYLE)
self.assertEqual(builtin_tr.getDescription(), self.EXAMPLE_DESC)
self.assertEqual(builtin_tr.getDirection(),
self.assertEqual(builtin_tr.getDirection(),
OCIO.TRANSFORM_DIR_FORWARD)

def test_str(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from UnitTestUtils import STRING_TYPES


class BuiltinTransformRegistryTest(unittest.TestCase):
class TestBuiltinTransformRegistry(unittest.TestCase):
# BuiltinTransformRegistry singleton
REGISTRY = None

Expand All @@ -39,7 +39,7 @@ def test_iterable(self):

# Iterator size is available
self.assertEqual(len(iterator), len(self.REGISTRY))

# Iterator supports range-based loop and indexing
values = list(iterator)
for i in range(len(iterator)):
Expand Down Expand Up @@ -68,7 +68,7 @@ def test_get_builtins(self):

# Iterator size is available
self.assertEqual(len(iterator), len(self.REGISTRY))

# Iterator supports range-based loop and indexing
values = list(iterator)
for i in range(len(iterator)):
Expand All @@ -91,13 +91,13 @@ def test_contains(self):
self.assertFalse("invalid" in self.REGISTRY)

def test_multi_reference(self):
# Registry is a singleton. Make sure multiple Python
# Registry is a singleton. Make sure multiple Python
# instances can be held.
instances = []
for i in range(10):
instances.append(OCIO.BuiltinTransformRegistry())

# Other instances should still function after deleting one. The
# Other instances should still function after deleting one. The
# underlying C++ object is not deleted.
instance_0 = instances.pop(0)
self.assertEqual(len(instances), 9)
Expand All @@ -107,7 +107,7 @@ def test_multi_reference(self):
with self.assertRaises(NameError):
len(instance_0)

# Test underlying C++ reference validity by accessing registry
# Test underlying C++ reference validity by accessing registry
# data for each instance.
for instance in instances:
self.assertGreaterEqual(len(instance), 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import PyOpenColorIO as OCIO
from UnitTestUtils import TEST_DATAFILES_DIR, TEST_NAMES, TEST_DESCS
from TransformsBaseTest import TransformsBaseTest
from test_TransformsBase import TransformsBaseTest


class CDLTransformTest(unittest.TestCase, TransformsBaseTest):
class TestCDLTransform(unittest.TestCase, TransformsBaseTest):
# Default CDL values on initialization.
DEFAULT_CDL_SLOPE = [1.0, 1.0, 1.0]
DEFAULT_CDL_OFFSET = [0.0, 0.0, 0.0]
Expand Down
Loading