def constraint_test(self): s2 = {"os": None} self.sut.constraint(s2) with self.assertRaises(ConanException) as cm: self.sut.compiler self.assertEqual(str(cm.exception), undefined_field("settings", "compiler", ["os"])) self.sut.os = "Windows" self.sut.os = "Linux"
def constraint5_test(self): s2 = {"os": None, "compiler": {"Visual Studio": {"version2": None}}} with self.assertRaises(ConanException) as cm: self.sut.constraint(s2) self.assertEqual(str(cm.exception), undefined_field("settings.compiler", "version2", ['runtime', 'version'])) self.sut.os = "Windows"
def constraint5_test(self): s2 = {"os": None, "compiler": {"Visual Studio": {"version2": None}}} with self.assertRaises(ConanException) as cm: self.sut.constraint(s2) self.assertEqual( str(cm.exception), undefined_field("settings.compiler", "version2", ['runtime', 'version'])) self.sut.os = "Windows"
def constraint6_test(self): s2 = {"os": None, "compiler": {"Visual Studio": {"version": None}}} self.sut.constraint(s2) self.sut.compiler = "Visual Studio" with self.assertRaises(ConanException) as cm: self.sut.compiler.arch self.assertEqual(str(cm.exception), undefined_field("settings.compiler", "arch", ['version'], "Visual Studio")) self.sut.os = "Windows" self.sut.compiler.version = "11" self.sut.compiler.version = "12"
def constraint6_test(self): s2 = {"os": None, "compiler": {"Visual Studio": {"version": None}}} self.sut.constraint(s2) self.sut.compiler = "Visual Studio" with self.assertRaises(ConanException) as cm: self.sut.compiler.arch self.assertEqual( str(cm.exception), undefined_field("settings.compiler", "arch", ['version'], "Visual Studio")) self.sut.os = "Windows" self.sut.compiler.version = "11" self.sut.compiler.version = "12"
def constraint(self, constraint_def): """ allows to restrict a given Settings object with the input of another Settings object 1. The other Settings object MUST be exclusively a subset of the former. No additions allowed 2. If the other defines {"compiler": None} means to keep the full specification """ if isinstance(constraint_def, (list, tuple, set)): constraint_def = {str(k): None for k in constraint_def or []} else: constraint_def = {str(k): v for k, v in constraint_def.iteritems()} fields_to_remove = [] for field, config_item in self._data.iteritems(): if field not in constraint_def: fields_to_remove.append(field) continue other_field_def = constraint_def[field] if other_field_def is None: # Means leave it as is continue values_to_remove = [] for value in config_item.values_range: # value = "Visual Studio" if value not in other_field_def: values_to_remove.append(value) else: # recursion if (not config_item.is_final and isinstance(other_field_def, dict) and other_field_def[value] is not None): config_item[value].constraint(other_field_def[value]) # Sanity check of input constraint values for value in other_field_def: if value not in config_item.values_range: raise ConanException( bad_value_msg(field, value, config_item.values_range)) config_item.remove(values_to_remove) # Sanity check for input constraint wrong fields for field in constraint_def: if field not in self._data: raise ConanException( undefined_field(self._name, field, self.fields)) # remove settings not defined in the constraint self.remove(fields_to_remove)
def constraint(self, constraint_def): """ allows to restrict a given Settings object with the input of another Settings object 1. The other Settings object MUST be exclusively a subset of the former. No additions allowed 2. If the other defines {"compiler": None} means to keep the full specification """ if isinstance(constraint_def, (list, tuple, set)): constraint_def = {str(k): None for k in constraint_def or []} else: constraint_def = {str(k): v for k, v in constraint_def.items()} fields_to_remove = [] for field, config_item in self._data.items(): if field not in constraint_def: fields_to_remove.append(field) continue other_field_def = constraint_def[field] if other_field_def is None: # Means leave it as is continue values_to_remove = [] for value in config_item.values_range: # value = "Visual Studio" if value not in other_field_def: values_to_remove.append(value) else: # recursion if (not config_item.is_final and isinstance(other_field_def, dict) and other_field_def[value] is not None): config_item[value].constraint(other_field_def[value]) # Sanity check of input constraint values for value in other_field_def: if value not in config_item.values_range: raise ConanException(bad_value_msg(field, value, config_item.values_range)) config_item.remove(values_to_remove) # Sanity check for input constraint wrong fields for field in constraint_def: if field not in self._data: raise ConanException(undefined_field(self._name, field, self.fields)) # remove settings not defined in the constraint self.remove(fields_to_remove)
def my_test(self): self.assertEqual(self.sut.compiler, None) with self.assertRaises(ConanException) as cm: self.sut.compiler = "kk" self.assertEqual( str(cm.exception), bad_value_msg("settings.compiler", "kk", "['Visual Studio', 'gcc']")) self.sut.compiler = "Visual Studio" self.assertEqual(str(self.sut.compiler), "Visual Studio") self.assertEqual(self.sut.compiler, "Visual Studio") with self.assertRaises(ConanException) as cm: self.sut.compiler.kk self.assertEqual( str(cm.exception), undefined_field("settings.compiler", "kk", "['runtime', 'version']", "Visual Studio")) self.assertEqual(self.sut.compiler.version, None) with self.assertRaises(ConanException) as cm: self.sut.compiler.version = "123" self.assertEqual( str(cm.exception), bad_value_msg("settings.compiler.version", "123", ['10', '11', '12'])) self.sut.compiler.version = "12" self.assertEqual(self.sut.compiler.version, "12") self.assertEqual(str(self.sut.compiler.version), "12") with self.assertRaises(ConanException) as cm: assert self.sut.compiler == "kk" self.assertEqual( str(cm.exception), bad_value_msg("settings.compiler", "kk", "['Visual Studio', 'gcc']")) self.assertFalse(self.sut.compiler == "gcc") self.assertTrue(self.sut.compiler == "Visual Studio") self.assertTrue(self.sut.compiler.version == "12") self.assertFalse(self.sut.compiler.version == "11") with self.assertRaises(ConanException) as cm: assert self.sut.compiler.version == "13" self.assertEqual( str(cm.exception), bad_value_msg("settings.compiler.version", "13", ['10', '11', '12'])) self.sut.compiler = "gcc" with self.assertRaises(ConanException) as cm: self.sut.compiler.runtime self.assertEqual( str(cm.exception), undefined_field("settings.compiler", "runtime", "['arch', 'version']", "gcc")) self.sut.compiler.arch = "x86" self.sut.compiler.arch.speed = "A" self.assertEqual(self.sut.compiler.arch.speed, "A") with self.assertRaises(ConanException) as cm: self.sut.compiler.arch.speed = "D" self.assertEqual( str(cm.exception), bad_value_msg("settings.compiler.arch.speed", "D", ['A', 'B'])) self.sut.compiler.arch = "x64" self.sut.compiler.arch.speed = "C" self.assertEqual(self.sut.compiler.arch.speed, "C") with self.assertRaises(ConanException) as cm: self.sut.compiler.arch.speed = "A" self.assertEqual( str(cm.exception), bad_value_msg("settings.compiler.arch.speed", "A", ['C', 'D'])) self.sut.compiler.arch.speed = "D" self.assertEqual(self.sut.compiler.arch.speed, "D")
def my_test(self): self.assertEqual(self.sut.compiler, None) with self.assertRaises(ConanException) as cm: self.sut.compiler = "kk" self.assertEqual(str(cm.exception), bad_value_msg("settings.compiler", "kk", "['Visual Studio', 'gcc']")) self.sut.compiler = "Visual Studio" self.assertEqual(str(self.sut.compiler), "Visual Studio") self.assertEqual(self.sut.compiler, "Visual Studio") with self.assertRaises(ConanException) as cm: self.sut.compiler.kk self.assertEqual(str(cm.exception), undefined_field("settings.compiler", "kk", "['runtime', 'version']", "Visual Studio")) self.assertEqual(self.sut.compiler.version, None) with self.assertRaises(ConanException) as cm: self.sut.compiler.version = "123" self.assertEqual(str(cm.exception), bad_value_msg("settings.compiler.version", "123", ['10', '11', '12'])) self.sut.compiler.version = "12" self.assertEqual(self.sut.compiler.version, "12") self.assertEqual(str(self.sut.compiler.version), "12") with self.assertRaises(ConanException) as cm: assert self.sut.compiler == "kk" self.assertEqual(str(cm.exception), bad_value_msg("settings.compiler", "kk", "['Visual Studio', 'gcc']")) self.assertFalse(self.sut.compiler == "gcc") self.assertTrue(self.sut.compiler == "Visual Studio") self.assertTrue(self.sut.compiler.version == "12") self.assertFalse(self.sut.compiler.version == "11") with self.assertRaises(ConanException) as cm: assert self.sut.compiler.version == "13" self.assertEqual(str(cm.exception), bad_value_msg("settings.compiler.version", "13", ['10', '11', '12'])) self.sut.compiler = "gcc" with self.assertRaises(ConanException) as cm: self.sut.compiler.runtime self.assertEqual(str(cm.exception), undefined_field("settings.compiler", "runtime", "['arch', 'version']", "gcc")) self.sut.compiler.arch = "x86" self.sut.compiler.arch.speed = "A" self.assertEqual(self.sut.compiler.arch.speed, "A") with self.assertRaises(ConanException) as cm: self.sut.compiler.arch.speed = "D" self.assertEqual(str(cm.exception), bad_value_msg("settings.compiler.arch.speed", "D", ['A', 'B'])) self.sut.compiler.arch = "x64" self.sut.compiler.arch.speed = "C" self.assertEqual(self.sut.compiler.arch.speed, "C") with self.assertRaises(ConanException) as cm: self.sut.compiler.arch.speed = "A" self.assertEqual(str(cm.exception), bad_value_msg("settings.compiler.arch.speed", "A", ['C', 'D'])) self.sut.compiler.arch.speed = "D" self.assertEqual(self.sut.compiler.arch.speed, "D")
def constraint2_test(self): s2 = {"os2": None} with self.assertRaises(ConanException) as cm: self.sut.constraint(s2) self.assertEqual(str(cm.exception), undefined_field("settings", "os2", ["compiler", "os"]))