def test_enums_custom_error(self):
        Enum = c.enum({'V1': '1', 'V2': '2', 'V3': '3'})

        observer = Mock()
        ctx = context.create(validation_error_observer=observer)
        Enum('V4', ctx=ctx)
        observer.on_error.assert_called_once_with(_ANY_CONTEXT, 'V1 or V2 or V3', 'V4')
    def test_named_enums(self):
        Enum = c.enum({'V1': '1', 'V2': '2', 'V3': '3'}, name='MyEnum')

        self.assertEqual('1', Enum.V1)
        self.assertEqual('2', Enum.V2)
        self.assertEqual('3', Enum.V3)

        e = Enum('V1')
        self.assertEqual('1', e)

        with self.assertRaises(exceptions.PyCombValidationError) as e:
            Enum('V4')
        e = e.exception
        self.assertEqual('Error on MyEnum: expected V1 or V2 or V3 but was V4', e.args[0])
 def test_enums_production(self):
     Enum = c.enum({'V1': '1', 'V2': '2', 'V3': '3'})
     self.assertEqual('V4', Enum('V4', ctx=context.create(production_mode=True)))