From f73d23d2980dfe622720b6c7a6ebcd95e8c7e14a Mon Sep 17 00:00:00 2001 From: Berg Lucas <55436804+BergLucas@users.noreply.github.com> Date: Wed, 22 May 2024 09:16:41 +0200 Subject: [PATCH] Fix assertion generation for float subclasses --- src/pynguin/assertion/assertion_to_ast.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pynguin/assertion/assertion_to_ast.py b/src/pynguin/assertion/assertion_to_ast.py index 69d83ce6..4c783aa0 100644 --- a/src/pynguin/assertion/assertion_to_ast.py +++ b/src/pynguin/assertion/assertion_to_ast.py @@ -99,12 +99,14 @@ def visit_float_assertion(self, assertion: ass.FloatAssertion) -> None: Args: assertion: the assertion that is visited. - """ + # Convert the assertion value to a float primitive in case it is a subclass + # of it because Constant nodes in the AST only works with primitives + value = float(assertion.value) left = au.create_full_name( self._variable_names, self._module_aliases, assertion.source, load=True ) - comp = self._construct_float_comparator(au.create_ast_constant(assertion.value)) + comp = self._construct_float_comparator(au.create_ast_constant(value)) self._assertion_nodes.append( au.create_ast_assert(au.create_ast_compare(left, ast.Eq(), comp)) )