2 # -*- coding: utf-8 -*-
5 Defines unit tests for *ACES* configuration.
15 from aces_ocio.utilities import files_walker
16 from aces_ocio.create_aces_config import (
17 ACES_OCIO_CTL_DIRECTORY_ENVIRON,
20 __author__ = 'ACES Developers'
21 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
23 __maintainer__ = 'ACES Developers'
24 __email__ = 'aces@oscars.org'
25 __status__ = 'Production'
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):
45 Performs tests on the *ACES* configuration.
50 Initialises common tests attributes.
53 self.__aces_ocio_ctl_directory = os.environ.get(
54 ACES_OCIO_CTL_DIRECTORY_ENVIRON, None)
56 assert self.__aces_ocio_ctl_directory is not None, (
57 'Undefined "{0}" environment variable!'.format(
58 ACES_OCIO_CTL_DIRECTORY_ENVIRON))
60 assert os.path.exists(self.__aces_ocio_ctl_directory) is True, (
61 '"{0}" directory does not exists!'.format(
62 self.__aces_ocio_ctl_directory))
65 self.__temporary_directory = tempfile.mkdtemp()
72 shutil.rmtree(self.__temporary_directory)
75 def directory_hashes(directory,
80 Recursively computes the hashes from the file within given directory.
84 directory : str or unicode
85 Directory to compute the file hashes.
86 filters_in : array_like
88 filters_out : array_like
96 Directory file hashes.
100 for path in files_walker(directory,
101 filters_in=filters_in,
102 filters_out=filters_out,
104 with open(path) as file:
105 digest = hashlib.md5(
106 re.sub('\s', '', file.read())).hexdigest()
107 hashes[path.replace(directory, '')] = digest
110 def test_ACES_config(self):
112 Performs tests on the *ACES* configuration by computing hashes on the
113 generated configuration and comparing them to the existing one.
116 self.assertTrue(create_ACES_config(self.__aces_ocio_ctl_directory,
117 self.__temporary_directory))
119 reference_hashes = self.directory_hashes(
120 REFERENCE_CONFIG_ROOT_DIRECTORY,
122 test_hashes = self.directory_hashes(
123 self.__temporary_directory,
126 self.assertDictEqual(reference_hashes, test_hashes)
128 # Checking that unashable files ('.icc', '.ocio') are generated.
129 unashable = lambda x: (
130 sorted([file.replace(x, '') for file in
131 files_walker(x, UNHASHABLE_TEST_PATTERNS)]))
133 self.assertListEqual(unashable(REFERENCE_CONFIG_ROOT_DIRECTORY),
134 unashable(self.__temporary_directory))
137 if __name__ == '__main__':