2 # -*- coding: utf-8 -*-
5 Defines unit tests for *ACES* configuration.
8 from __future__ import division
17 from aces_ocio.utilities import files_walker
18 from aces_ocio.create_aces_config import (
19 ACES_OCIO_CTL_DIRECTORY_ENVIRON,
22 __author__ = 'ACES Developers'
23 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
25 __maintainer__ = 'ACES Developers'
26 __email__ = 'aces@oscars.org'
27 __status__ = 'Production'
29 __all__ = ['REFERENCE_CONFIG_ROOT_DIRECTORY',
31 'UNHASHABLE_TEST_PATTERNS',
35 # TODO: Investigate how the current config has been generated to use it for
37 # REFERENCE_CONFIG_ROOT_DIRECTORY = os.path.abspath(
38 # os.path.join(os.path.dirname(__file__), '..', '..', '..'))
39 REFERENCE_CONFIG_ROOT_DIRECTORY = '/colour-science/colour-ramblings/ocio/aces'
41 HASH_TEST_PATTERNS = ('\.3dl', '\.lut', '\.csp')
42 UNHASHABLE_TEST_PATTERNS = ('\.icc', '\.ocio')
45 class TestACESConfig(unittest.TestCase):
47 Performs tests on the *ACES* configuration.
52 Initialises common tests attributes.
55 self.__aces_ocio_ctl_directory = os.environ.get(
56 ACES_OCIO_CTL_DIRECTORY_ENVIRON, None)
58 assert self.__aces_ocio_ctl_directory is not None, (
59 'Undefined "{0}" environment variable!'.format(
60 ACES_OCIO_CTL_DIRECTORY_ENVIRON))
62 assert os.path.exists(self.__aces_ocio_ctl_directory) is True, (
63 '"{0}" directory does not exists!'.format(
64 self.__aces_ocio_ctl_directory))
67 self.__temporary_directory = tempfile.mkdtemp()
74 shutil.rmtree(self.__temporary_directory)
77 def directory_hashes(directory,
82 Recursively computes the hashes from the file within given directory.
86 directory : str or unicode
87 Directory to compute the file hashes.
88 filters_in : array_like
90 filters_out : array_like
98 Directory file hashes.
102 for path in files_walker(directory,
103 filters_in=filters_in,
104 filters_out=filters_out,
106 with open(path) as file:
107 digest = hashlib.md5(
108 re.sub('\s', '', file.read())).hexdigest()
109 hashes[path.replace(directory, '')] = digest
112 def test_ACES_config(self):
114 Performs tests on the *ACES* configuration by computing hashes on the
115 generated configuration and comparing them to the existing one.
118 self.assertTrue(create_ACES_config(self.__aces_ocio_ctl_directory,
119 self.__temporary_directory))
121 reference_hashes = self.directory_hashes(
122 REFERENCE_CONFIG_ROOT_DIRECTORY,
124 test_hashes = self.directory_hashes(
125 self.__temporary_directory,
128 self.assertDictEqual(reference_hashes, test_hashes)
130 # Checking that unashable files ('.icc', '.ocio') are generated.
131 unashable = lambda x: (
132 sorted([file.replace(x, '') for file in
133 files_walker(x, UNHASHABLE_TEST_PATTERNS)]))
135 self.assertListEqual(unashable(REFERENCE_CONFIG_ROOT_DIRECTORY),
136 unashable(self.__temporary_directory))
139 if __name__ == '__main__':