2 # -*- coding: utf-8 -*-
5 Defines unit tests for *ACES* configuration.
8 from __future__ import division
18 sys.path.append(os.path.abspath(
19 os.path.join(os.path.dirname(__file__), '..', '..')))
21 from aces_ocio.utilities import files_walker
22 from aces_ocio.aces_config import (
23 ACES_OCIO_CTL_DIRECTORY_ENVIRON,
26 __author__ = 'ACES Developers'
27 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
29 __maintainer__ = 'ACES Developers'
30 __email__ = 'aces@oscars.org'
31 __status__ = 'Production'
33 __all__ = ['REFERENCE_CONFIG_ROOT_DIRECTORY',
35 'UNHASHABLE_TEST_PATTERNS',
39 # TODO: Investigate how the current config has been generated to use it for
41 REFERENCE_CONFIG_ROOT_DIRECTORY = os.path.abspath(
42 os.path.join(os.path.dirname(__file__), '..', '..', '..'))
43 # REFERENCE_CONFIG_ROOT_DIRECTORY = '/colour-science/colour-ramblings/ocio/aces'
45 HASH_TEST_PATTERNS = ('\.3dl', '\.lut', '\.csp')
46 UNHASHABLE_TEST_PATTERNS = ('\.icc', '\.ocio')
49 class TestACESConfig(unittest.TestCase):
51 Performs tests on the *ACES* configuration.
56 Initialises common tests attributes.
59 self.__aces_ocio_ctl_directory = os.environ.get(
60 ACES_OCIO_CTL_DIRECTORY_ENVIRON, None)
62 assert self.__aces_ocio_ctl_directory is not None, (
63 'Undefined "{0}" environment variable!'.format(
64 ACES_OCIO_CTL_DIRECTORY_ENVIRON))
66 assert os.path.exists(self.__aces_ocio_ctl_directory) is True, (
67 '"{0}" directory does not exists!'.format(
68 self.__aces_ocio_ctl_directory))
71 self.__temporary_directory = tempfile.mkdtemp()
78 shutil.rmtree(self.__temporary_directory)
81 def directory_hashes(directory,
86 Recursively computes the hashes from the file within given directory.
90 directory : str or unicode
91 Directory to compute the file hashes.
92 filters_in : array_like
94 filters_out : array_like
102 Directory file hashes.
106 for path in files_walker(directory,
107 filters_in=filters_in,
108 filters_out=filters_out,
110 with open(path) as file:
111 digest = hashlib.md5(
112 re.sub('\s', '', file.read())).hexdigest()
113 hashes[path.replace(directory, '')] = digest
116 def test_ACES_config(self):
118 Performs tests on the *ACES* configuration by computing hashes on the
119 generated configuration and comparing them to the existing one.
122 self.assertTrue(create_ACES_config(self.__aces_ocio_ctl_directory,
123 self.__temporary_directory))
125 reference_hashes = self.directory_hashes(
126 REFERENCE_CONFIG_ROOT_DIRECTORY,
128 test_hashes = self.directory_hashes(
129 self.__temporary_directory,
132 self.assertDictEqual(reference_hashes, test_hashes)
134 # Checking that unashable files ('.icc', '.ocio') are generated.
135 unashable = lambda x: (
136 sorted([file.replace(x, '') for file in
137 files_walker(x, UNHASHABLE_TEST_PATTERNS)]))
139 self.assertListEqual(unashable(REFERENCE_CONFIG_ROOT_DIRECTORY),
140 unashable(self.__temporary_directory))
143 if __name__ == '__main__':