Yelp / bravado-core

Other
109 stars 98 forks source link

Update Model.__eq__ logic #355

Closed macisamuele closed 4 years ago

macisamuele commented 4 years ago

Model equality check was implemented by ensuring that two objects of the same class and with the same "dict" representation are considered the same.

As far as this definition is valid we might do it a bit better. Currently, isinstance and issubclass checks do consider equivalent model types generated by different bravado_core.spec.Spec instances if they are created out of the same specs (same url and content). So what can happen is that

instance1 = spec1.definitions['model1'](...)
instance2 = spec2.definitions['model1']model1(...)

assert isinstance(instance1, instance2.__class__)
assert isinstance(instance2, instance1.__class__)
assert instance1._as_dict() == instance2._as_dict()
assert instance1 == instance2  # This would fail with the currently released bravado-core and succeed after this PR

The added test, test_model_equality_if_model_class_generated_by_different_Spec_object, will ensure that regression will be catched if the behaviour will change and it currently fails if the changes in bravado_core/model.py are reverted

coveralls commented 4 years ago

Coverage Status

Coverage decreased (-0.1%) to 98.895% when pulling 820ed6c2834c8d67942bd77d14efeaeceecbd4c5 on macisamuele:maci-update-equality-condition-of-models into d92cab7083545d5006bd607d144a5374b783280c on Yelp:master.