class Pins:
- def __init__(self, names, *, dir="io", conn=None):
+ def __init__(self, names, *, dir="io", conn=None, assert_width=None):
if not isinstance(names, str):
raise TypeError("Names must be a whitespace-separated string, not {!r}"
.format(names))
raise TypeError("Direction must be one of \"i\", \"o\", \"oe\", or \"io\", not {!r}"
.format(dir))
+ if assert_width is not None and len(names) != assert_width:
+ raise AssertionError("{} names are specified ({}), but {} names are expected"
+ .format(len(names), " ".join(names), assert_width))
+
self.names = names
self.dir = dir
self.invert = False
class DiffPairs:
- def __init__(self, p, n, *, dir="io", conn=None):
- self.p = Pins(p, dir=dir, conn=conn)
- self.n = Pins(n, dir=dir, conn=conn)
+ def __init__(self, p, n, *, dir="io", conn=None, assert_width=None):
+ self.p = Pins(p, dir=dir, conn=conn, assert_width=assert_width)
+ self.n = Pins(n, dir=dir, conn=conn, assert_width=assert_width)
if len(self.p.names) != len(self.n.names):
raise TypeError("Positive and negative pins must have the same width, but {!r} "
"connector pin pmod_0:1"):
p.map_names(mapping, p)
+ def test_wrong_assert_width(self):
+ with self.assertRaises(AssertionError,
+ msg="3 names are specified (0 1 2), but 4 names are expected"):
+ Pins("0 1 2", assert_width=4)
+
class DiffPairsTestCase(FHDLTestCase):
def test_basic(self):
"and (pins io B0 B1) do not"):
dp = DiffPairs("A0", "B0 B1")
+ def test_wrong_assert_width(self):
+ with self.assertRaises(AssertionError,
+ msg="3 names are specified (0 1 2), but 4 names are expected"):
+ DiffPairs("0 1 2", "3 4 5", assert_width=4)
+
class AttrsTestCase(FHDLTestCase):
def test_basic(self):