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

Python unit test module LookTest update #1027

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 6 additions & 7 deletions src/bindings/python/PyLook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void bindPyLook(py::module & m)
const std::string & processSpace,
const TransformRcPtr & transform,
const TransformRcPtr & inverseTransform,
const std::string & description)
const std::string & description)
{
LookRcPtr p = Look::Create();
if (!name.empty()) { p->setName(name.c_str()); }
Expand All @@ -26,24 +26,23 @@ void bindPyLook(py::module & m)
if (inverseTransform) { p->setInverseTransform(inverseTransform); }
if (!description.empty()) { p->setDescription(description.c_str()); }
return p;
}),
}),
"name"_a = DEFAULT->getName(),
"processSpace"_a = DEFAULT->getProcessSpace(),
"transform"_a = DEFAULT->getTransform(),
"inverseTransform"_a = DEFAULT->getInverseTransform(),
"description"_a = DEFAULT->getDescription())
"description"_a = DEFAULT->getDescription())

.def("getName", &Look::getName)
.def("setName", &Look::setName, "name"_a)
.def("setName", &Look::setName, "name"_a.none(false))
.def("getProcessSpace", &Look::getProcessSpace)
.def("setProcessSpace", &Look::setProcessSpace, "processSpace"_a)
.def("setProcessSpace", &Look::setProcessSpace, "processSpace"_a.none(false))
.def("getTransform", &Look::getTransform)
.def("setTransform", &Look::setTransform, "transform"_a)
.def("getInverseTransform", &Look::getInverseTransform)
.def("setInverseTransform", &Look::setInverseTransform, "transform"_a)
.def("getDescription", &Look::getDescription)
.def("setDescription", &Look::setDescription, "description"_a);

michdolan marked this conversation as resolved.
Show resolved Hide resolved
.def("setDescription", &Look::setDescription, "description"_a.none(false));
defStr(cls);
}

Expand Down
202 changes: 180 additions & 22 deletions tests/python/LookTest.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,186 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright Contributors to the OpenColorIO Project.

import unittest, os, sys
import unittest
import os
import sys

import PyOpenColorIO as OCIO
from UnitTestUtils import TEST_NAMES, TEST_DESCS


class LookTest(unittest.TestCase):

def test_interface(self):
lk = OCIO.Look()
lk.setName("coollook")
self.assertEqual("coollook", lk.getName())
lk.setProcessSpace("somespace")
self.assertEqual("somespace", lk.getProcessSpace())
lk.setDescription("this is a test")
self.assertEqual("this is a test", lk.getDescription())
et = OCIO.ExponentTransform()
et.setValue([0.1, 0.2, 0.3, 0.4])
lk.setTransform(et)
oet = lk.getTransform()
vals = oet.getValue()
self.assertAlmostEqual(0.2, vals[1], delta=1e-8)
iet = OCIO.ExponentTransform()
iet.setValue([-0.1, -0.2, -0.3, -0.4])
lk.setInverseTransform(iet)
ioet = lk.getInverseTransform()
vals2 = ioet.getValue()
self.assertAlmostEqual(-0.2, vals2[1], delta=1e-8)
TEST_PROCESS_SPACES = ['raw', 'lnh', 'vd8', 'a.b.c.', '1-2-3-']

def setUp(self):
self.look = OCIO.Look()

def tearDown(self):
self.look = None

def test_name(self):
"""
Test the setName() and getName() methods.
"""

# Default initialized name value is ""
self.assertEqual(self.look.getName(), '')

for name in TEST_NAMES:
self.look.setName(name)
self.assertEqual(name, self.look.getName())

# Wrong type tests.
with self.assertRaises(TypeError):
self.look.setName(None)
self.look.setName(1)

def test_process(self):
michdolan marked this conversation as resolved.
Show resolved Hide resolved
"""
Test the setProcessSpace() and getProcessName() methods.
"""

# Default initialized process space value is ""
self.assertEqual(self.look.getProcessSpace(), '')

for process_space in self.TEST_PROCESS_SPACES:
self.look.setProcessSpace(process_space)
self.assertEqual(process_space, self.look.getProcessSpace())

# Wrong type tests.
with self.assertRaises(TypeError):
self.look.setProcessSpace(None)
self.look.setProcessSpace(1)

def test_description(self):
"""
Test the setDescription() and getDescription() methods.
"""

# Default initialized description value is ""
self.assertEqual(self.look.getDescription(), '')

for desc in TEST_DESCS:
self.look.setDescription(desc)
self.assertEqual(desc, self.look.getDescription())

# Wrong type tests.
with self.assertRaises(TypeError):
self.look.setDescription(None)
self.look.setDescription(1)

def test_transform(self):
"""
Test the setTransform() and getTransform() methods.
"""

# Default initialized transform value is None
self.assertIsNone(self.look.getTransform())

exp_tr = OCIO.ExponentTransform()
exp_values = [0.1, 0.2, 0.3, 0.4]
exp_tr.setValue(exp_values)
self.look.setTransform(exp_tr)
oet = self.look.getTransform()
michdolan marked this conversation as resolved.
Show resolved Hide resolved
self.assertListEqual(oet.getValue(), exp_values)

# Wrong type tests.
with self.assertRaises(TypeError):
self.look.setTransform(OCIO.ALLOCATION_UNIFORM)
self.look.setTransform(1)
michdolan marked this conversation as resolved.
Show resolved Hide resolved

def test_inverse_transform(self):
"""
Test the setInverseTransform() and getInverseTransform() methods.
"""

# Default initialized inverse transform value is None
self.assertIsNone(self.look.getInverseTransform())

exp_tr = OCIO.ExponentTransform()
exp_values = [-0.1, -0.2, -0.3, -0.4]
michdolan marked this conversation as resolved.
Show resolved Hide resolved
exp_tr.setValue(exp_values)
self.look.setInverseTransform(exp_tr)
inv_oet = self.look.getInverseTransform()
self.assertListEqual(inv_oet.getValue(), exp_values)

# Wrong type tests.
with self.assertRaises(TypeError):
self.look.setInverseTransform(OCIO.ALLOCATION_UNIFORM)
self.look.setInverseTransform(1)

def test_constructor_with_keyword(self):
"""
Test Look constructor with keywords and validate its values.
"""

# With keywords in their proper order.
exp_tr = OCIO.ExponentTransform()
inv_exp_tr = OCIO.ExponentTransform()
look = OCIO.Look(name='coollook',
processSpace='somespace',
transform=exp_tr,
inverseTransform=inv_exp_tr,
description='this is a test')

self.assertEqual(look.getName(), 'coollook')
self.assertEqual(look.getProcessSpace(), 'somespace')
self.assertIsInstance(look.getTransform(), type(exp_tr))
self.assertIsInstance(look.getInverseTransform(), type(inv_exp_tr))
self.assertEqual(look.getDescription(), 'this is a test')

# With keyword not in their proper order.
exp_tr2 = OCIO.ExponentTransform()
inv_exp_tr2 = OCIO.ExponentTransform()
look2 = OCIO.Look(inverseTransform=inv_exp_tr,
description='this is a test',
name='coollook',
processSpace='somespace',
transform=exp_tr)

self.assertEqual(look2.getName(), 'coollook')
self.assertEqual(look2.getProcessSpace(), 'somespace')
self.assertIsInstance(look2.getTransform(), type(exp_tr2))
self.assertIsInstance(look2.getInverseTransform(), type(inv_exp_tr2))
self.assertEqual(look2.getDescription(), 'this is a test')

def test_constructor_without_keyword(self):
michdolan marked this conversation as resolved.
Show resolved Hide resolved
"""
Test Look constructor without keywords and validate its values.
"""

exp_tr = OCIO.ExponentTransform()
inv_exp_tr = OCIO.ExponentTransform()
look = OCIO.Look('coollook',
'somespace',
exp_tr,
inv_exp_tr,
'this is a test')

self.assertEqual(look.getName(), 'coollook')
self.assertEqual(look.getProcessSpace(), 'somespace')
self.assertIsInstance(look.getTransform(), type(exp_tr))
self.assertIsInstance(look.getInverseTransform(), type(inv_exp_tr))
self.assertEqual(look.getDescription(), 'this is a test')

def test_constructor_without_parameter(self):
michdolan marked this conversation as resolved.
Show resolved Hide resolved
"""
Test Look default constructor and validate its values.
"""

look = OCIO.Look()

self.assertEqual(look.getName(), '')
self.assertEqual(look.getProcessSpace(), '')
self.assertIsNone(look.getTransform())
self.assertIsNone(look.getInverseTransform())
self.assertEqual(look.getDescription(), '')

def test_constructor_wrong_parameter_type(self):
"""
Test Look constructor with a wrong parameter type.
"""

with self.assertRaises(TypeError):
look = OCIO.Look(None)
look = OCIO.Look(1)
4 changes: 2 additions & 2 deletions tests/python/OpenColorIOTestSuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

import ColorSpaceTest
import CDLTransformTest
import LookTest
Copy link
Contributor

Choose a reason for hiding this comment

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

it could be nice to sort these in alphabetical order

#from MainTest import *
#from ConstantsTest import *
#from ConfigTest import *
#from ContextTest import *
#from LookTest import *
#from GpuShaderDescTest import *
#from Baker import *
#from TransformsTest import *
Expand All @@ -55,12 +55,12 @@ def suite():

suite.addTest(loader.loadTestsFromModule(ColorSpaceTest))
suite.addTest(loader.loadTestsFromModule(CDLTransformTest))
suite.addTest(loader.loadTestsFromModule(LookTest))
Copy link
Contributor

Choose a reason for hiding this comment

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

alphabetical order?

#suite.addTest(MainTest("test_interface"))
#suite.addTest(ConstantsTest("test_interface"))
#suite.addTest(ConfigTest("test_interface"))
#suite.addTest(ConfigTest("test_is_editable"))
#suite.addTest(ContextTest("test_interface"))
#suite.addTest(LookTest("test_interface"))
#suite.addTest(RangeTransformTest("test_interface"))
#suite.addTest(RangeTransformTest("test_equality"))
#suite.addTest(RangeTransformTest("test_validation"))
Expand Down