4 from contextlib
import contextmanager
6 from ..hdl
.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 assertRaisesRegex(self
, exception
, regex
=None):
30 with
super().assertRaises(exception
) as cm
:
33 # unittest.assertRaisesRegex also seems broken...
34 self
.assertRegex(str(cm
.exception
), regex
)
37 def assertWarns(self
, category
, msg
=None):
38 with warnings
.catch_warnings(record
=True) as warns
:
40 self
.assertEqual(len(warns
), 1)
41 self
.assertEqual(warns
[0].category
, category
)
43 self
.assertEqual(str(warns
[0].message
), msg
)