示例#1
0
    def test_check_type_of_param_value_sanity_check_paths(self):
        """Test check_type_of_param_value function for sanity_check_paths."""

        # sanity_check_paths (type check)
        inputs = [
            {'files': [], 'dirs': []},
            {'files': ['bin/foo'], 'dirs': [('lib', 'lib64')]},
            {'files': ['bin/foo', ('bin/bar', 'bin/baz')], 'dirs': []},
        ]
        for inp in inputs:
            self.assertEqual(check_type_of_param_value('sanity_check_paths', inp), (True, inp))

        inputs = [
            {},
            {'files': []},
            {'files': [], 'dirs': [], 'somethingelse': []},
            {'files': [['bin/foo']], 'dirs': []},
            {'files': [], 'dirs': [1]},
            {'files': ['foo'], 'dirs': [(1, 2)]},
        ]
        for inp in inputs:
            self.assertEqual(check_type_of_param_value('sanity_check_paths', inp), (False, None))

        # sanity_check_paths (auto-convert)
        inp = {'files': ['bin/foo', ['bin/bar', 'bin/baz']], 'dirs': [['lib', 'lib64', 'lib32']]}
        out = {'files': ['bin/foo', ('bin/bar', 'bin/baz')], 'dirs': [('lib', 'lib64', 'lib32')]}
        self.assertEqual(check_type_of_param_value('sanity_check_paths', inp, auto_convert=True), (True, out))
    def test_check_type_of_param_value(self):
        """Test check_type_of_param_value function."""
        # check selected values that should be strings
        for key in ['name', 'version']:
            self.assertEqual(check_type_of_param_value(key, 'foo'), (True, 'foo'))
            for not_a_string in [100, 1.5, ('bar',), ['baz'], None]:
                self.assertEqual(check_type_of_param_value(key, not_a_string), (False, None))
            # value doesn't matter, only type does
            self.assertEqual(check_type_of_param_value(key, ''), (True, ''))

        # parameters with no type specification always pass the check
        key = 'nosucheasyconfigparametereverhopefully'
        for val in ['foo', 100, 1.5, ('bar',), ['baz'], '', None]:
            self.assertEqual(check_type_of_param_value(key, val), (True, val))

        # check use of auto_convert
        self.assertEqual(check_type_of_param_value('version', 1.5), (False, None))
        self.assertEqual(check_type_of_param_value('version', 1.5, auto_convert=True), (True, '1.5'))

        # check type checking of toolchain (non-trivial type: dict with only name/version keys & string values)
        toolchain = {'name': 'goolf', 'version': '1.4.10'}
        self.assertEqual(check_type_of_param_value('toolchain', toolchain), (True, toolchain))
        # missing 'version' key
        self.assertEqual(check_type_of_param_value('toolchain', {'name': 'intel'}), (False, None))
        # non-string value for 'version'
        toolchain = {'name': 'goolf', 'version': 100}
        self.assertEqual(check_type_of_param_value('toolchain', toolchain), (False, None))

        # check auto-converting of toolchain value
        toolchain = {'name': 'intel', 'version': '2015a'}
        for tcspec in ["intel, 2015a", ['intel', '2015a'], toolchain]:
            self.assertEqual(check_type_of_param_value('toolchain', tcspec, auto_convert=True), (True, toolchain))
    def test_check_type_of_param_value_sanity_check_paths(self):
        """Test check_type_of_param_value function for sanity_check_paths."""

        # sanity_check_paths (type check)
        inputs = [
            {'files': [], 'dirs': []},
            {'files': ['bin/foo'], 'dirs': [('lib', 'lib64')]},
            {'files': ['bin/foo', ('bin/bar', 'bin/baz')], 'dirs': []},
        ]
        for inp in inputs:
            self.assertEqual(check_type_of_param_value('sanity_check_paths', inp), (True, inp))

        inputs = [
            {},
            {'files': []},
            {'files': [], 'dirs': [], 'somethingelse': []},
            {'files': [['bin/foo']], 'dirs': []},
            {'files': [], 'dirs': [1]},
            {'files': ['foo'], 'dirs': [(1, 2)]},
        ]
        for inp in inputs:
            self.assertEqual(check_type_of_param_value('sanity_check_paths', inp), (False, None))

        # sanity_check_paths (auto-convert)
        inp = {'files': ['bin/foo', ['bin/bar', 'bin/baz']], 'dirs': [['lib', 'lib64', 'lib32']]}
        out = {'files': ['bin/foo', ('bin/bar', 'bin/baz')], 'dirs': [('lib', 'lib64', 'lib32')]}
        self.assertEqual(check_type_of_param_value('sanity_check_paths', inp, auto_convert=True), (True, out))
示例#4
0
    def check_values_types(self, cfg):
        """
        Check types of easyconfig parameter values.

        :param cfg: dictionary with easyconfig parameter values (result of get_config_dict())
        """
        wrong_type_msgs = []
        for key in cfg:
            type_ok, newval = check_type_of_param_value(
                key, cfg[key], self.auto_convert)
            if not type_ok:
                wrong_type_msgs.append(
                    "value for '%s' should be of type '%s'" %
                    (key, PARAMETER_TYPES[key].__name__))
            elif newval != cfg[key]:
                warning_msg = "Value for '%s' easyconfig parameter was converted from %s (type: %s) to %s (type: %s)"
                self.log.warning(warning_msg, key, cfg[key], type(cfg[key]),
                                 newval, type(newval))
                cfg[key] = newval

        if wrong_type_msgs:
            raise EasyBuildError(
                "Type checking of easyconfig parameter values failed: %s",
                ', '.join(wrong_type_msgs))
        else:
            self.log.info(
                "Type checking of easyconfig parameter values passed!")
    def test_check_type_of_param_value_toolchain(self):
        """Test check_type_of_param_value function for toolchain."""

        # check type checking of toolchain (non-trivial type: dict with only name/version keys & string values)
        toolchain = {'name': 'goolf', 'version': '1.4.10'}
        self.assertEqual(check_type_of_param_value('toolchain', toolchain), (True, toolchain))
        # missing 'version' key
        self.assertEqual(check_type_of_param_value('toolchain', {'name': 'intel'}), (False, None))
        # non-string value for 'version'
        toolchain = {'name': 'goolf', 'version': 100}
        self.assertEqual(check_type_of_param_value('toolchain', toolchain), (False, None))

        # check auto-converting of toolchain value
        toolchain = {'name': 'intel', 'version': '2015a'}
        for tcspec in ["intel, 2015a", ['intel', '2015a'], toolchain]:
            self.assertEqual(check_type_of_param_value('toolchain', tcspec, auto_convert=True), (True, toolchain))
    def test_check_type_of_param_value(self):
        """Test check_type_of_param_value function."""
        # check selected values that should be strings
        for key in ['name', 'version']:
            self.assertEqual(check_type_of_param_value(key, 'foo'),
                             (True, 'foo'))
            for not_a_string in [100, 1.5, ('bar', ), ['baz'], None]:
                self.assertEqual(check_type_of_param_value(key, not_a_string),
                                 (False, None))
            # value doesn't matter, only type does
            self.assertEqual(check_type_of_param_value(key, ''), (True, ''))

        # parameters with no type specification always pass the check
        key = 'nosucheasyconfigparametereverhopefully'
        for val in ['foo', 100, 1.5, ('bar', ), ['baz'], '', None]:
            self.assertEqual(check_type_of_param_value(key, val), (True, val))

        # check use of auto_convert
        self.assertEqual(check_type_of_param_value('version', 1.5),
                         (False, None))
        self.assertEqual(
            check_type_of_param_value('version', 1.5, auto_convert=True),
            (True, '1.5'))

        # check type checking of toolchain (non-trivial type: dict with only name/version keys & string values)
        toolchain = {'name': 'goolf', 'version': '1.4.10'}
        self.assertEqual(check_type_of_param_value('toolchain', toolchain),
                         (True, toolchain))
        # missing 'version' key
        self.assertEqual(
            check_type_of_param_value('toolchain', {'name': 'intel'}),
            (False, None))
        # non-string value for 'version'
        toolchain = {'name': 'goolf', 'version': 100}
        self.assertEqual(check_type_of_param_value('toolchain', toolchain),
                         (False, None))

        # check auto-converting of toolchain value
        toolchain = {'name': 'intel', 'version': '2015a'}
        for tcspec in ["intel, 2015a", ['intel', '2015a'], toolchain]:
            self.assertEqual(
                check_type_of_param_value('toolchain',
                                          tcspec,
                                          auto_convert=True),
                (True, toolchain))
示例#7
0
    def test_check_type_of_param_value_deps(self):
        """Test check_type_of_param_value function for *dependencies."""

        # dependencies (type check)
        inputs = [
            [],
            [{'name': 'foo', 'version': '1.2.3'}],
            [{'name': 'foo', 'version': '1.2.3', 'versionsuffix': ''}],
            [{'name': 'foo', 'version': '1.2.3', 'versionsuffix': '', 'toolchain': {'name': 'GCC', 'version': '4.7'}}],
            [{'name': 'foo', 'version': '1.2.3', 'toolchain': {'name': 'GCC', 'version': '4.7'}}],
            [{'name': 'foo', 'version': '1.2.3'}, {'name': 'bar', 'version': '3.4.5'}],
        ]
        for inp in inputs:
            self.assertEqual(check_type_of_param_value('dependencies', inp), (True, inp))

        inputs = [
            ['foo'],
            [{'name': 'foo'}],
            ['foo,1.2.3'],
            [{'foo': '1.2.3'}],
            [('foo', '1.2.3')],
            [{'name': 'foo', 'version': '1.2.3'}, ('bar', '3.4.5')],
            [{'name': 'foo', 'version': '1.2.3', 'somekey': 'wrong'}],
        ]
        for inp in inputs:
            self.assertEqual(check_type_of_param_value('dependencies', inp), (False, None))

        # dependencies (auto-convert)
        self.assertEqual(check_type_of_param_value('dependencies', [{'foo': '1.2.3'}], auto_convert=True),
                         (True, [{'name': 'foo', 'version': '1.2.3'}]))
        # tuple values pass through untouched (are handled later by EasyConfig._parse_dependency)
        inp = [('foo', '1.2.3')]
        self.assertEqual(check_type_of_param_value('dependencies', inp, auto_convert=True), (True, [('foo', '1.2.3')]))
        inp = [('foo', '1.2.3'), {'bar': '3.4.5'}, ('baz', '9.8.7')]
        out = (True, [('foo', '1.2.3'), {'name': 'bar', 'version': '3.4.5'}, ('baz', '9.8.7')])
        self.assertEqual(check_type_of_param_value('dependencies', inp, auto_convert=True), out)

        # osdependencies (type check)
        inputs = [
            ['zlib'],
            [('openssl-devel', 'libssl-dev', 'libopenssl-devel')],
            ['zlib', ('openssl-devel', 'libssl-dev', 'libopenssl-devel')],
        ]
        for inp in inputs:
            self.assertEqual(check_type_of_param_value('osdependencies', inp), (True, inp))

        inp = ['zlib', ['openssl-devel', 'libssl-dev', 'libopenssl-devel']]
        self.assertEqual(check_type_of_param_value('osdependencies', inp), (False, None))

        # osdependencies (auto-convert)
        out = ['zlib', ('openssl-devel', 'libssl-dev', 'libopenssl-devel')]
        self.assertEqual(check_type_of_param_value('osdependencies', inp, auto_convert=True), (True, out))
    def test_check_type_of_param_value_deps(self):
        """Test check_type_of_param_value function for *dependencies."""

        # dependencies (type check)
        inputs = [
            [],
            [{'name': 'foo', 'version': '1.2.3'}],
            [{'name': 'foo', 'version': '1.2.3', 'versionsuffix': ''}],
            [{'name': 'foo', 'version': '1.2.3', 'versionsuffix': '', 'toolchain': {'name': 'GCC', 'version': '4.7'}}],
            [{'name': 'foo', 'version': '1.2.3', 'toolchain': {'name': 'GCC', 'version': '4.7'}}],
            [{'name': 'foo', 'version': '1.2.3'}, {'name': 'bar', 'version': '3.4.5'}],
        ]
        for inp in inputs:
            self.assertEqual(check_type_of_param_value('dependencies', inp), (True, inp))

        inputs = [
            ['foo'],
            [{'name': 'foo'}],
            ['foo,1.2.3'],
            [{'foo': '1.2.3'}],
            [('foo', '1.2.3')],
            [{'name': 'foo', 'version': '1.2.3'}, ('bar', '3.4.5')],
            [{'name': 'foo', 'version': '1.2.3', 'somekey': 'wrong'}],
        ]
        for inp in inputs:
            self.assertEqual(check_type_of_param_value('dependencies', inp), (False, None))

        # dependencies (auto-convert)
        self.assertEqual(check_type_of_param_value('dependencies', [{'foo': '1.2.3'}], auto_convert=True),
                         (True, [{'name': 'foo', 'version': '1.2.3'}]))
        # tuple values pass through untouched (are handled later by EasyConfig._parse_dependency)
        inp = [('foo', '1.2.3')]
        self.assertEqual(check_type_of_param_value('dependencies', inp, auto_convert=True), (True, [('foo', '1.2.3')]))
        inp = [('foo', '1.2.3'), {'bar': '3.4.5'}, ('baz', '9.8.7')]
        out = (True, [('foo', '1.2.3'), {'name': 'bar', 'version': '3.4.5'}, ('baz', '9.8.7')])
        self.assertEqual(check_type_of_param_value('dependencies', inp, auto_convert=True), out)

        # osdependencies (type check)
        inputs = [
            ['zlib'],
            [('openssl-devel', 'libssl-dev', 'libopenssl-devel')],
            ['zlib', ('openssl-devel', 'libssl-dev', 'libopenssl-devel')],
        ]
        for inp in inputs:
            self.assertEqual(check_type_of_param_value('osdependencies', inp), (True, inp))

        inp = ['zlib', ['openssl-devel', 'libssl-dev', 'libopenssl-devel']]
        self.assertEqual(check_type_of_param_value('osdependencies', inp), (False, None))

        # osdependencies (auto-convert)
        out = ['zlib', ('openssl-devel', 'libssl-dev', 'libopenssl-devel')]
        self.assertEqual(check_type_of_param_value('osdependencies', inp, auto_convert=True), (True, out))
示例#9
0
    def test_check_type_of_param_value_checksums(self):
        """Test check_type_of_param_value function for checksums."""

        md5_checksum = 'fa618be8435447a017fd1bf2c7ae9224'
        sha256_checksum1 = 'fa618be8435447a017fd1bf2c7ae922d0428056cfc7449f7a8641edf76b48265'
        sha256_checksum2 = 'b5f9cb06105c1d2d30719db5ffb3ea67da60919fb68deaefa583deccd8813551'
        sha256_checksum3 = '033be54514a03e255df75c5aee8f9e672f663f93abb723444caec8fe43437bde'

        # valid values for 'checksums' easyconfig parameters
        inputs = [
            [],
            # single checksum (one file)
            [md5_checksum],
            [sha256_checksum1],
            # one checksum, for 3 files
            [sha256_checksum1, sha256_checksum2, sha256_checksum3],
            # one checksum of specific type (as 2-tuple)
            [('md5', md5_checksum)],
            [('sha256', sha256_checksum1)],
            # alternative checksums for a single file (n-tuple)
            [(sha256_checksum1, sha256_checksum2)],
            [(sha256_checksum1, sha256_checksum2, sha256_checksum3)],
            [(sha256_checksum1, sha256_checksum2, sha256_checksum3, md5_checksum)],
            [(md5_checksum,)],
            # multiple checksums of specific type, one for each file
            [('md5', md5_checksum), ('sha256', sha256_checksum1)],
            # checksum as dict (file to checksum mapping)
            [{'foo.txt': sha256_checksum1, 'bar.txt': sha256_checksum2}],
            # list of checksums for a single file
            [[md5_checksum]],
            [[sha256_checksum1, sha256_checksum2, sha256_checksum3]],
            # in the mix (3 files, each a different kind of checksum spec)...
            [
                sha256_checksum1,
                ('md5', md5_checksum),
                {'foo.txt': sha256_checksum2, 'bar.txt': sha256_checksum3},
            ],
            # each item can be a list of checksums for a single file, which can be of different types...
            [
                # two checksums for a single file, *both* should match
                [sha256_checksum1, md5_checksum],
                # three checksums for a single file, *all* should match
                [sha256_checksum1, ('md5', md5_checksum), {'foo.txt': sha256_checksum1}],
                # single checksum for a single file
                sha256_checksum1,
                # filename-to-checksum mapping
                {'foo.txt': sha256_checksum1, 'bar.txt': sha256_checksum2},
                # 3 alternative checksums for a single file, one match is sufficient
                (sha256_checksum1, sha256_checksum2, sha256_checksum3),
            ]
        ]
        for inp in inputs:
            self.assertEqual(check_type_of_param_value('checksums', inp), (True, inp))
示例#10
0
    def test_check_type_of_param_value_toolchain(self):
        """Test check_type_of_param_value function for toolchain."""

        # check type checking of toolchain (non-trivial type: dict with only name/version keys & string values)
        toolchain = {'name': 'goolf', 'version': '1.4.10'}
        self.assertEqual(check_type_of_param_value('toolchain', toolchain),
                         (True, toolchain))
        # missing 'version' key
        self.assertEqual(
            check_type_of_param_value('toolchain', {'name': 'intel'}),
            (False, None))
        # non-string value for 'version'
        toolchain = {'name': 'goolf', 'version': 100}
        self.assertEqual(check_type_of_param_value('toolchain', toolchain),
                         (False, None))

        # check auto-converting of toolchain value
        toolchain = {'name': 'intel', 'version': '2015a'}
        for tcspec in ["intel, 2015a", ['intel', '2015a'], toolchain]:
            self.assertEqual(
                check_type_of_param_value('toolchain',
                                          tcspec,
                                          auto_convert=True),
                (True, toolchain))
示例#11
0
    def test_check_type_of_param_value_name_version(self):
        """Test check_type_of_param_value function for name/version."""
        # check selected values that should be strings
        for key in ['name', 'version']:
            self.assertEqual(check_type_of_param_value(key, 'foo'), (True, 'foo'))
            for not_a_string in [100, 1.5, ('bar',), ['baz'], None]:
                self.assertEqual(check_type_of_param_value(key, not_a_string), (False, None))
            # value doesn't matter, only type does
            self.assertEqual(check_type_of_param_value(key, ''), (True, ''))

        # parameters with no type specification always pass the check
        key = 'nosucheasyconfigparametereverhopefully'
        for val in ['foo', 100, 1.5, ('bar',), ['baz'], '', None]:
            self.assertEqual(check_type_of_param_value(key, val), (True, val))

        # check use of auto_convert
        self.assertEqual(check_type_of_param_value('version', 1.5), (False, None))
        self.assertEqual(check_type_of_param_value('version', 1.5, auto_convert=True), (True, '1.5'))
示例#12
0
    def test_check_type_of_param_value_name_version(self):
        """Test check_type_of_param_value function for name/version."""
        # check selected values that should be strings
        for key in ['name', 'version']:
            self.assertEqual(check_type_of_param_value(key, 'foo'), (True, 'foo'))
            for not_a_string in [100, 1.5, ('bar',), ['baz'], None]:
                self.assertEqual(check_type_of_param_value(key, not_a_string), (False, None))
            # value doesn't matter, only type does
            self.assertEqual(check_type_of_param_value(key, ''), (True, ''))

        # parameters with no type specification always pass the check
        key = 'nosucheasyconfigparametereverhopefully'
        for val in ['foo', 100, 1.5, ('bar',), ['baz'], '', None]:
            self.assertEqual(check_type_of_param_value(key, val), (True, val))

        # check use of auto_convert
        self.assertEqual(check_type_of_param_value('version', 1.5), (False, None))
        self.assertEqual(check_type_of_param_value('version', 1.5, auto_convert=True), (True, '1.5'))