def test_aproximate_modified_equality_double(self): expected = self._get_test_proto() actual = self._get_test_proto() expected.bars[0].precision = 2.3 + 1.1e-15 actual.bars[0].precision = 2.3 + 1.2e-15 assert_that(actual, not_(equals_proto(expected))) assert_that(actual, approximately(equals_proto(expected)))
def test_ignore_field_single(self): expected = text_format.Parse('baz { status: ERROR }', test_pb2.Foo()) actual = text_format.Parse('', test_pb2.Foo()) assert_that(actual, not_(equals_proto(expected))) assert_that(actual, ignoring_field_paths({('baz',)}, equals_proto(expected)))
def test_ignore_field_repeated(self): expected = self._get_test_proto() actual = self._get_test_proto() del actual.bars[:] assert_that(actual, not_(equals_proto(expected))) assert_that(actual, ignoring_field_paths({('bars',)}, equals_proto(expected)))
def test_ignore_field_nested(self): expected = self._get_test_proto() actual = self._get_test_proto() actual.bars[0].size = 2 assert_that(actual, not_(equals_proto(expected))) assert_that( actual, ignoring_field_paths({('bars', 'size')}, equals_proto(expected)))
def test_compare_proto_repeated_fields_ignoring_order(self): expected = self._get_test_proto() actual = self._get_test_proto() reversed_bars = actual.bars[::-1] del actual.bars[:] actual.bars.extend(reversed_bars) assert_that(actual, not_(equals_proto(expected))) assert_that(actual, ignoring_repeated_field_ordering(equals_proto(expected)))
def test_ignore_field_multiple(self): expected = self._get_test_proto() actual = self._get_test_proto() del actual.bars[:] actual.baz.status = test_pb2.Baz.OK assert_that( actual, not_(ignoring_field_paths({('baz',)}, equals_proto(expected)))) assert_that( actual, not_(ignoring_field_paths({('bars',)}, equals_proto(expected)))) assert_that( actual, ignoring_field_paths({('bars',), ('baz',)}, equals_proto(expected)))
def test_within_fraction_or_margin_float(self): expected = self._get_test_proto() actual = self._get_test_proto() expected.bars[0].progress = 100.0 actual.bars[0].progress = 109.9 assert_that(actual, not_(equals_proto(expected))) assert_that(actual, approximately(equals_proto(expected), float_margin=10.0)) assert_that(actual, approximately(equals_proto(expected), float_fraction=0.2)) assert_that( actual, not_(approximately(equals_proto(expected), float_fraction=0.01))) assert_that( actual, approximately(equals_proto(expected), float_fraction=0.1, float_margin=10.0))
def test_partial_equality_test_extra_field(self): expected = self._get_test_proto() expected.baz.Clear() assert_that(self._get_test_proto(), partially(equals_proto(expected)))
def test_basic_partial_equality(self): assert_that(self._get_test_proto(), partially(equals_proto(_TEST_PROTO)))
def test_map_field_inequality(self): expected = self._get_test_proto() expected.mapping[15] = 'luck' assert_that(self._get_test_proto(), not_(equals_proto(expected)))
def test_basic_inequality(self): expected = self._get_test_proto() expected.baz.Clear() assert_that(self._get_test_proto(), not_(equals_proto(expected)))
def test_taking_expected_text_proto(self): assert_that(self._get_test_proto(), equals_proto(_TEST_PROTO))
def test_repeated_field_partial_inequality(self): expected = self._get_test_proto() expected.bars.add().progress = 0.1 assert_that(self._get_test_proto(), not_(partially(equals_proto(expected))))
def test_oneof_inequality(self): expected = self._get_test_proto() expected.bars[0].long_id = expected.bars[0].short_id assert_that(self._get_test_proto(), not_(equals_proto(expected)))
def test_basic_partial_inequality(self): expected = self._get_test_proto() expected.baz.status = test_pb2.Baz.OK assert_that(self._get_test_proto(), not_(partially(equals_proto(expected))))
def test_partial_inequality_missing_field(self): actual = self._get_test_proto() actual.baz.Clear() assert_that(actual, not_(partially(equals_proto(_TEST_PROTO))))
def test_basic_equality(self): expected = self._get_test_proto() assert_that(self._get_test_proto(), equals_proto(expected))
def test_aproximate_equality(self): actual = self._get_test_proto() assert_that(actual, approximately(equals_proto(_TEST_PROTO)))
def test_aproximate_modified_equality(self): expected = self._get_test_proto() actual = self._get_test_proto() expected.bars[0].progress = 2.300005 actual.bars[0].progress = 2.300006 assert_that(actual, approximately(equals_proto(expected)))