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