From 8bd7a6c170b68e245f3423e36ce31a3d7e041ceb Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 23 Sep 2019 11:03:50 +0000 Subject: [PATCH] lib.fifo: change FIFOInterface() diagnostics to follow Memory(). --- nmigen/lib/fifo.py | 9 ++++++--- nmigen/test/test_lib_fifo.py | 10 +++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/nmigen/lib/fifo.py b/nmigen/lib/fifo.py index f157d65..c96288a 100644 --- a/nmigen/lib/fifo.py +++ b/nmigen/lib/fifo.py @@ -61,9 +61,12 @@ class FIFOInterface: r_attributes="") def __init__(self, width, depth, *, fwft): - if depth <= 0: - raise ValueError("FIFO depth must be positive, not {}".format(depth)) - + if not isinstance(width, int) or width < 0: + raise TypeError("FIFO width must be a non-negative integer, not '{!r}'" + .format(width)) + if not isinstance(depth, int) or depth <= 0: + raise TypeError("FIFO depth must be a positive integer, not '{!r}'" + .format(depth)) self.width = width self.depth = depth self.fwft = fwft diff --git a/nmigen/test/test_lib_fifo.py b/nmigen/test/test_lib_fifo.py index 527a152..835d7b7 100644 --- a/nmigen/test/test_lib_fifo.py +++ b/nmigen/test/test_lib_fifo.py @@ -7,11 +7,11 @@ from ..lib.fifo import * class FIFOTestCase(FHDLTestCase): def test_depth_wrong(self): - with self.assertRaises(ValueError, - msg="FIFO depth must be positive, not -1"): - FIFOInterface(width=8, depth=-1, fwft=True) - with self.assertRaises(ValueError, - msg="FIFO depth must be positive, not 0"): + with self.assertRaises(TypeError, + msg="FIFO width must be a non-negative integer, not '-1'"): + FIFOInterface(width=-1, depth=8, fwft=True) + with self.assertRaises(TypeError, + msg="FIFO depth must be a positive integer, not '0'"): FIFOInterface(width=8, depth=0, fwft=True) def test_async_depth(self): -- 2.30.2