Exemplo n.º 1
0
 def testNonBoolean(self):
   decoder = option_decoders.BooleanDecoder(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 "int"). '
       'Value must be one of the following types: bool.'))
 def testValidBoolean(self):
     decoder = option_decoders.BooleanDecoder(option=_OPTION)
     self.assertIs(decoder.Decode(True, _COMPONENT, _FLAGS), True)
 def testNone(self):
     decoder = option_decoders.BooleanDecoder(none_ok=True, option=_OPTION)
     self.assertIsNone(decoder.Decode(None, _COMPONENT, _FLAGS))
     decoder = option_decoders.BooleanDecoder(option=_OPTION)
     with self.assertRaises(errors.Config.InvalidValue):
         decoder.Decode(None, _COMPONENT, _FLAGS)
 def testDefault(self):
     decoder = option_decoders.BooleanDecoder(default=None, option=_OPTION)
     self.assertIs(decoder.required, False)
     self.assertIsNone(decoder.default)