File tree 2 files changed +39
-0
lines changed
2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,11 @@ class Query(ObjectType):
118
118
**kwargs (Dict[str: Any]): Keyword arguments to use for Field values of value object
119
119
"""
120
120
121
+ def __eq__ (self , other ):
122
+ if isinstance (other , self .__class__ ):
123
+ return self .__dict__ == other .__dict__
124
+ return False
125
+
121
126
@classmethod
122
127
def __init_subclass_with_meta__ (
123
128
cls ,
Original file line number Diff line number Diff line change @@ -35,6 +35,40 @@ def get_type(self):
35
35
return MyType
36
36
37
37
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
+
38
72
def test_generate_objecttype ():
39
73
class MyObjectType (ObjectType ):
40
74
"""Documentation"""
You can’t perform that action at this time.
0 commit comments