compat: suppress deprecation warnings that are internal or during test.
authorwhitequark <whitequark@whitequark.org>
Sat, 26 Jan 2019 15:43:00 +0000 (15:43 +0000)
committerwhitequark <whitequark@whitequark.org>
Sat, 26 Jan 2019 15:43:00 +0000 (15:43 +0000)
nmigen/compat/genlib/fsm.py
nmigen/test/compat/support.py
nmigen/tools.py

index 509c9efeb1ed662023916e82c1064daec804f724..844d323456fdebe41890fc7e28b79533f39150e2 100644 (file)
@@ -1,6 +1,6 @@
-import warnings
 from collections import OrderedDict
 
+from ...tools import _ignore_deprecated
 from ...hdl.xfrm import ValueTransformer, StatementTransformer
 from ...hdl.ast import *
 from ..fhdl.module import CompatModule, CompatFinalizeError
@@ -153,6 +153,7 @@ class FSM(CompatModule):
         self.sync += signal.eq(self.before_leaving(state))
         return signal
 
+    @_ignore_deprecated
     def do_finalize(self):
         nstates = len(self.actions)
         self.encoding = dict((s, n) for n, s in enumerate(self.actions.keys()))
@@ -178,11 +179,10 @@ class FSM(CompatModule):
 
     def _finalize_sync(self, ls):
         cases = dict((self.encoding[k], ls.on_statement(v)) for k, v in self.actions.items() if v)
-        with warnings.catch_warnings():
-            self.comb += [
-                self.next_state.eq(self.state),
-                Case(self.state, cases).makedefault(self.encoding[self.reset_state])
-            ]
-            self.sync += self.state.eq(self.next_state)
-            for register, next_value_ce, next_value in ls.registers:
-                self.sync += If(next_value_ce, register.eq(next_value))
+        self.comb += [
+            self.next_state.eq(self.state),
+            Case(self.state, cases).makedefault(self.encoding[self.reset_state])
+        ]
+        self.sync += self.state.eq(self.next_state)
+        for register, next_value_ce, next_value in ls.registers:
+            self.sync += If(next_value_ce, register.eq(next_value))
index 3de32763314b9c3dbb2add873338cfd6418d3b71..1dd5601129292e420a7a8ab04ddfc68af366ec24 100644 (file)
@@ -1,10 +1,12 @@
+from ...tools import _ignore_deprecated
 from ...compat import *
 from ...compat.fhdl import verilog
 
 
 class SimCase:
     def setUp(self, *args, **kwargs):
-        self.tb = self.TestBench(*args, **kwargs)
+        with _ignore_deprecated():
+            self.tb = self.TestBench(*args, **kwargs)
 
     def test_to_verilog(self):
         verilog.convert(self.tb)
index 0cdbbce577b72d779a3d28a4075dca26d487c141..25b6893ab1a4b85402bf25bc96ebdc66e58b4241 100644 (file)
@@ -1,6 +1,8 @@
-from collections.abc import Iterable
+import contextlib
 import functools
 import warnings
+from collections.abc import Iterable
+from contextlib import contextmanager
 
 
 __all__ = ["flatten", "union", "log2_int", "bits_for", "deprecated"]
@@ -54,6 +56,23 @@ def deprecated(message, stacklevel=2):
     return decorator
 
 
+def _ignore_deprecated(f=None):
+    if f is None:
+        @contextlib.contextmanager
+        def context_like():
+            with warnings.catch_warnings():
+                warnings.filterwarnings(action="ignore", category=DeprecationWarning)
+                yield
+        return context_like()
+    else:
+        @functools.wraps(f)
+        def decorator_like(*args, **kwargs):
+            with warnings.catch_warnings():
+                warnings.filterwarnings(action="ignore", category=DeprecationWarning)
+                f(*args, **kwargs)
+        return decorator_like
+
+
 def extend(cls):
     def decorator(f):
         if isinstance(f, property):