/ tests / test_utils_truthy_values.py
test_utils_truthy_values.py
 1  """Tests for shared truthy-value helpers."""
 2  
 3  from utils import env_var_enabled, is_truthy_value
 4  
 5  
 6  def test_is_truthy_value_accepts_common_truthy_strings():
 7      assert is_truthy_value("true") is True
 8      assert is_truthy_value(" YES ") is True
 9      assert is_truthy_value("on") is True
10      assert is_truthy_value("1") is True
11  
12  
13  def test_is_truthy_value_respects_default_for_none():
14      assert is_truthy_value(None, default=True) is True
15      assert is_truthy_value(None, default=False) is False
16  
17  
18  def test_is_truthy_value_rejects_falsey_strings():
19      assert is_truthy_value("false") is False
20      assert is_truthy_value("0") is False
21      assert is_truthy_value("off") is False
22  
23  
24  def test_env_var_enabled_uses_shared_truthy_rules(monkeypatch):
25      monkeypatch.setenv("HERMES_TEST_BOOL", "YeS")
26      assert env_var_enabled("HERMES_TEST_BOOL") is True
27  
28      monkeypatch.setenv("HERMES_TEST_BOOL", "no")
29      assert env_var_enabled("HERMES_TEST_BOOL") is False