def test_to_python():
    class Foo(proto.Enum):
        FOO_UNSPECIFIED = 0
        BAR = 1
        BAZ = 2

    enum_rule = EnumRule(Foo)
    foo_a = enum_rule.to_python(1)
    foo_b = enum_rule.to_python(Foo.BAR)
    assert foo_a is foo_b is Foo.BAR
def test_to_python_unknown_value():
    class Foo(proto.Enum):
        FOO_UNSPECIFIED = 0
        BAR = 1
        BAZ = 2

    enum_rule = EnumRule(Foo)
    with mock.patch.object(warnings, 'warn') as warn:
        assert enum_rule.to_python(4) == 4
        warn.assert_called_once_with('Unrecognized Foo enum value: 4')