lib.fifo: change FIFOInterface() diagnostics to follow Memory().
authorwhitequark <cz@m-labs.hk>
Mon, 23 Sep 2019 11:03:50 +0000 (11:03 +0000)
committerwhitequark <cz@m-labs.hk>
Mon, 23 Sep 2019 11:03:50 +0000 (11:03 +0000)
nmigen/lib/fifo.py
nmigen/test/test_lib_fifo.py

index f157d655ef71d402b5b9e9351169b9390bb110ac..c96288aad865aa8cab43091685211513d0679d62 100644 (file)
@@ -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
index 527a1527f56753853ad9673977774a721b7c6587..835d7b73c1e8e0a51c2160d7a8f014c1498a4701 100644 (file)
@@ -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):