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 @@ -128,6 +128,11 @@ def __init_subclass_with_meta__(
128
128
129
129
is_type_of = None
130
130
131
+ def __eq__ (self , other ):
132
+ if isinstance (other , self .__class__ ):
133
+ return self .__dict__ == other .__dict__
134
+ return False
135
+
131
136
def __init__ (self , * args , ** kwargs ):
132
137
# ObjectType acting as container
133
138
args_len = len (args )
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