2 # -*- coding: utf-8 -*-
5 Defines unit tests for the generated *ACES* configuration.
15 from aces_ocio.util import files_walker
16 from aces_ocio.create_aces_config import (
17 ACES_OCIO_CTL_DIRECTORY_ENVIRON,
27 __all__ = ['REFERENCE_CONFIG_ROOT_DIRECTORY',
29 'UNHASHABLE_TEST_PATTERNS',
33 # TODO: Investigate how the current config has been generated to use it for
35 # REFERENCE_CONFIG_ROOT_DIRECTORY = os.path.abspath(
36 # os.path.join(os.path.dirname(__file__), '..', '..'))
37 REFERENCE_CONFIG_ROOT_DIRECTORY = '/colour-science/colour-ramblings/ocio/aces'
39 HASH_TEST_PATTERNS = ('\.3dl', '\.lut', '\.csp')
40 UNHASHABLE_TEST_PATTERNS = ('\.icc', '\.ocio')
43 class TestACESConfig(unittest.TestCase):
49 Initialises common tests attributes.
52 self.__aces_ocio_ctl_directory = os.environ.get(
53 ACES_OCIO_CTL_DIRECTORY_ENVIRON, None)
55 assert self.__aces_ocio_ctl_directory is not None, (
56 'Undefined "{0}" environment variable!'.format(
57 ACES_OCIO_CTL_DIRECTORY_ENVIRON))
59 assert os.path.exists(self.__aces_ocio_ctl_directory) is True, (
60 '"{0}" directory does not exists!'.format(
61 self.__aces_ocio_ctl_directory))
64 self.__temporary_directory = tempfile.mkdtemp()
71 shutil.rmtree(self.__temporary_directory)
74 def directory_hashes(directory, filters_in=None, filters_out=None):
79 for path in files_walker(directory,
80 filters_in=filters_in,
81 filters_out=filters_out):
82 with open(path) as file:
84 re.sub('\s', '', file.read())).hexdigest()
85 hashes[path.replace(directory, '')] = hash
88 def test_ACES_config(self):
92 self.assertTrue(createACESConfig(self.__aces_ocio_ctl_directory,
93 self.__temporary_directory))
95 reference_hashes = self.directory_hashes(
96 REFERENCE_CONFIG_ROOT_DIRECTORY,
98 test_hashes = self.directory_hashes(
99 self.__temporary_directory,
102 self.assertDictEqual(reference_hashes, test_hashes)
104 # Checking that unashable files ('.icc', '.ocio') are generated.
105 unashable = lambda x: (
106 sorted([file.replace(x, '') for file in
107 files_walker(x, UNHASHABLE_TEST_PATTERNS)]))
109 self.assertListEqual(unashable(REFERENCE_CONFIG_ROOT_DIRECTORY),
110 unashable(self.__temporary_directory))
113 if __name__ == '__main__':