Google OR-Tools
v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
proto_matcher.py
Go to the documentation of this file.
1
# Copyright 2010-2024 Google LLC
2
# Licensed under the Apache License, Version 2.0 (the "License");
3
# you may not use this file except in compliance with the License.
4
# You may obtain a copy of the License at
5
#
6
# http://www.apache.org/licenses/LICENSE-2.0
7
#
8
# Unless required by applicable law or agreed to in writing, software
9
# distributed under the License is distributed on an "AS IS" BASIS,
10
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
# See the License for the specific language governing permissions and
12
# limitations under the License.
13
14
"""A matcher that tests if protos meet MathOpts definition of equivalence.
15
16
This is designed to be used with unittest.mock, which is canonical for mocking
17
in Google Python (e.g., see stubby codelabs).
18
19
See normalize.py for technical definitions.
20
21
The matcher can be used as a replacement for
22
google3.net.proto2.contrib.pyutil.matcher.Proto2Matcher
23
but supports a much smaller set of features.
24
"""
25
26
import
copy
27
28
from
google.protobuf
import
message
29
from
ortools.math_opt.python
import
normalize
30
31
32
class
MathOptProtoEquivMatcher
:
33
"""Matcher that checks if protos are equivalent in the MathOpt sense.
34
35
See normalize.py for technical definitions.
36
"""
37
38
def
__init__
(self, expected: message.Message):
39
self.
_expected
= copy.deepcopy(expected)
40
normalize.math_opt_normalize_proto(self.
_expected
)
41
42
def
__eq__
(self, actual: message.Message) -> bool:
43
actual = copy.deepcopy(actual)
44
normalize.math_opt_normalize_proto(actual)
45
return
str(actual) == str(self.
_expected
)
46
47
def
__ne__
(self, other: message.Message) -> bool:
48
return
not
self == other
ortools.math_opt.python.testing.proto_matcher.MathOptProtoEquivMatcher
Definition
proto_matcher.py:32
ortools.math_opt.python.testing.proto_matcher.MathOptProtoEquivMatcher.__ne__
bool __ne__(self, message.Message other)
Definition
proto_matcher.py:47
ortools.math_opt.python.testing.proto_matcher.MathOptProtoEquivMatcher.__init__
__init__(self, message.Message expected)
Definition
proto_matcher.py:38
ortools.math_opt.python.testing.proto_matcher.MathOptProtoEquivMatcher._expected
_expected
Definition
proto_matcher.py:39
ortools.math_opt.python.testing.proto_matcher.MathOptProtoEquivMatcher.__eq__
bool __eq__(self, message.Message actual)
Definition
proto_matcher.py:42
ortools.math_opt.python
Definition
__init__.py:1
build
python
ortools
math_opt
python
testing
proto_matcher.py
Generated by
1.12.0