def test_unsupported_string_constraints(self): # A ValueError is raised if unsupported string constraints are found. with self.assertRaises(ValueError) as context_manager: utils._prepare_constraints('cpu-cores=4,invalid1=1,invalid2=2') self.assertEqual( 'unsupported constraints: invalid1, invalid2', str(context_manager.exception))
def test_invalid_string_constraints(self): # A ValueError is raised if unsupported string constraints are found. with self.assertRaises(ValueError) as context_manager: utils._prepare_constraints('arch=,cpu-cores=,') self.assertEqual( 'invalid constraints: arch=,cpu-cores=,', str(context_manager.exception))
def test_invalid_constraints(self): # A ValueError is raised if unsupported constraints are found. with self.assertRaises(ValueError) as context_manager: utils._prepare_constraints({'arch': 'i386', 'not-valid': 'bang!'}) self.assertEqual( 'unsupported constraints: not-valid', str(context_manager.exception))
def test_valid_constraints(self): # Valid constraints are returned as they are. constraints = { 'arch': 'i386', 'cpu-cores': 4, 'cpu-power': 2, 'mem': 2000, } self.assertEqual(constraints, utils._prepare_constraints(constraints))
def test_string_constraints(self): # String constraints are converted to a dict. constraints = 'arch=i386,cpu-cores=4,cpu-power=2,mem=2000' expected = { 'arch': 'i386', 'cpu-cores': '4', 'cpu-power': '2', 'mem': '2000', } self.assertEqual(expected, utils._prepare_constraints(constraints))
def test_string_constraints_subset(self): # A subset of string constraints is converted to a dict. constraints = 'cpu-cores=4,mem=2000' expected = {'cpu-cores': '4', 'mem': '2000'} self.assertEqual(expected, utils._prepare_constraints(constraints))
def test_valid_constraints_subset(self): # A subset of valid constraints is returned as it is. constraints = {'cpu-cores': '4', 'cpu-power': 2} self.assertEqual(constraints, utils._prepare_constraints(constraints))