From 4b1c41d4427d815d7e86666157255a648457c725 Mon Sep 17 00:00:00 2001 From: Wanda Date: Wed, 28 Feb 2024 10:06:19 +0100 Subject: [PATCH] lib.io: Add missing __repr__ to signature type. --- amaranth/lib/io.py | 8 ++++++-- tests/test_lib_io.py | 11 ++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/amaranth/lib/io.py b/amaranth/lib/io.py index 2a179ec9c..09058d29c 100644 --- a/amaranth/lib/io.py +++ b/amaranth/lib/io.py @@ -114,6 +114,10 @@ def __eq__(self, other): 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 @@ def __init__(self, width, dir, *, xdr=0, name=None, path=None, src_loc_at=0): @property def width(self): return self.signature.width - + @property def dir(self): return self.signature.dir - + @property def xdr(self): return self.signature.xdr diff --git a/tests/test_lib_io.py b/tests/test_lib_io.py index ae41c0711..1c82b1f68 100644 --- a/tests/test_lib_io.py +++ b/tests/test_lib_io.py @@ -199,6 +199,16 @@ def test_signature_io(self): }) +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 @@ def test_attributes(self): self.assertEqual(pin.signature.width, 2) self.assertEqual(pin.signature.dir, "io") self.assertEqual(pin.signature.xdr, 2) -