File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -128,6 +128,11 @@ def __init_subclass_with_meta__(
128128
129129 is_type_of = None
130130
131+ def __eq__ (self , other ):
132+ if isinstance (other , self .__class__ ):
133+ return self .__dict__ == other .__dict__
134+ return False
135+
131136 def __init__ (self , * args , ** kwargs ):
132137 # ObjectType acting as container
133138 args_len = len (args )
Original file line number Diff line number Diff line change @@ -35,6 +35,40 @@ def get_type(self):
3535 return MyType
3636
3737
38+ def test_equality ():
39+ # instances of object with no properties are equal
40+ class NoPropertiesObject (ObjectType ):
41+ pass
42+
43+ my_obj = NoPropertiesObject ()
44+ assert my_obj == NoPropertiesObject ()
45+
46+
47+ # different classes are unequal
48+ class OtherNoPropertiesObject (ObjectType ):
49+ pass
50+
51+ assert NoPropertiesObject () != OtherNoPropertiesObject ()
52+
53+
54+ # compare instances of the same simple class
55+ class MyObjectType (ObjectType ):
56+ prop = String ()
57+
58+ my_obj = MyObjectType (prop = "a" )
59+ assert my_obj == MyObjectType (prop = "a" )
60+ assert my_obj != MyObjectType (prop = "b" )
61+
62+
63+ # complex instances of the same class
64+ # class contains another class in a field
65+ class ParentObjectType (ObjectType ):
66+ child = Field (MyObjectType )
67+
68+ my_obj = ParentObjectType (child = MyObjectType (prop = "a" ))
69+ assert my_obj == ParentObjectType (child = MyObjectType (prop = "a" ))
70+ assert my_obj != ParentObjectType (child = MyObjectType (prop = "b" ))
71+
3872def test_generate_objecttype ():
3973 class MyObjectType (ObjectType ):
4074 """Documentation"""
You can’t perform that action at this time.
0 commit comments