Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Model.__eq__ logic #355

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bravado_core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,7 @@ def __eq__(self, other):
Two model instances are equal if they have the same type and the same
properties and values (including additional properties).
"""
# Check same type as self
if type(self) is not type(other):
if not isinstance(other, self.__class__):
return False

# Ignore any '_raw' keys
Expand Down
10 changes: 9 additions & 1 deletion tests/model/model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,20 @@ def test_model_issubclass_inherits_from(pet_type, cat_type):
assert issubclass(cat_type, pet_type)


def test_model_isinstance_model_class_generate_by_different_Spec_object(cat_swagger_spec, cat_type, cat_kwargs):
def test_model_isinstance_model_class_generated_by_different_Spec_object(cat_swagger_spec, cat_type, cat_kwargs):
cat = cat_type(**cat_kwargs)
new_cat_spec = Spec.from_dict(cat_swagger_spec.client_spec_dict)
assert isinstance(cat, new_cat_spec.definitions['Cat'])


def test_model_equality_if_model_class_generated_by_different_Spec_object(cat_swagger_spec, cat_type, cat_kwargs):
cat = cat_type(**cat_kwargs)
new_cat_spec = Spec.from_dict(cat_swagger_spec.client_spec_dict)
new_cat_type = new_cat_spec.definitions['Cat']
new_cat = new_cat_type(**cat_kwargs)
assert cat == new_cat


def test_model_deepcopy(user_type, user_kwargs):
user = user_type(**user_kwargs)
user_copy = deepcopy(user)
Expand Down