示例#1
0
 def testAssertEqualWithStringArg(self):
     pb = compare_test_pb2.Large()
     pb.string_ = 'abc'
     pb.float_ = 1.234
     compare.assertProto2Equal(
         self, """
       string_: 'abc'
       float_: 1.234
     """, pb)
 def testAssertEqualWithStringArg(self):
   pb = compare_test_pb2.Large()
   pb.string_ = 'abc'
   pb.float_ = 1.234
   compare.assertProto2Equal(
       self,
       """
         string_: 'abc'
         float_: 1.234
       """,
       pb)
示例#3
0
  def testNormalizesFloat(self):
    pb1 = compare_test_pb2.Large()
    pb1.double_ = 4.0
    pb2 = compare_test_pb2.Large()
    pb2.double_ = 4
    compare.assertProto2Equal(self, pb1, pb2, normalize_numbers=True)

    pb1 = compare_test_pb2.Medium()
    pb1.floats.extend([4.0, 6.0])
    pb2 = compare_test_pb2.Medium()
    pb2.floats.extend([6, 4])
    compare.assertProto2SameElements(self, pb1, pb2, normalize_numbers=True)
示例#4
0
    def _AssertProtoEquals(self, a, b):
        """Asserts that a and b are the same proto.

    Uses Proto2Cmp() first, as it returns correct results
    for floating point attributes, and then use assertProto2Equal()
    in case of failure as it provides good error messages.

    Args:
      a: a proto.
      b: another proto.
    """
        if compare.Proto2Cmp(a, b) != 0:
            compare.assertProto2Equal(self, a, b, normalize_numbers=True)
示例#5
0
  def _AssertProtoEquals(self, a, b):
    """Asserts that a and b are the same proto.

    Uses Proto2Cmp() first, as it returns correct results
    for floating point attributes, and then use assertProto2Equal()
    in case of failure as it provides good error messages.

    Args:
      a: a proto.
      b: another proto.
    """
    if compare.Proto2Cmp(a, b) != 0:
      compare.assertProto2Equal(self, a, b, normalize_numbers=True)
示例#6
0
 def testNormalizesNumbers(self):
   pb1 = compare_test_pb2.Large()
   pb1.int64_ = 4
   pb2 = compare_test_pb2.Large()
   pb2.int64_ = 4
   compare.assertProto2Equal(self, pb1, pb2)
示例#7
0
 def assertProto2Equal(self, a, b, **kwargs):
   if isinstance(a, basestring) and isinstance(b, basestring):
     a, b = LargePbs(a, b)
   compare.assertProto2Equal(self, a, b, **kwargs)
示例#8
0
 def assertProto2Equal(self, a, b, **kwargs):
     if isinstance(a, six.string_types) and isinstance(b, six.string_types):
         a, b = LargePbs(a, b)
     compare.assertProto2Equal(self, a, b, **kwargs)