def test_to_toolchain_dict(self): """ Test toolchain string to dict conversion """ # normal cases self.assertEqual(to_toolchain_dict(('intel', '2015a')), { 'name': 'intel', 'version': '2015a' }) self.assertEqual(to_toolchain_dict("intel, 2015a"), { 'name': 'intel', 'version': '2015a' }) self.assertEqual(to_toolchain_dict(['gcc', '4.7']), { 'name': 'gcc', 'version': '4.7' }) # incl. hidden spec expected = {'name': 'intel', 'version': '2015a', 'hidden': True} self.assertEqual(to_toolchain_dict("intel, 2015a, True"), expected) expected = {'name': 'intel', 'version': '2015a', 'hidden': False} self.assertEqual(to_toolchain_dict(('intel', '2015a', 'False')), expected) expected = {'name': 'gcc', 'version': '4.7', 'hidden': True} self.assertEqual(to_toolchain_dict(['gcc', '4.7', 'True']), expected) tc = {'name': 'intel', 'version': '2015a'} self.assertEqual(to_toolchain_dict(tc), tc) tc = {'name': 'intel', 'version': '2015a', 'hidden': True} self.assertEqual(to_toolchain_dict(tc), tc) # wrong type self.assertErrorRegex( EasyBuildError, r"Conversion of .* \(type .*\) to toolchain dict is not supported", to_toolchain_dict, 1000) # wrong number of elements errstr = "Can not convert .* to toolchain dict. Expected 2 or 3 elements" self.assertErrorRegex(EasyBuildError, errstr, to_toolchain_dict, "intel, 2015, True, a") self.assertErrorRegex(EasyBuildError, errstr, to_toolchain_dict, "intel") self.assertErrorRegex(EasyBuildError, errstr, to_toolchain_dict, ['gcc', '4', 'False', '7']) # invalid truth value errstr = "invalid truth value .*" self.assertErrorRegex(ValueError, errstr, to_toolchain_dict, "intel, 2015, foo") self.assertErrorRegex(ValueError, errstr, to_toolchain_dict, ['gcc', '4', '7']) # missing keys self.assertErrorRegex(EasyBuildError, "Incorrect set of keys", to_toolchain_dict, {'name': 'intel'})
def test_to_toolchain_dict(self): """ Test toolchain string to dict conversion """ # normal cases self.assertEqual(to_toolchain_dict(('intel', '2015a')), {'name': 'intel', 'version': '2015a'}) self.assertEqual(to_toolchain_dict("intel, 2015a"), {'name': 'intel', 'version': '2015a'}) self.assertEqual(to_toolchain_dict(['gcc', '4.7']), {'name': 'gcc', 'version': '4.7'}) # incl. hidden spec expected = {'name': 'intel', 'version': '2015a', 'hidden': True} self.assertEqual(to_toolchain_dict("intel, 2015a, True"), expected) expected = {'name': 'intel', 'version': '2015a', 'hidden': False} self.assertEqual(to_toolchain_dict(('intel', '2015a', 'False')), expected) expected = {'name': 'gcc', 'version': '4.7', 'hidden': True} self.assertEqual(to_toolchain_dict(['gcc', '4.7', 'True']), expected) tc = {'name': 'intel', 'version': '2015a'} self.assertEqual(to_toolchain_dict(tc), tc) tc = {'name': 'intel', 'version': '2015a', 'hidden': True} self.assertEqual(to_toolchain_dict(tc), tc) # wrong type self.assertErrorRegex(EasyBuildError, r"Conversion of .* \(type .*\) to toolchain dict is not supported", to_toolchain_dict, 1000) # wrong number of elements errstr = "Can not convert .* to toolchain dict. Expected 2 or 3 elements" self.assertErrorRegex(EasyBuildError, errstr, to_toolchain_dict, "intel, 2015, True, a") self.assertErrorRegex(EasyBuildError, errstr, to_toolchain_dict, "intel") self.assertErrorRegex(EasyBuildError, errstr, to_toolchain_dict, ['gcc', '4', 'False', '7']) # invalid truth value errstr = "invalid truth value .*" self.assertErrorRegex(ValueError, errstr, to_toolchain_dict, "intel, 2015, foo") self.assertErrorRegex(ValueError, errstr, to_toolchain_dict, ['gcc', '4', '7']) # missing keys self.assertErrorRegex(EasyBuildError, "Incorrect set of keys", to_toolchain_dict, {'name': 'intel'})