4 from contextlib
import contextmanager
6 from ..fhdl
.ast
import *
9 __all__
= ["FHDLTestCase"]
12 class FHDLTestCase(unittest
.TestCase
):
13 def assertRepr(self
, obj
, repr_str
):
14 obj
= Statement
.wrap(obj
)
15 repr_str
= re
.sub(r
"\s+", " ", repr_str
)
16 repr_str
= re
.sub(r
"\( (?=\()", "(", repr_str
)
17 repr_str
= re
.sub(r
"\) (?=\))", ")", repr_str
)
18 self
.assertEqual(repr(obj
), repr_str
.strip())
21 def assertRaises(self
, exception
, msg
=None):
22 with
super().assertRaises(exception
) as cm
:
25 # WTF? unittest.assertRaises is completely broken.
26 self
.assertEqual(str(cm
.exception
), msg
)
29 def assertWarns(self
, category
, msg
=None):
30 with warnings
.catch_warnings(record
=True) as warns
:
32 self
.assertEqual(len(warns
), 1)
33 self
.assertEqual(warns
[0].category
, category
)
35 self
.assertEqual(str(warns
[0].message
), msg
)