Debian Codegraph @

test/units/module_utils/common/test_json.py

raw
1 from __future__ import annotations
2
3 import json
4
5 from ansible.module_utils import _internal
6 from ansible.module_utils.common.json import AnsibleJSONEncoder
7 from ansible.module_utils._internal._json._legacy_encoder import LegacyTargetJSONEncoder
8
9
10 def test_controller_impl_patch() -> None:
11 """Ensure that the context-appropriate implementation of `AnsibleJSONEncoder` is patched into the module."""
12 if _internal.is_controller:
13 assert AnsibleJSONEncoder is not LegacyTargetJSONEncoder
14 else:
15 assert AnsibleJSONEncoder is LegacyTargetJSONEncoder
16
17
18 def test_mu_bytes() -> None:
19 assert json.dumps(b'abc', cls=LegacyTargetJSONEncoder, _decode_bytes=True) == '"abc"'