Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
ortools.math_opt.python.testing.compare_proto Namespace Reference

Classes

class  MathOptProtoAssertions

Functions

None assert_protos_equal (unittest.TestCase test, message.Message actual, message.Message expected)
None assert_protos_equiv (unittest.TestCase test, message.Message actual, message.Message expected)

Detailed Description

Assertions to compare protocol buffers.

Two comparisons are provided:

1. assert_protos_equal(): Checks that two messages are exactly the same (roughly
speaking, they should produce the same binary representation).
2. assert_protos_equiv(): Checks that two messages are equivalent in the MathOpt
sense (roughly speaking, empty submessages being set/unset do not matter,
details below).

(2) is reduced to (1) by recursively clearing empty messages via normalize.py.
To implement (1),
in open source we check that the text proto representations are the same (this
is a slightly weaker test).

The exact contract for assert_protos_equiv() is as follows.
Empty sub-messages (recursively) have no effect on equivalence, except for the
Duration message, otherwise the same as proto equality. Oneof messages have
their fields recursively cleared, but the oneof itself is not, to preserve the
selection. This is similar to C++ EquivToProto, but this function cares about:
  * field presence for optional scalar fields,
  * field presence for Duration messages (e.g. Duration unset of time limit
    means +inf),
  * field presence for one_ofs,
and C++ EquivToProto does not.

See normalize.py for details.

Function Documentation

◆ assert_protos_equal()

None ortools.math_opt.python.testing.compare_proto.assert_protos_equal ( unittest.TestCase test,
message.Message actual,
message.Message expected )
Asserts the input protos are equal, see module doc for details.

Definition at line 51 of file compare_proto.py.

◆ assert_protos_equiv()

None ortools.math_opt.python.testing.compare_proto.assert_protos_equiv ( unittest.TestCase test,
message.Message actual,
message.Message expected )
Asserts the input protos are equivalent, see module doc for details.

Definition at line 60 of file compare_proto.py.