def testZeroMaxOrMin(self): decoder = option_decoders.IntDecoder(max=0, min=0, option=_OPTION) with self.assertRaises(errors.Config.InvalidValue): decoder.Decode(-1, _COMPONENT, _FLAGS) with self.assertRaises(errors.Config.InvalidValue): decoder.Decode(1, _COMPONENT, _FLAGS) self.assertEqual(decoder.Decode(0, _COMPONENT, _FLAGS), 0)
def testNonInt(self): decoder = option_decoders.IntDecoder(option=_OPTION) with self.assertRaises(errors.Config.InvalidValue) as cm: decoder.Decode('5', _COMPONENT, _FLAGS) self.assertEqual(str(cm.exception), ( 'Invalid test_component.test_option value: "5" (of type "str"). ' 'Value must be one of the following types: int.'))
def testMin(self): decoder = option_decoders.IntDecoder(min=10, option=_OPTION) with self.assertRaises(errors.Config.InvalidValue) as cm: decoder.Decode(5, _COMPONENT, _FLAGS) self.assertEqual(str(cm.exception), ( 'Invalid test_component.test_option value: "5". Value must be at ' 'least 10.')) self.assertIs(decoder.Decode(10, _COMPONENT, _FLAGS), 10) self.assertIs(decoder.Decode(15, _COMPONENT, _FLAGS), 15)
def testMax(self): decoder = option_decoders.IntDecoder(max=2, option=_OPTION) with self.assertRaises(errors.Config.InvalidValue) as cm: decoder.Decode(5, _COMPONENT, _FLAGS) self.assertEqual(str(cm.exception), ( 'Invalid test_component.test_option value: "5". Value must be at ' 'most 2.')) self.assertIs(decoder.Decode(2, _COMPONENT, _FLAGS), 2) self.assertIs(decoder.Decode(1, _COMPONENT, _FLAGS), 1)
def setUp(self): super(ListDecoderTestCase, self).setUp() self._int_decoder = option_decoders.IntDecoder()
def testNone(self): decoder = option_decoders.FloatDecoder(none_ok=True, option=_OPTION) self.assertIsNone(decoder.Decode(None, _COMPONENT, _FLAGS)) decoder = option_decoders.IntDecoder(option=_OPTION) with self.assertRaises(errors.Config.InvalidValue): decoder.Decode(None, _COMPONENT, _FLAGS)
def testValidInt(self): decoder = option_decoders.IntDecoder(option=_OPTION) self.assertEqual(decoder.Decode(5, _COMPONENT, _FLAGS), 5)
def testDefault(self): decoder = option_decoders.IntDecoder(default=5, option=_OPTION) self.assertIs(decoder.required, False) self.assertIs(decoder.default, 5)