diff --git a/lib/ansible/_internal/_json/_profiles/_cache_persistence.py b/lib/ansible/_internal/_json/_profiles/_cache_persistence.py index a6c16e1a794..6b76cb56d59 100644 --- a/lib/ansible/_internal/_json/_profiles/_cache_persistence.py +++ b/lib/ansible/_internal/_json/_profiles/_cache_persistence.py @@ -46,6 +46,8 @@ class _Profile(_profiles._JSONSerializationProfile): _datetime.datetime: _datatag.AnsibleSerializableDateTime, } + cls.handle_key = cls._handle_key_str_fallback # legacy stdlib-compatible key behavior + class Encoder(_profiles.AnsibleProfileJSONEncoder): _profile = _Profile diff --git a/lib/ansible/_internal/_json/_profiles/_legacy.py b/lib/ansible/_internal/_json/_profiles/_legacy.py index 95f23c103b2..d9f26302d90 100644 --- a/lib/ansible/_internal/_json/_profiles/_legacy.py +++ b/lib/ansible/_internal/_json/_profiles/_legacy.py @@ -152,6 +152,8 @@ class _Profile(_profiles._JSONSerializationProfile["Encoder", "Decoder"]): '__ansible_vault': cls.deserialize_vault, } + cls.handle_key = cls._handle_key_str_fallback # type: ignore[method-assign] # legacy stdlib-compatible key behavior + @classmethod def pre_serialize(cls, encoder: Encoder, o: _t.Any) -> _t.Any: # DTFIX7: these conversion args probably aren't needed @@ -165,16 +167,6 @@ class _Profile(_profiles._JSONSerializationProfile["Encoder", "Decoder"]): return avv.visit(o) - @classmethod - def handle_key(cls, k: _t.Any) -> _t.Any: - if isinstance(k, str): - return k - - # DTFIX3: decide if this is a deprecation warning, error, or what? - # Non-string variable names have been disallowed by set_fact and other things since at least 2021. - # DTFIX5: document why this behavior is here, also verify the legacy tagless use case doesn't need this same behavior - return str(k) - class Encoder(_profiles.AnsibleProfileJSONEncoder): _profile = _Profile diff --git a/lib/ansible/module_utils/_internal/_json/_profiles/__init__.py b/lib/ansible/module_utils/_internal/_json/_profiles/__init__.py index e28c83739b0..73fb1f5f47e 100644 --- a/lib/ansible/module_utils/_internal/_json/_profiles/__init__.py +++ b/lib/ansible/module_utils/_internal/_json/_profiles/__init__.py @@ -204,6 +204,7 @@ class _JSONSerializationProfile(t.Generic[_T_encoder, _T_decoder]): @classmethod def handle_key(cls, k: t.Any) -> t.Any: + """Validation/conversion hook before a dict key is serialized. The default implementation only accepts str-typed keys.""" # NOTE: Since JSON requires string keys, there is no support for preserving tags on dictionary keys during serialization. if not isinstance(k, str): # DTFIX-FUTURE: optimize this to use all known str-derived types in type map / allowed types @@ -211,6 +212,19 @@ class _JSONSerializationProfile(t.Generic[_T_encoder, _T_decoder]): return k + @classmethod + def _handle_key_str_fallback(cls, k: t.Any) -> t.Any: + """Legacy implementations should use this key handler for backward compatibility with stdlib JSON key conversion quirks.""" + # DTFIX-FUTURE: optimized exact-type table lookup first + + if isinstance(k, str): + return k + + if k is None or isinstance(k, (int, float)): + return json.dumps(k) + + raise TypeError(f'Key of type {type(k).__name__!r} is not JSON serializable by the {cls.profile_name!r} profile.') + @classmethod def default(cls, o: t.Any) -> t.Any: # Preserve the built-in JSON encoder support for subclasses of scalar types. diff --git a/lib/ansible/module_utils/_internal/_json/_profiles/_module_legacy_c2m.py b/lib/ansible/module_utils/_internal/_json/_profiles/_module_legacy_c2m.py index a1ec7699037..3247d27a81c 100644 --- a/lib/ansible/module_utils/_internal/_json/_profiles/_module_legacy_c2m.py +++ b/lib/ansible/module_utils/_internal/_json/_profiles/_module_legacy_c2m.py @@ -22,6 +22,8 @@ class _Profile(_profiles._JSONSerializationProfile["Encoder", "Decoder"]): } ) + cls.handle_key = cls._handle_key_str_fallback # type: ignore[method-assign] # legacy stdlib-compatible key behavior + class Encoder(_profiles.AnsibleProfileJSONEncoder): _profile = _Profile diff --git a/lib/ansible/module_utils/_internal/_json/_profiles/_module_legacy_m2c.py b/lib/ansible/module_utils/_internal/_json/_profiles/_module_legacy_m2c.py index 78ae0b54992..3030f72ad8e 100644 --- a/lib/ansible/module_utils/_internal/_json/_profiles/_module_legacy_m2c.py +++ b/lib/ansible/module_utils/_internal/_json/_profiles/_module_legacy_m2c.py @@ -26,6 +26,8 @@ class _Profile(_profiles._JSONSerializationProfile["Encoder", "Decoder"]): _datetime.datetime: cls.serialize_as_isoformat, # legacy _json_encode_fallback behavior *and* legacy parameters.py does this before serialization } + cls.handle_key = cls._handle_key_str_fallback # type: ignore[method-assign] # legacy stdlib-compatible key behavior + class Encoder(_profiles.AnsibleProfileJSONEncoder): _profile = _Profile diff --git a/lib/ansible/module_utils/_internal/_json/_profiles/_tagless.py b/lib/ansible/module_utils/_internal/_json/_profiles/_tagless.py index c741cf9aa97..29ff96c4173 100644 --- a/lib/ansible/module_utils/_internal/_json/_profiles/_tagless.py +++ b/lib/ansible/module_utils/_internal/_json/_profiles/_tagless.py @@ -41,6 +41,8 @@ class _Profile(_profiles._JSONSerializationProfile["Encoder", "Decoder"]): '__ansible_vault': _functools.partial(cls.unsupported_target_type_error, '__ansible_vault'), } + cls.handle_key = cls._handle_key_str_fallback # type: ignore[method-assign] # legacy stdlib-compatible key behavior + class Encoder(_profiles.AnsibleProfileJSONEncoder): _profile = _Profile diff --git a/test/units/utils/expected_serialization_profiles/cache_persistence.txt b/test/units/utils/expected_serialization_profiles/cache_persistence.txt index 592290c0428..b0de00a9609 100644 --- a/test/units/utils/expected_serialization_profiles/cache_persistence.txt +++ b/test/units/utils/expected_serialization_profiles/cache_persistence.txt @@ -49,4 +49,20 @@ _TestParameters(profile_name='cache_persistence', value={frozenset({1, 2}): 'thr _TestParameters(profile_name='cache_persistence', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'), TrustedAsTemplate(), Origin(path='/tmp/x', description='y', line_num=1, col_num=2), VaultedValue(ciphertext='x'), SourceWasEncrypted())): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'cache_persistence' profile."), round_trip=None, tags=()), _TestParameters(profile_name='cache_persistence', value={frozenset({1, 2}): 'three'}, lazy=True): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'cache_persistence' profile."), round_trip=None, tags=()), _TestParameters(profile_name='cache_persistence', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'), TrustedAsTemplate(), Origin(path='/tmp/x', description='y', line_num=1, col_num=2), VaultedValue(ciphertext='x'), SourceWasEncrypted()), lazy=True): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'cache_persistence' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='cache_persistence', value={1: 'two'}): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='cache_persistence', value={1: 'two'}, tags=(Deprecated(msg='x'), TrustedAsTemplate(), Origin(path='/tmp/x', description='y', line_num=1, col_num=2), VaultedValue(ciphertext='x'), SourceWasEncrypted())): _TestOutput(payload='{"value": {"1": "two"}, "tags": [{"msg": "x", "__ansible_type": "Deprecated"}, {"__ansible_type": "TrustedAsTemplate"}, {"path": "/tmp/x", "description": "y", "line_num": 1, "col_num": 2, "__ansible_type": "Origin"}, {"ciphertext": "x", "__ansible_type": "VaultedValue"}, {"__ansible_type": "SourceWasEncrypted"}], "__ansible_type": "_AnsibleTaggedDict"}', round_trip={'1': 'two'}, tags=(Deprecated(msg='x'), Origin(path='/tmp/x', description='y', line_num=1, col_num=2), SourceWasEncrypted(), TrustedAsTemplate(), VaultedValue(ciphertext='x'))), +_TestParameters(profile_name='cache_persistence', value={1: 'two'}, lazy=True): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='cache_persistence', value={1: 'two'}, tags=(Deprecated(msg='x'), TrustedAsTemplate(), Origin(path='/tmp/x', description='y', line_num=1, col_num=2), VaultedValue(ciphertext='x'), SourceWasEncrypted()), lazy=True): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='cache_persistence', value={1.1: 'two'}): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='cache_persistence', value={1.1: 'two'}, tags=(Deprecated(msg='x'), TrustedAsTemplate(), Origin(path='/tmp/x', description='y', line_num=1, col_num=2), VaultedValue(ciphertext='x'), SourceWasEncrypted())): _TestOutput(payload='{"value": {"1.1": "two"}, "tags": [{"msg": "x", "__ansible_type": "Deprecated"}, {"__ansible_type": "TrustedAsTemplate"}, {"path": "/tmp/x", "description": "y", "line_num": 1, "col_num": 2, "__ansible_type": "Origin"}, {"ciphertext": "x", "__ansible_type": "VaultedValue"}, {"__ansible_type": "SourceWasEncrypted"}], "__ansible_type": "_AnsibleTaggedDict"}', round_trip={'1.1': 'two'}, tags=(Deprecated(msg='x'), Origin(path='/tmp/x', description='y', line_num=1, col_num=2), SourceWasEncrypted(), TrustedAsTemplate(), VaultedValue(ciphertext='x'))), +_TestParameters(profile_name='cache_persistence', value={1.1: 'two'}, lazy=True): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='cache_persistence', value={1.1: 'two'}, tags=(Deprecated(msg='x'), TrustedAsTemplate(), Origin(path='/tmp/x', description='y', line_num=1, col_num=2), VaultedValue(ciphertext='x'), SourceWasEncrypted()), lazy=True): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='cache_persistence', value={True: 'two'}): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='cache_persistence', value={True: 'two'}, tags=(Deprecated(msg='x'), TrustedAsTemplate(), Origin(path='/tmp/x', description='y', line_num=1, col_num=2), VaultedValue(ciphertext='x'), SourceWasEncrypted())): _TestOutput(payload='{"value": {"true": "two"}, "tags": [{"msg": "x", "__ansible_type": "Deprecated"}, {"__ansible_type": "TrustedAsTemplate"}, {"path": "/tmp/x", "description": "y", "line_num": 1, "col_num": 2, "__ansible_type": "Origin"}, {"ciphertext": "x", "__ansible_type": "VaultedValue"}, {"__ansible_type": "SourceWasEncrypted"}], "__ansible_type": "_AnsibleTaggedDict"}', round_trip={'true': 'two'}, tags=(Deprecated(msg='x'), Origin(path='/tmp/x', description='y', line_num=1, col_num=2), SourceWasEncrypted(), TrustedAsTemplate(), VaultedValue(ciphertext='x'))), +_TestParameters(profile_name='cache_persistence', value={True: 'two'}, lazy=True): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='cache_persistence', value={True: 'two'}, tags=(Deprecated(msg='x'), TrustedAsTemplate(), Origin(path='/tmp/x', description='y', line_num=1, col_num=2), VaultedValue(ciphertext='x'), SourceWasEncrypted()), lazy=True): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='cache_persistence', value={None: 'two'}): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='cache_persistence', value={None: 'two'}, tags=(Deprecated(msg='x'), TrustedAsTemplate(), Origin(path='/tmp/x', description='y', line_num=1, col_num=2), VaultedValue(ciphertext='x'), SourceWasEncrypted())): _TestOutput(payload='{"value": {"null": "two"}, "tags": [{"msg": "x", "__ansible_type": "Deprecated"}, {"__ansible_type": "TrustedAsTemplate"}, {"path": "/tmp/x", "description": "y", "line_num": 1, "col_num": 2, "__ansible_type": "Origin"}, {"ciphertext": "x", "__ansible_type": "VaultedValue"}, {"__ansible_type": "SourceWasEncrypted"}], "__ansible_type": "_AnsibleTaggedDict"}', round_trip={'null': 'two'}, tags=(Deprecated(msg='x'), Origin(path='/tmp/x', description='y', line_num=1, col_num=2), SourceWasEncrypted(), TrustedAsTemplate(), VaultedValue(ciphertext='x'))), +_TestParameters(profile_name='cache_persistence', value={None: 'two'}, lazy=True): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='cache_persistence', value={None: 'two'}, tags=(Deprecated(msg='x'), TrustedAsTemplate(), Origin(path='/tmp/x', description='y', line_num=1, col_num=2), VaultedValue(ciphertext='x'), SourceWasEncrypted()), lazy=True): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), } diff --git a/test/units/utils/expected_serialization_profiles/fallback_to_str.txt b/test/units/utils/expected_serialization_profiles/fallback_to_str.txt index 5d702f797c1..b3104843c82 100644 --- a/test/units/utils/expected_serialization_profiles/fallback_to_str.txt +++ b/test/units/utils/expected_serialization_profiles/fallback_to_str.txt @@ -49,6 +49,22 @@ _TestParameters(profile_name='fallback_to_str', value={frozenset({1, 2}): 'three _TestParameters(profile_name='fallback_to_str', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"[1, 2]": "three"}', round_trip={'[1, 2]': 'three'}, tags=()), _TestParameters(profile_name='fallback_to_str', value={frozenset({1, 2}): 'three'}, lazy=True): _TestOutput(payload='{"[1, 2]": "three"}', round_trip={'[1, 2]': 'three'}, tags=()), _TestParameters(profile_name='fallback_to_str', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"[1, 2]": "three"}', round_trip={'[1, 2]': 'three'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={1: 'two'}): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={1: 'two'}, lazy=True): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={1: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={1.1: 'two'}): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={1.1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={1.1: 'two'}, lazy=True): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={1.1: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={True: 'two'}): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={True: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={True: 'two'}, lazy=True): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={True: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={None: 'two'}): _TestOutput(payload='{"None": "two"}', round_trip={'None': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={None: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"None": "two"}', round_trip={'None': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={None: 'two'}, lazy=True): _TestOutput(payload='{"None": "two"}', round_trip={'None': 'two'}, tags=()), +_TestParameters(profile_name='fallback_to_str', value={None: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"None": "two"}', round_trip={'None': 'two'}, tags=()), _TestParameters(profile_name='fallback_to_str', value=b'\x00'): _TestOutput(payload='"\\u0000"', round_trip='\x00', tags=()), _TestParameters(profile_name='fallback_to_str', value=b'\x00', tags=(Deprecated(msg='x'),)): _TestOutput(payload='"\\u0000"', round_trip='\x00', tags=()), _TestParameters(profile_name='fallback_to_str', value=b'\x80'): _TestOutput(payload='"\\udc80"', round_trip=AnsibleRuntimeError('Refusing to deserialize an invalid UTF8 string value.'), tags=()), diff --git a/test/units/utils/expected_serialization_profiles/inventory_legacy.txt b/test/units/utils/expected_serialization_profiles/inventory_legacy.txt index 44f0438bf2a..be5a1b642f8 100644 --- a/test/units/utils/expected_serialization_profiles/inventory_legacy.txt +++ b/test/units/utils/expected_serialization_profiles/inventory_legacy.txt @@ -41,12 +41,28 @@ _TestParameters(profile_name='inventory_legacy', value={'a': 1}, lazy=True): _Te _TestParameters(profile_name='inventory_legacy', value={'a': 1}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"a": 1}', round_trip={'a': 1}, tags=()), _TestParameters(profile_name='inventory_legacy', value=CustomMapping({'a': 1})): _TestOutput(payload='{"a": 1}', round_trip={'a': 1}, tags=()), _TestParameters(profile_name='inventory_legacy', value=CustomMapping({'a': 1}), tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"a": 1}', round_trip={'a': 1}, tags=()), -_TestParameters(profile_name='inventory_legacy', value={(1, 2): 'three'}): _TestOutput(payload='{"(1, 2)": "three"}', round_trip={'(1, 2)': 'three'}, tags=()), -_TestParameters(profile_name='inventory_legacy', value={(1, 2): 'three'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"(1, 2)": "three"}', round_trip={'(1, 2)': 'three'}, tags=()), -_TestParameters(profile_name='inventory_legacy', value={(1, 2): 'three'}, lazy=True): _TestOutput(payload='{"(1, 2)": "three"}', round_trip={'(1, 2)': 'three'}, tags=()), -_TestParameters(profile_name='inventory_legacy', value={(1, 2): 'three'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"(1, 2)": "three"}', round_trip={'(1, 2)': 'three'}, tags=()), -_TestParameters(profile_name='inventory_legacy', value={frozenset({1, 2}): 'three'}): _TestOutput(payload='{"frozenset({1, 2})": "three"}', round_trip={'frozenset({1, 2})': 'three'}, tags=()), -_TestParameters(profile_name='inventory_legacy', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"frozenset({1, 2})": "three"}', round_trip={'frozenset({1, 2})': 'three'}, tags=()), -_TestParameters(profile_name='inventory_legacy', value={frozenset({1, 2}): 'three'}, lazy=True): _TestOutput(payload='{"frozenset({1, 2})": "three"}', round_trip={'frozenset({1, 2})': 'three'}, tags=()), -_TestParameters(profile_name='inventory_legacy', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"frozenset({1, 2})": "three"}', round_trip={'frozenset({1, 2})': 'three'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={(1, 2): 'three'}): _TestOutput(payload=TypeError("Key of type 'tuple' is not JSON serializable by the 'inventory_legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='inventory_legacy', value={(1, 2): 'three'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'tuple' is not JSON serializable by the 'inventory_legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='inventory_legacy', value={(1, 2): 'three'}, lazy=True): _TestOutput(payload=TypeError("Key of type 'tuple' is not JSON serializable by the 'inventory_legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='inventory_legacy', value={(1, 2): 'three'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload=TypeError("Key of type 'tuple' is not JSON serializable by the 'inventory_legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='inventory_legacy', value={frozenset({1, 2}): 'three'}): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'inventory_legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='inventory_legacy', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'inventory_legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='inventory_legacy', value={frozenset({1, 2}): 'three'}, lazy=True): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'inventory_legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='inventory_legacy', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'inventory_legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='inventory_legacy', value={1: 'two'}): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={1: 'two'}, lazy=True): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={1: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={1.1: 'two'}): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={1.1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={1.1: 'two'}, lazy=True): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={1.1: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={True: 'two'}): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={True: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={True: 'two'}, lazy=True): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={True: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={None: 'two'}): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={None: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={None: 'two'}, lazy=True): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='inventory_legacy', value={None: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), } diff --git a/test/units/utils/expected_serialization_profiles/legacy.txt b/test/units/utils/expected_serialization_profiles/legacy.txt index ff54b346f6a..8e3f1e389b8 100644 --- a/test/units/utils/expected_serialization_profiles/legacy.txt +++ b/test/units/utils/expected_serialization_profiles/legacy.txt @@ -41,12 +41,28 @@ _TestParameters(profile_name='legacy', value={'a': 1}, lazy=True): _TestOutput(p _TestParameters(profile_name='legacy', value={'a': 1}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"a": 1}', round_trip={'a': 1}, tags=()), _TestParameters(profile_name='legacy', value=CustomMapping({'a': 1})): _TestOutput(payload='{"a": 1}', round_trip={'a': 1}, tags=()), _TestParameters(profile_name='legacy', value=CustomMapping({'a': 1}), tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"a": 1}', round_trip={'a': 1}, tags=()), -_TestParameters(profile_name='legacy', value={(1, 2): 'three'}): _TestOutput(payload='{"(1, 2)": {"__ansible_unsafe": "three"}}', round_trip={'(1, 2)': 'three'}, tags=()), -_TestParameters(profile_name='legacy', value={(1, 2): 'three'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"(1, 2)": {"__ansible_unsafe": "three"}}', round_trip={'(1, 2)': 'three'}, tags=()), -_TestParameters(profile_name='legacy', value={(1, 2): 'three'}, lazy=True): _TestOutput(payload='{"(1, 2)": {"__ansible_unsafe": "three"}}', round_trip={'(1, 2)': 'three'}, tags=()), -_TestParameters(profile_name='legacy', value={(1, 2): 'three'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"(1, 2)": {"__ansible_unsafe": "three"}}', round_trip={'(1, 2)': 'three'}, tags=()), -_TestParameters(profile_name='legacy', value={frozenset({1, 2}): 'three'}): _TestOutput(payload='{"frozenset({1, 2})": {"__ansible_unsafe": "three"}}', round_trip={'frozenset({1, 2})': 'three'}, tags=()), -_TestParameters(profile_name='legacy', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"frozenset({1, 2})": {"__ansible_unsafe": "three"}}', round_trip={'frozenset({1, 2})': 'three'}, tags=()), -_TestParameters(profile_name='legacy', value={frozenset({1, 2}): 'three'}, lazy=True): _TestOutput(payload='{"frozenset({1, 2})": {"__ansible_unsafe": "three"}}', round_trip={'frozenset({1, 2})': 'three'}, tags=()), -_TestParameters(profile_name='legacy', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"frozenset({1, 2})": {"__ansible_unsafe": "three"}}', round_trip={'frozenset({1, 2})': 'three'}, tags=()), +_TestParameters(profile_name='legacy', value={(1, 2): 'three'}): _TestOutput(payload=TypeError("Key of type 'tuple' is not JSON serializable by the 'legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='legacy', value={(1, 2): 'three'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'tuple' is not JSON serializable by the 'legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='legacy', value={(1, 2): 'three'}, lazy=True): _TestOutput(payload=TypeError("Key of type 'tuple' is not JSON serializable by the 'legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='legacy', value={(1, 2): 'three'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload=TypeError("Key of type 'tuple' is not JSON serializable by the 'legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='legacy', value={frozenset({1, 2}): 'three'}): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='legacy', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='legacy', value={frozenset({1, 2}): 'three'}, lazy=True): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='legacy', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'legacy' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='legacy', value={1: 'two'}): _TestOutput(payload='{"1": {"__ansible_unsafe": "two"}}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"1": {"__ansible_unsafe": "two"}}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={1: 'two'}, lazy=True): _TestOutput(payload='{"1": {"__ansible_unsafe": "two"}}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={1: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"1": {"__ansible_unsafe": "two"}}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={1.1: 'two'}): _TestOutput(payload='{"1.1": {"__ansible_unsafe": "two"}}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={1.1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"1.1": {"__ansible_unsafe": "two"}}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={1.1: 'two'}, lazy=True): _TestOutput(payload='{"1.1": {"__ansible_unsafe": "two"}}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={1.1: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"1.1": {"__ansible_unsafe": "two"}}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={True: 'two'}): _TestOutput(payload='{"true": {"__ansible_unsafe": "two"}}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={True: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"true": {"__ansible_unsafe": "two"}}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={True: 'two'}, lazy=True): _TestOutput(payload='{"true": {"__ansible_unsafe": "two"}}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={True: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"true": {"__ansible_unsafe": "two"}}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={None: 'two'}): _TestOutput(payload='{"null": {"__ansible_unsafe": "two"}}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={None: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"null": {"__ansible_unsafe": "two"}}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={None: 'two'}, lazy=True): _TestOutput(payload='{"null": {"__ansible_unsafe": "two"}}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='legacy', value={None: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"null": {"__ansible_unsafe": "two"}}', round_trip={'null': 'two'}, tags=()), } diff --git a/test/units/utils/expected_serialization_profiles/module_legacy_c2m.txt b/test/units/utils/expected_serialization_profiles/module_legacy_c2m.txt index 11b37007990..afc4245042b 100644 --- a/test/units/utils/expected_serialization_profiles/module_legacy_c2m.txt +++ b/test/units/utils/expected_serialization_profiles/module_legacy_c2m.txt @@ -49,4 +49,20 @@ _TestParameters(profile_name='module_legacy_c2m', value={frozenset({1, 2}): 'thr _TestParameters(profile_name='module_legacy_c2m', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'module_legacy_c2m' profile."), round_trip=None, tags=()), _TestParameters(profile_name='module_legacy_c2m', value={frozenset({1, 2}): 'three'}, lazy=True): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'module_legacy_c2m' profile."), round_trip=None, tags=()), _TestParameters(profile_name='module_legacy_c2m', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'module_legacy_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={1: 'two'}): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={1: 'two'}, lazy=True): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={1: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={1.1: 'two'}): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={1.1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={1.1: 'two'}, lazy=True): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={1.1: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={True: 'two'}): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={True: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={True: 'two'}, lazy=True): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={True: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={None: 'two'}): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={None: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={None: 'two'}, lazy=True): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_c2m', value={None: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), } diff --git a/test/units/utils/expected_serialization_profiles/module_legacy_m2c.txt b/test/units/utils/expected_serialization_profiles/module_legacy_m2c.txt index 2cf243430f8..5c20e01aa9a 100644 --- a/test/units/utils/expected_serialization_profiles/module_legacy_m2c.txt +++ b/test/units/utils/expected_serialization_profiles/module_legacy_m2c.txt @@ -62,4 +62,16 @@ _TestParameters(profile_name='module_legacy_m2c', value={(1, 2): 'three'}, tags= _TestParameters(profile_name='module_legacy_m2c', value={frozenset({1, 2}): 'three'}): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'module_legacy_m2c' profile."), round_trip=None, tags=()), _TestParameters(profile_name='module_legacy_m2c', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'module_legacy_m2c' profile."), round_trip=None, tags=()), _TestParameters(profile_name='module_legacy_m2c', value={frozenset({1, 2}): 'three'}, tags=(TrustedAsTemplate(),)): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'module_legacy_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_legacy_m2c', value={1: 'two'}): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_m2c', value={1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"value": {"1": "two"}, "tags": [{"msg": "x", "__ansible_type": "Deprecated"}], "__ansible_type": "_AnsibleTaggedDict"}', round_trip={'1': 'two'}, tags=(Deprecated(msg='x'),)), +_TestParameters(profile_name='module_legacy_m2c', value={1: 'two'}, tags=(TrustedAsTemplate(),)): _TestOutput(payload=TypeError("Object of type 'TrustedAsTemplate' is not JSON serializable by the 'module_legacy_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_legacy_m2c', value={1.1: 'two'}): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_m2c', value={1.1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"value": {"1.1": "two"}, "tags": [{"msg": "x", "__ansible_type": "Deprecated"}], "__ansible_type": "_AnsibleTaggedDict"}', round_trip={'1.1': 'two'}, tags=(Deprecated(msg='x'),)), +_TestParameters(profile_name='module_legacy_m2c', value={1.1: 'two'}, tags=(TrustedAsTemplate(),)): _TestOutput(payload=TypeError("Object of type 'TrustedAsTemplate' is not JSON serializable by the 'module_legacy_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_legacy_m2c', value={True: 'two'}): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_m2c', value={True: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"value": {"true": "two"}, "tags": [{"msg": "x", "__ansible_type": "Deprecated"}], "__ansible_type": "_AnsibleTaggedDict"}', round_trip={'true': 'two'}, tags=(Deprecated(msg='x'),)), +_TestParameters(profile_name='module_legacy_m2c', value={True: 'two'}, tags=(TrustedAsTemplate(),)): _TestOutput(payload=TypeError("Object of type 'TrustedAsTemplate' is not JSON serializable by the 'module_legacy_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_legacy_m2c', value={None: 'two'}): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='module_legacy_m2c', value={None: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"value": {"null": "two"}, "tags": [{"msg": "x", "__ansible_type": "Deprecated"}], "__ansible_type": "_AnsibleTaggedDict"}', round_trip={'null': 'two'}, tags=(Deprecated(msg='x'),)), +_TestParameters(profile_name='module_legacy_m2c', value={None: 'two'}, tags=(TrustedAsTemplate(),)): _TestOutput(payload=TypeError("Object of type 'TrustedAsTemplate' is not JSON serializable by the 'module_legacy_m2c' profile."), round_trip=None, tags=()), } diff --git a/test/units/utils/expected_serialization_profiles/module_modern_c2m.txt b/test/units/utils/expected_serialization_profiles/module_modern_c2m.txt index b69658f1d4b..adab6c4522d 100644 --- a/test/units/utils/expected_serialization_profiles/module_modern_c2m.txt +++ b/test/units/utils/expected_serialization_profiles/module_modern_c2m.txt @@ -49,4 +49,20 @@ _TestParameters(profile_name='module_modern_c2m', value={frozenset({1, 2}): 'thr _TestParameters(profile_name='module_modern_c2m', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), _TestParameters(profile_name='module_modern_c2m', value={frozenset({1, 2}): 'three'}, lazy=True): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), _TestParameters(profile_name='module_modern_c2m', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={1: 'two'}): _TestOutput(payload=TypeError("Key of type 'int' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'int' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={1: 'two'}, lazy=True): _TestOutput(payload=TypeError("Key of type 'int' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={1: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload=TypeError("Key of type 'int' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={1.1: 'two'}): _TestOutput(payload=TypeError("Key of type 'float' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={1.1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'float' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={1.1: 'two'}, lazy=True): _TestOutput(payload=TypeError("Key of type 'float' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={1.1: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload=TypeError("Key of type 'float' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={True: 'two'}): _TestOutput(payload=TypeError("Key of type 'bool' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={True: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'bool' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={True: 'two'}, lazy=True): _TestOutput(payload=TypeError("Key of type 'bool' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={True: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload=TypeError("Key of type 'bool' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={None: 'two'}): _TestOutput(payload=TypeError("Key of type 'NoneType' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={None: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'NoneType' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={None: 'two'}, lazy=True): _TestOutput(payload=TypeError("Key of type 'NoneType' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_c2m', value={None: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload=TypeError("Key of type 'NoneType' is not JSON serializable by the 'module_modern_c2m' profile."), round_trip=None, tags=()), } diff --git a/test/units/utils/expected_serialization_profiles/module_modern_m2c.txt b/test/units/utils/expected_serialization_profiles/module_modern_m2c.txt index 895867e45c5..358731507e3 100644 --- a/test/units/utils/expected_serialization_profiles/module_modern_m2c.txt +++ b/test/units/utils/expected_serialization_profiles/module_modern_m2c.txt @@ -62,4 +62,16 @@ _TestParameters(profile_name='module_modern_m2c', value={(1, 2): 'three'}, tags= _TestParameters(profile_name='module_modern_m2c', value={frozenset({1, 2}): 'three'}): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), _TestParameters(profile_name='module_modern_m2c', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), _TestParameters(profile_name='module_modern_m2c', value={frozenset({1, 2}): 'three'}, tags=(TrustedAsTemplate(),)): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_m2c', value={1: 'two'}): _TestOutput(payload=TypeError("Key of type 'int' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_m2c', value={1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'int' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_m2c', value={1: 'two'}, tags=(TrustedAsTemplate(),)): _TestOutput(payload=TypeError("Key of type 'int' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_m2c', value={1.1: 'two'}): _TestOutput(payload=TypeError("Key of type 'float' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_m2c', value={1.1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'float' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_m2c', value={1.1: 'two'}, tags=(TrustedAsTemplate(),)): _TestOutput(payload=TypeError("Key of type 'float' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_m2c', value={True: 'two'}): _TestOutput(payload=TypeError("Key of type 'bool' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_m2c', value={True: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'bool' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_m2c', value={True: 'two'}, tags=(TrustedAsTemplate(),)): _TestOutput(payload=TypeError("Key of type 'bool' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_m2c', value={None: 'two'}): _TestOutput(payload=TypeError("Key of type 'NoneType' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_m2c', value={None: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'NoneType' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='module_modern_m2c', value={None: 'two'}, tags=(TrustedAsTemplate(),)): _TestOutput(payload=TypeError("Key of type 'NoneType' is not JSON serializable by the 'module_modern_m2c' profile."), round_trip=None, tags=()), } diff --git a/test/units/utils/expected_serialization_profiles/tagless.txt b/test/units/utils/expected_serialization_profiles/tagless.txt index afc16337a29..a0f4fdc1dd5 100644 --- a/test/units/utils/expected_serialization_profiles/tagless.txt +++ b/test/units/utils/expected_serialization_profiles/tagless.txt @@ -49,4 +49,20 @@ _TestParameters(profile_name='tagless', value={frozenset({1, 2}): 'three'}): _Te _TestParameters(profile_name='tagless', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'tagless' profile."), round_trip=None, tags=()), _TestParameters(profile_name='tagless', value={frozenset({1, 2}): 'three'}, lazy=True): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'tagless' profile."), round_trip=None, tags=()), _TestParameters(profile_name='tagless', value={frozenset({1, 2}): 'three'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload=TypeError("Key of type 'frozenset' is not JSON serializable by the 'tagless' profile."), round_trip=None, tags=()), +_TestParameters(profile_name='tagless', value={1: 'two'}): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={1: 'two'}, lazy=True): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={1: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"1": "two"}', round_trip={'1': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={1.1: 'two'}): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={1.1: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={1.1: 'two'}, lazy=True): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={1.1: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"1.1": "two"}', round_trip={'1.1': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={True: 'two'}): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={True: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={True: 'two'}, lazy=True): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={True: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"true": "two"}', round_trip={'true': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={None: 'two'}): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={None: 'two'}, tags=(Deprecated(msg='x'),)): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={None: 'two'}, lazy=True): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), +_TestParameters(profile_name='tagless', value={None: 'two'}, tags=(Deprecated(msg='x'),), lazy=True): _TestOutput(payload='{"null": "two"}', round_trip={'null': 'two'}, tags=()), } diff --git a/test/units/utils/test_serialization_profiles.py b/test/units/utils/test_serialization_profiles.py index b364a3337cd..fcdc0ab7262 100644 --- a/test/units/utils/test_serialization_profiles.py +++ b/test/units/utils/test_serialization_profiles.py @@ -54,6 +54,10 @@ basic_values = ( CustomMapping(dict(a=1)), {(1, 2): "three"}, # hashable non-scalar key {frozenset((1, 2)): "three"}, # hashable non-scalar key + {1: "two"}, # int key + {1.1: "two"}, # float key + {True: "two"}, # bool key + {None: "two"}, # None key ) # DTFIX5: we need tests for recursion, specifically things like custom sequences and mappings when: @@ -83,7 +87,7 @@ def test_cache_persistence_schema() -> None: # DTFIX5: ensure all types/attrs included in _profiles._common_module_response_types are represented here, since they can appear in cached responses expected_schema_id = 1 - expected_schema_hash = "bf52e60cf1d25a3f8b6bfdf734781ee07cfe46e94189d2f538815c5000b617c6" + expected_schema_hash = "0bc4bec94abe6ec0f62fc9f45ea1099ea65b13f00a5e5de1699e0dbcf0de2b2c" test_hash = hashlib.sha256() test_hash.update(pathlib.Path(DataSet.PROFILE_DIR / _cache_persistence._Profile.profile_name).with_suffix('.txt').read_bytes())