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.generate_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__), '..', '..', '..'))
44 HASH_TEST_PATTERNS = ('\.3dl', '\.lut', '\.csp')
45 UNHASHABLE_TEST_PATTERNS = ('\.icc', '\.ocio')
48 class TestACESConfig(unittest.TestCase):
50 Performs tests on the *ACES* configuration.
55 Initialises common tests attributes.
58 self.__aces_ocio_ctl_directory = os.environ.get(
59 ACES_OCIO_CTL_DIRECTORY_ENVIRON, None)
61 assert self.__aces_ocio_ctl_directory is not None, (
62 'Undefined "{0}" environment variable!'.format(
63 ACES_OCIO_CTL_DIRECTORY_ENVIRON))
65 assert os.path.exists(self.__aces_ocio_ctl_directory) is True, (
66 '"{0}" directory does not exists!'.format(
67 self.__aces_ocio_ctl_directory))
70 self.__temporary_directory = tempfile.mkdtemp()
77 shutil.rmtree(self.__temporary_directory)
80 def directory_hashes(directory,
85 Recursively computes the hashes from the file within given directory.
89 directory : str or unicode
90 Directory to compute the file hashes.
91 filters_in : array_like
93 filters_out : array_like
101 Directory file hashes.
105 for path in files_walker(directory,
106 filters_in=filters_in,
107 filters_out=filters_out,
109 with open(path) as file:
110 digest = hashlib.md5(
111 re.sub('\s', '', file.read())).hexdigest()
112 hashes[path.replace(directory, '')] = digest
115 def test_ACES_config(self):
117 Performs tests on the *ACES* configuration by computing hashes on the
118 generated configuration and comparing them to the existing one.
121 self.assertTrue(generate_config(self.__aces_ocio_ctl_directory,
122 self.__temporary_directory))
124 reference_hashes = self.directory_hashes(
125 REFERENCE_CONFIG_ROOT_DIRECTORY,
127 test_hashes = self.directory_hashes(
128 self.__temporary_directory,
131 self.assertDictEqual(reference_hashes, test_hashes)
133 # Checking that unashable files ('.icc', '.ocio') are generated.
134 unashable = lambda x: (
135 sorted([file.replace(x, '') for file in
136 files_walker(x, UNHASHABLE_TEST_PATTERNS)]))
138 self.assertListEqual(unashable(REFERENCE_CONFIG_ROOT_DIRECTORY),
139 unashable(self.__temporary_directory))
142 if __name__ == '__main__':