Skip to content

Commit

Permalink
Fix OrderedDict representation in test
Browse files Browse the repository at this point in the history
Add pytest fixture to handle OrderedDict representation based on
Python version. Ensures compatibility with Python 3.12+ in
test_complex_object.
  • Loading branch information
andreztz committed Sep 4, 2024
1 parent b3e8f8c commit 794be31
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tests/unit/pypyr/steps/debug_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from unittest.mock import call, patch
import sys

import pytest

from pypyr.context import Context
import pypyr.steps.debug as debug
from pypyr.dsl import Jsonify, PyString, SicString
Expand Down Expand Up @@ -163,7 +165,16 @@ def get_obj_hex(obj):
return hex(id(obj))


def test_complex_object():
@pytest.fixture
def expected_ordered_dict():
if (3, 7) <= sys.version_info < (3, 12):
ordered_dict = "OrderedDict([('a', 1), ('b', 2)])"
else:
ordered_dict = "OrderedDict({'a': 1, 'b': 2})"
return ordered_dict


def test_complex_object(expected_ordered_dict):
"""Check different complex objects, like error, date, type..."""
py_str = PyString('py_arb')

Expand Down Expand Up @@ -207,7 +218,7 @@ def arb_func():
" 'lambda': <function test_complex_object.<locals>.<lambda>"
f" at {get_obj_hex(arb_lambda)}>,\n"
" 'list': ['arb1', 'arb2', ['arb3']],\n"
" 'ordered_dict': OrderedDict([('a', 1), ('b', 2)]),\n"
f" 'ordered_dict': {expected_ordered_dict},\n"
" 'py': PyString('py_arb'),\n"
" 'sic': SicString('sic_arb'),\n"
" 'tuple': ('arb1', 'arb2'),\n"
Expand Down

0 comments on commit 794be31

Please sign in to comment.