-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_config.py
More file actions
58 lines (41 loc) · 1.79 KB
/
test_config.py
File metadata and controls
58 lines (41 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Tests for gbot.core.config."""
import yaml
from gbot.core.config import Config, load_config
def test_defaults():
cfg = Config()
assert cfg.assistant.name == "GraphBot"
assert cfg.assistant.session_token_limit == 30_000
assert cfg.database.path == "data/gbot.db"
assert cfg.rag is None
def test_from_dict():
cfg = Config(
assistant={"name": "TestBot", "model": "openai/gpt-4o"},
providers={"anthropic": {"api_key": "sk-test"}},
)
assert cfg.assistant.name == "TestBot"
assert cfg.providers.anthropic.api_key == "sk-test"
def test_get_api_key():
cfg = Config(providers={"anthropic": {"api_key": "sk-ant"}})
assert cfg.get_api_key("anthropic/claude-sonnet") == "sk-ant"
assert cfg.get_api_key() is None or cfg.get_api_key("unknown") == "sk-ant"
def test_load_yaml(tmp_path):
f = tmp_path / "config.yaml"
f.write_text(yaml.dump({"assistant": {"name": "YamlBot"}}))
cfg = load_config(f)
assert cfg.assistant.name == "YamlBot"
def test_load_missing(tmp_path):
cfg = load_config(tmp_path / "nope.yaml")
assert cfg.assistant.name == "GraphBot"
# ── Owner Config ──────────────────────────────────────────
def test_owner_config_none():
"""No owner configured → owner is None, owner_user_id is None."""
cfg = Config()
assert cfg.assistant.owner is None
assert cfg.owner_user_id is None
def test_owner_config_from_dict():
"""Owner parsed from dict correctly."""
cfg = Config(assistant={"name": "Bot", "owner": {"username": "ali", "name": "Ali"}})
assert cfg.assistant.owner is not None
assert cfg.assistant.owner.username == "ali"
assert cfg.assistant.owner.name == "Ali"
assert cfg.owner_user_id == "ali"