hdl.ir: raise a more descriptive error on non-elaboratable object.
authorwhitequark <cz@m-labs.hk>
Thu, 14 Feb 2019 20:52:42 +0000 (20:52 +0000)
committerwhitequark <cz@m-labs.hk>
Thu, 14 Feb 2019 20:52:42 +0000 (20:52 +0000)
nmigen/hdl/ir.py
nmigen/test/test_hdl_ir.py

index ac608e21400d3258b3ce41167da4584743bd185a..d799648b9fbad7f0ff3b5adaf44eb1c2dd11bb09 100644 (file)
@@ -18,9 +18,13 @@ class Fragment:
     def get(obj, platform):
         if isinstance(obj, Fragment):
             return obj
-        if not hasattr(obj, "elaborate"): # :deprecated:
-            return Fragment.get(obj.get_fragment(platform), platform)
-        return Fragment.get(obj.elaborate(platform), platform)
+        if hasattr(obj, "elaborate"):
+            frag = obj.elaborate(platform)
+        elif hasattr(obj, "get_fragment"): # :deprecated:
+            frag = obj.get_fragment(platform)
+        else:
+            raise AttributeError("Object '{!r}' cannot be elaborated".format(obj))
+        return Fragment.get(frag, platform)
 
     def __init__(self):
         self.ports = SignalDict()
index e6158bbb9c2bc4ce42ec572738b1bbf4eb8d2f46..4c59917520ddd13cb9d2c186111d9fe8a36da6e1 100644 (file)
@@ -7,6 +7,13 @@ from ..hdl.mem import *
 from .tools import *
 
 
+class FragmentGetTestCase(FHDLTestCase):
+    def test_get_wrong(self):
+        with self.assertRaises(AttributeError,
+                msg="Object 'None' cannot be elaborated"):
+            Fragment.get(None, platform=None)
+
+
 class FragmentGeneratedTestCase(FHDLTestCase):
     def test_find_subfragment(self):
         f1 = Fragment()