From 7fc916361ed9da5730ed1bb277d9bfadb9a78d33 Mon Sep 17 00:00:00 2001 From: Lee Garrett Date: Fri, 18 Apr 2025 02:56:01 +0200 Subject: [PATCH] Fix test_range_templating on 32-bit architectures (#85007) * Fix test_range_templating on 32-bit architectures 32-bit archtectures like i386, armel, armhf will fail with the error ansible._internal._templating._errors.AnsibleTemplatePluginRuntimeError: The filter plugin 'ansible.builtin.random' failed: Python int too large to convert to C ssize_t So just pick sys.maxsize (2**31 - 1) so it works on 32 bit machines. --------- Co-authored-by: Lee Garrett Co-authored-by: Matt Clay (cherry picked from commit 5f6aef95ac670bd87162cf223e1665b8922d0efa) --- test/units/_internal/templating/test_lazy_containers.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/units/_internal/templating/test_lazy_containers.py b/test/units/_internal/templating/test_lazy_containers.py index 903ba600e0b..ccb6e387c5f 100644 --- a/test/units/_internal/templating/test_lazy_containers.py +++ b/test/units/_internal/templating/test_lazy_containers.py @@ -5,6 +5,7 @@ from __future__ import annotations import collections.abc as c import copy import re +import sys import typing as t import pytest @@ -463,11 +464,13 @@ def test_range_templating(): They are usually listified like other iterables when returned from a Jinja filter or method/function call, except when calling the Python `range()` global function directly, which allows the range object to be returned and used directly. """ - templar = TemplateEngine() + templar = TemplateEngine(variables=dict( + large_value=min(1000000000000, sys.maxsize - 1) # ensure we don't exceed ssize_t on 32-bit systems + )) # ensure that an insanely large range is not listified - assert templar.evaluate_conditional(TRUST.tag("range(1000000000000) | type_debug == 'range'")) - assert isinstance(templar.template(TRUST.tag("{{ range(1000000000000) | random }}")), int) + assert templar.evaluate_conditional(TRUST.tag("range(large_value) | type_debug == 'range'")) + assert isinstance(templar.template(TRUST.tag("{{ range(large_value) | random }}")), int) assert templar.template(TRUST.tag("{{ range(3) | reverse }}")) == [2, 1, 0]