@@ -365,11 +365,6 @@ def test_cast_wrong_recur(self):
365365 r"^Shape-castable object <.+> casts to itself$" ):
366366 Layout .cast (sc )
367367
368- def test_of_wrong (self ):
369- with self .assertRaisesRegex (TypeError ,
370- r"^Object <.+> is not a data view$" ):
371- Layout .of (object ())
372-
373368 def test_eq_wrong_recur (self ):
374369 sc = MockShapeCastable (None )
375370 sc .shape = sc
@@ -379,7 +374,7 @@ def test_call(self):
379374 sl = StructLayout ({"f" : unsigned (1 )})
380375 s = Signal (1 )
381376 v = sl (s )
382- self .assertIs (Layout . of ( v ), sl )
377+ self .assertIs (v . shape ( ), sl )
383378 self .assertIs (v .as_value (), s )
384379
385380 def test_const (self ):
@@ -621,6 +616,11 @@ def test_attr_wrong_reserved(self):
621616 r"and may only be accessed by indexing$" ):
622617 Signal (StructLayout ({"_c" : signed (1 )}))._c
623618
619+ def test_signal_like (self ):
620+ s1 = Signal (StructLayout ({"a" : unsigned (1 )}))
621+ s2 = Signal .like (s1 )
622+ self .assertEqual (s2 .shape (), StructLayout ({"a" : unsigned (1 )}))
623+
624624 def test_bug_837_array_layout_getitem_str (self ):
625625 with self .assertRaisesRegex (TypeError ,
626626 r"^Views with array layout may only be indexed with an integer or a value, "
@@ -646,7 +646,7 @@ class S(Struct):
646646 }))
647647
648648 v = Signal (S )
649- self .assertEqual (Layout . of ( v ), S )
649+ self .assertEqual (v . shape ( ), S )
650650 self .assertEqual (Value .cast (v ).shape (), Shape .cast (S ))
651651 self .assertEqual (Value .cast (v ).name , "v" )
652652 self .assertRepr (v .a , "(slice (sig v) 0:1)" )
@@ -666,11 +666,11 @@ class S(Struct):
666666 self .assertEqual (Shape .cast (S ), unsigned (9 ))
667667
668668 v = Signal (S )
669- self .assertIs (Layout . of ( v ), S )
669+ self .assertIs (v . shape ( ), S )
670670 self .assertIsInstance (v , S )
671- self .assertIs (Layout . of ( v .b ), R )
671+ self .assertIs (v .b . shape ( ), R )
672672 self .assertIsInstance (v .b , R )
673- self .assertIs (Layout . of ( v .b .q ), Q )
673+ self .assertIs (v .b .q . shape ( ), Q )
674674 self .assertIsInstance (v .b .q , View )
675675 self .assertRepr (v .b .p , "(slice (slice (sig v) 1:9) 0:4)" )
676676 self .assertRepr (v .b .q .as_value (), "(slice (slice (sig v) 1:9) 4:8)" )
@@ -747,10 +747,17 @@ class S(Struct):
747747 b : int
748748 c : str = "x"
749749
750- self .assertEqual (Layout .of ( Signal ( S ) ), StructLayout ({"a" : unsigned (1 )}))
750+ self .assertEqual (Layout .cast ( S ), StructLayout ({"a" : unsigned (1 )}))
751751 self .assertEqual (S .__annotations__ , {"b" : int , "c" : str })
752752 self .assertEqual (S .c , "x" )
753753
754+ def test_signal_like (self ):
755+ class S (Struct ):
756+ a : 1
757+ s1 = Signal (S )
758+ s2 = Signal .like (s1 )
759+ self .assertEqual (s2 .shape (), S )
760+
754761
755762class UnionTestCase (FHDLTestCase ):
756763 def test_construct (self ):
@@ -765,7 +772,7 @@ class U(Union):
765772 }))
766773
767774 v = Signal (U )
768- self .assertEqual (Layout . of ( v ), U )
775+ self .assertEqual (v . shape ( ), U )
769776 self .assertEqual (Value .cast (v ).shape (), Shape .cast (U ))
770777 self .assertRepr (v .a , "(slice (sig v) 0:1)" )
771778 self .assertRepr (v .b , "(s (slice (sig v) 0:3))" )
@@ -887,7 +894,7 @@ class Kind(Enum):
887894
888895 view1 = Signal (layout1 )
889896 self .assertIsInstance (view1 , View )
890- self .assertEqual (Layout . of ( view1 ), layout1 )
897+ self .assertEqual (view1 . shape ( ), layout1 )
891898 self .assertEqual (view1 .as_value ().shape (), unsigned (3 ))
892899
893900 m1 = Module ()
@@ -933,4 +940,4 @@ def check_m2():
933940
934941 self .assertEqual (layout1 , Layout .cast (SomeVariant ))
935942
936- self .assertIs (SomeVariant , Layout . of ( view2 ))
943+ self .assertIs (SomeVariant , view2 . shape ( ))
0 commit comments