@@ -744,7 +744,7 @@ def test_bug_837_array_layout_getattr(self):
744
744
r"^View with an array layout does not have fields$" ):
745
745
Signal (data .ArrayLayout (unsigned (1 ), 1 ), init = [0 ]).init
746
746
747
- def test_eq (self ):
747
+ def test_compare (self ):
748
748
s1 = Signal (data .StructLayout ({"a" : unsigned (2 )}))
749
749
s2 = Signal (data .StructLayout ({"a" : unsigned (2 )}))
750
750
s3 = Signal (data .StructLayout ({"a" : unsigned (1 ), "b" : unsigned (1 )}))
@@ -973,11 +973,12 @@ def test_bug_837_array_layout_getattr(self):
973
973
r"^Constant with an array layout does not have fields$" ):
974
974
data .Const (data .ArrayLayout (unsigned (1 ), 1 ), 0 ).init
975
975
976
- def test_eq (self ):
976
+ def test_compare (self ):
977
977
c1 = data .Const (data .StructLayout ({"a" : unsigned (2 )}), 1 )
978
978
c2 = data .Const (data .StructLayout ({"a" : unsigned (2 )}), 1 )
979
979
c3 = data .Const (data .StructLayout ({"a" : unsigned (2 )}), 2 )
980
980
c4 = data .Const (data .StructLayout ({"a" : unsigned (1 ), "b" : unsigned (1 )}), 2 )
981
+ c5 = data .Const (data .ArrayLayout (2 , 4 ), 0b11100100 )
981
982
s1 = Signal (data .StructLayout ({"a" : unsigned (2 )}))
982
983
self .assertTrue (c1 == c2 )
983
984
self .assertFalse (c1 != c2 )
@@ -987,13 +988,23 @@ def test_eq(self):
987
988
self .assertRepr (c1 != s1 , "(!= (const 2'd1) (sig s1))" )
988
989
self .assertRepr (s1 == c1 , "(== (sig s1) (const 2'd1))" )
989
990
self .assertRepr (s1 != c1 , "(!= (sig s1) (const 2'd1))" )
991
+ self .assertTrue (c1 == {"a" : 1 })
992
+ self .assertFalse (c1 == {"a" : 2 })
993
+ self .assertFalse (c1 != {"a" : 1 })
994
+ self .assertTrue (c1 != {"a" : 2 })
995
+ self .assertTrue (c5 == [0 ,1 ,2 ,3 ])
996
+ self .assertFalse (c5 == [0 ,1 ,3 ,3 ])
997
+ self .assertFalse (c5 != [0 ,1 ,2 ,3 ])
998
+ self .assertTrue (c5 != [0 ,1 ,3 ,3 ])
990
999
with self .assertRaisesRegex (TypeError ,
991
- r"^Constant with layout .* can only be compared to another view or constant with "
992
- r"the same layout, not .*$" ):
1000
+ r"^Constant with layout .* can only be compared to another view, a constant "
1001
+ r"with the same layout, or a dictionary or a list that can be converted to "
1002
+ r"a constant with the same layout, not .*$" ):
993
1003
c1 == c4
994
1004
with self .assertRaisesRegex (TypeError ,
995
- r"^Constant with layout .* can only be compared to another view or constant with "
996
- r"the same layout, not .*$" ):
1005
+ r"^Constant with layout .* can only be compared to another view, a constant "
1006
+ r"with the same layout, or a dictionary or a list that can be converted to "
1007
+ r"a constant with the same layout, not .*$" ):
997
1008
c1 != c4
998
1009
with self .assertRaisesRegex (TypeError ,
999
1010
r"^View with layout .* can only be compared to another view or constant with "
@@ -1004,21 +1015,45 @@ def test_eq(self):
1004
1015
r"the same layout, not .*$" ):
1005
1016
s1 != c4
1006
1017
with self .assertRaisesRegex (TypeError ,
1007
- r"^Constant with layout .* can only be compared to another view or constant with "
1008
- r"the same layout, not .*$" ):
1018
+ r"^Constant with layout .* can only be compared to another view, a constant "
1019
+ r"with the same layout, or a dictionary or a list that can be converted to "
1020
+ r"a constant with the same layout, not .*$" ):
1009
1021
c4 == s1
1010
1022
with self .assertRaisesRegex (TypeError ,
1011
- r"^Constant with layout .* can only be compared to another view or constant with "
1012
- r"the same layout, not .*$" ):
1023
+ r"^Constant with layout .* can only be compared to another view, a constant "
1024
+ r"with the same layout, or a dictionary or a list that can be converted to "
1025
+ r"a constant with the same layout, not .*$" ):
1013
1026
c4 != s1
1014
1027
with self .assertRaisesRegex (TypeError ,
1015
- r"^Constant with layout .* can only be compared to another view or constant with "
1016
- r"the same layout, not .*$" ):
1028
+ r"^Constant with layout .* can only be compared to another view, a constant "
1029
+ r"with the same layout, or a dictionary or a list that can be converted to "
1030
+ r"a constant with the same layout, not .*$" ):
1017
1031
c1 == Const (0 , 2 )
1018
1032
with self .assertRaisesRegex (TypeError ,
1019
- r"^Constant with layout .* can only be compared to another view or constant with "
1020
- r"the same layout, not .*$" ):
1033
+ r"^Constant with layout .* can only be compared to another view, a constant "
1034
+ r"with the same layout, or a dictionary or a list that can be converted to "
1035
+ r"a constant with the same layout, not .*$" ):
1021
1036
c1 != Const (0 , 2 )
1037
+ with self .assertRaisesRegex (TypeError ,
1038
+ r"^Constant with layout .* can only be compared to another view, a constant "
1039
+ r"with the same layout, or a dictionary or a list that can be converted to "
1040
+ r"a constant with the same layout, not .*$" ):
1041
+ c1 == {"b" : 1 }
1042
+ with self .assertRaisesRegex (TypeError ,
1043
+ r"^Constant with layout .* can only be compared to another view, a constant "
1044
+ r"with the same layout, or a dictionary or a list that can be converted to "
1045
+ r"a constant with the same layout, not .*$" ):
1046
+ c1 != {"b" : 1 }
1047
+ with self .assertRaisesRegex (TypeError ,
1048
+ r"^Constant with layout .* can only be compared to another view, a constant "
1049
+ r"with the same layout, or a dictionary or a list that can be converted to "
1050
+ r"a constant with the same layout, not .*$" ):
1051
+ c5 == [0 ,1 ,2 ,3 ,4 ]
1052
+ with self .assertRaisesRegex (TypeError ,
1053
+ r"^Constant with layout .* can only be compared to another view, a constant "
1054
+ r"with the same layout, or a dictionary or a list that can be converted to "
1055
+ r"a constant with the same layout, not .*$" ):
1056
+ c5 != [0 ,1 ,2 ,3 ,4 ]
1022
1057
1023
1058
def test_operator (self ):
1024
1059
s1 = data .Const (data .StructLayout ({"a" : unsigned (2 )}), 2 )
0 commit comments