| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -174,5 +174,5 @@ def __setitem__(self, key, value): | |||
| 174 | 174 | ||
| 175 | 175 | def insert(self, index: int, value): | |
| 176 | 176 | """Insert ``value`` in the sequence before ``index``.""" | |
| 177 | - pb_value = self._marshal.to_proto(self._pb_type, value, strict=True) | ||
| 177 | + pb_value = self._marshal.to_proto(self._pb_type, value) | ||
| 178 | 178 | self.pb.insert(index, pb_value) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,24 @@ | |||
| 1 | + # Copyright (C) 2021 Google LLC | ||
| 2 | + # | ||
| 3 | + # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + # you may not use this file except in compliance with the License. | ||
| 5 | + # You may obtain a copy of the License at | ||
| 6 | + # | ||
| 7 | + # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + # | ||
| 9 | + # Unless required by applicable law or agreed to in writing, software | ||
| 10 | + # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + # See the License for the specific language governing permissions and | ||
| 13 | + # limitations under the License. | ||
| 14 | + | ||
| 15 | + import proto | ||
| 16 | + from proto.marshal.marshal import BaseMarshal | ||
| 17 | + import pytest | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + def test_strict_to_proto(): | ||
| 21 | + m = BaseMarshal() | ||
| 22 | + | ||
| 23 | + with pytest.raises(TypeError): | ||
| 24 | + m.to_proto(dict, None, strict=True) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,3 +58,35 @@ class Foo(proto.Enum): | |||
| 58 | 58 | with mock.patch.object(warnings, "warn") as warn: | |
| 59 | 59 | assert enum_rule.to_python(4) == 4 | |
| 60 | 60 | warn.assert_called_once_with("Unrecognized Foo enum value: 4") | |
| 61 | + | ||
| 62 | + | ||
| 63 | + def test_enum_append(): | ||
| 64 | + class Bivalve(proto.Enum): | ||
| 65 | + CLAM = 0 | ||
| 66 | + OYSTER = 1 | ||
| 67 | + | ||
| 68 | + class MolluscContainer(proto.Message): | ||
| 69 | + bivalves = proto.RepeatedField(proto.ENUM, number=1, enum=Bivalve,) | ||
| 70 | + | ||
| 71 | + mc = MolluscContainer() | ||
| 72 | + clam = Bivalve.CLAM | ||
| 73 | + mc.bivalves.append(clam) | ||
| 74 | + mc.bivalves.append(1) | ||
| 75 | + | ||
| 76 | + assert mc.bivalves == [clam, Bivalve.OYSTER] | ||
| 77 | + | ||
| 78 | + | ||
| 79 | + def test_enum_map_insert(): | ||
| 80 | + class Bivalve(proto.Enum): | ||
| 81 | + CLAM = 0 | ||
| 82 | + OYSTER = 1 | ||
| 83 | + | ||
| 84 | + class MolluscContainer(proto.Message): | ||
| 85 | + bivalves = proto.MapField(proto.STRING, proto.ENUM, number=1, enum=Bivalve,) | ||
| 86 | + | ||
| 87 | + mc = MolluscContainer() | ||
| 88 | + clam = Bivalve.CLAM | ||
| 89 | + mc.bivalves["clam"] = clam | ||
| 90 | + mc.bivalves["oyster"] = 1 | ||
| 91 | + | ||
| 92 | + assert mc.bivalves == {"clam": clam, "oyster": Bivalve.OYSTER} | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments