Files
hermes-agent/tests/utils/test_utils_truthy_values.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

30 lines
952 B
Python

"""Tests for shared truthy-value helpers."""
from utils import env_var_enabled, is_truthy_value
def test_is_truthy_value_accepts_common_truthy_strings():
assert is_truthy_value("true") is True
assert is_truthy_value(" YES ") is True
assert is_truthy_value("on") is True
assert is_truthy_value("1") is True
def test_is_truthy_value_respects_default_for_none():
assert is_truthy_value(None, default=True) is True
assert is_truthy_value(None, default=False) is False
def test_is_truthy_value_rejects_falsey_strings():
assert is_truthy_value("false") is False
assert is_truthy_value("0") is False
assert is_truthy_value("off") is False
def test_env_var_enabled_uses_shared_truthy_rules(monkeypatch):
monkeypatch.setenv("HERMES_TEST_BOOL", "YeS")
assert env_var_enabled("HERMES_TEST_BOOL") is True
monkeypatch.setenv("HERMES_TEST_BOOL", "no")
assert env_var_enabled("HERMES_TEST_BOOL") is False