lib.io: Add missing __repr__ to signature type.

This commit is contained in:
Wanda 2024-02-28 10:06:19 +01:00 committed by Catherine
parent 8af9fe2606
commit 1dd2e6150c
2 changed files with 16 additions and 3 deletions

View file

@ -114,6 +114,10 @@ class Pin(wiring.PureInterface):
self.dir == other.dir and
self.xdr == other.xdr)
def __repr__(self):
xdr = f", xdr={self.xdr}" if self.xdr != 0 else ""
return f"Pin.Signature({self.width}, dir={self.dir!r}{xdr})"
def create(self, *, path=None, src_loc_at=0):
return Pin(self.width, self.dir, xdr=self.xdr, path=path, src_loc_at=1 + src_loc_at)
@ -128,11 +132,11 @@ class Pin(wiring.PureInterface):
@property
def width(self):
return self.signature.width
@property
def dir(self):
return self.signature.dir
@property
def xdr(self):
return self.signature.xdr

View file

@ -199,6 +199,16 @@ class PinSignatureDDRTestCase(PinSignatureTestCase):
})
class PinSignatureReprCase(FHDLTestCase):
def test_repr(self):
sig_0 = Pin.Signature(1, dir="i")
self.assertRepr(sig_0, "Pin.Signature(1, dir='i')")
sig_0 = Pin.Signature(2, dir="o", xdr=1)
self.assertRepr(sig_0, "Pin.Signature(2, dir='o', xdr=1)")
sig_0 = Pin.Signature(3, dir="io", xdr=2)
self.assertRepr(sig_0, "Pin.Signature(3, dir='io', xdr=2)")
class PinTestCase(FHDLTestCase):
def test_attributes(self):
pin = Pin(2, dir="io", xdr=2)
@ -208,4 +218,3 @@ class PinTestCase(FHDLTestCase):
self.assertEqual(pin.signature.width, 2)
self.assertEqual(pin.signature.dir, "io")
self.assertEqual(pin.signature.xdr, 2)