test: add support for Decimal to assert_approx

This commit is contained in:
Karl-Johan Alm committed 2022-08-02 10:11:12 +09:00
1 parent ce3b75690d
commit 701a64f548
1 file changed
+4
+4
View File
@@ -29,6 +29,10 @@ logger = logging.getLogger("TestFramework.utils")
def assert_approx(v, vexp, vspan=0.00001):
"""Assert that `v` is within `vspan` of `vexp`"""
if isinstance(v, Decimal) or isinstance(vexp, Decimal):
v=Decimal(v)
vexp=Decimal(vexp)
vspan=Decimal(vspan)
if v < vexp - vspan:
raise AssertionError("%s < [%s..%s]" % (str(v), str(vexp - vspan), str(vexp + vspan)))
if v > vexp + vspan: