File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,21 @@ def __str__(self) -> str:
76
76
77
77
return value or ''
78
78
79
+ def __eq__ (self , other ):
80
+ """Compares :paramref:self to :paramref:other for
81
+ equality.
82
+
83
+ Returns:
84
+ True when :paramref:self is equal to :paramref:other.
85
+ And False when they are not.
86
+ """
87
+
88
+ for lang_code , _ in settings .LANGUAGES :
89
+ if self .get (lang_code ) != other .get (lang_code ):
90
+ return False
91
+
92
+ return True
93
+
79
94
def __repr__ (self ): # pragma: no cover
80
95
"""Gets a textual representation of this object."""
81
96
Original file line number Diff line number Diff line change @@ -100,6 +100,19 @@ def test_str():
100
100
translation .activate (language )
101
101
assert str (localized_value ) == value
102
102
103
+ @staticmethod
104
+ def test_eq ():
105
+ """Tests whether the __eq__ operator
106
+ of :see:LocalizedValue works properly."""
107
+
108
+ a = LocalizedValue ({'en' : 'a' , 'ar' : 'b' })
109
+ b = LocalizedValue ({'en' : 'a' , 'ar' : 'b' })
110
+
111
+ assert a == b
112
+
113
+ b .en = 'b'
114
+ assert a != b
115
+
103
116
@staticmethod
104
117
def test_str_fallback ():
105
118
"""Tests whether the :see:LocalizedValue
You can’t perform that action at this time.
0 commit comments