Files
hermes-agent/tests/utils/test_utils_read_json_or_empty.py
alt-glitch a1bbd329ea refactor: split utils.py into the utils package
utils.py held three subjects in one 871-line file. It is now a package with
one module per subject: utils/files.py (atomic writes, temp files, file mode
and owner, signatures and digests, JSON and YAML file helpers), utils/urls.py
(the base_url helpers) and utils/env.py (truthy values, env numbers, proxy
env helpers). utils/__init__.py re-exports every public name, so no importer
changes. Function bodies are unchanged, no function-level import moved, and
the logger keeps the name "utils".

Tests patch a name in the module that now defines it. Patches stay on the
package where production reads the name through a function-level
"from utils import". The tests of utils itself move to tests/utils/.

A root module that becomes a folder drops out of anything that copies root
*.py files plus a fixed list of packages, so the fixtures that build a partial
source tree now list utils, as do pyproject's packages.find, three check
scripts and the CI change classifier.
2026-11-16 17:16:20 +05:30

15 lines
615 B
Python

"""``utils.read_json_or_empty``: the JSON object on disk, or ``{}`` for anything else."""
from utils import read_json_or_empty
def test_reads_an_object_and_treats_missing_damaged_or_non_object_files_as_empty(tmp_path):
path = tmp_path / "store.json"
assert read_json_or_empty(path) == {}
path.write_text('{"task": "snapshot"}', encoding="utf-8")
assert read_json_or_empty(path) == {"task": "snapshot"}
path.write_text('["not a mapping"]', encoding="utf-8")
assert read_json_or_empty(path) == {}
path.write_text("{bad json", encoding="utf-8")
assert read_json_or_empty(path) == {}