|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from shelloracle.config import get_config, initialize_config |
| 6 | + |
| 7 | + |
| 8 | +class TestConfiguration: |
| 9 | + @pytest.fixture |
| 10 | + def default_config(self, set_config): |
| 11 | + config = {'shelloracle': {'provider': 'Ollama', 'spinner_style': 'earth'}, |
| 12 | + 'provider': {'Ollama': {'host': 'localhost', 'port': 11434, 'model': 'dolphin-mistral'}}} |
| 13 | + set_config(config) |
| 14 | + return config |
| 15 | + |
| 16 | + def test_initialize_config(self, default_config): |
| 17 | + with pytest.raises(RuntimeError): |
| 18 | + initialize_config() |
| 19 | + |
| 20 | + def test_from_file(self, default_config): |
| 21 | + assert get_config() == default_config |
| 22 | + |
| 23 | + def test_getitem(self, default_config): |
| 24 | + for key in default_config: |
| 25 | + assert default_config[key] == get_config()[key] |
| 26 | + |
| 27 | + def test_len(self, default_config): |
| 28 | + assert len(default_config) == len(get_config()) |
| 29 | + |
| 30 | + def test_iter(self, default_config): |
| 31 | + assert list(iter(default_config)) == list(iter(get_config())) |
| 32 | + |
| 33 | + def test_str(self, default_config): |
| 34 | + assert str(get_config()) == f"Configuration({default_config})" |
| 35 | + |
| 36 | + def test_repr(self, default_config): |
| 37 | + assert repr(default_config) == str(default_config) |
| 38 | + |
| 39 | + def test_provider(self, default_config): |
| 40 | + assert get_config().provider == "Ollama" |
| 41 | + |
| 42 | + def test_spinner_style(self, default_config): |
| 43 | + assert get_config().spinner_style == "earth" |
| 44 | + |
| 45 | + def test_no_spinner_style(self, caplog, set_config): |
| 46 | + config_dict = {'shelloracle': {'provider': 'Ollama'}, |
| 47 | + 'provider': {'Ollama': {'host': 'localhost', 'port': 11434, 'model': 'dolphin-mistral'}}} |
| 48 | + set_config(config_dict) |
| 49 | + assert get_config().spinner_style is None |
| 50 | + assert "invalid spinner style" not in caplog.text |
| 51 | + |
| 52 | + def test_invalid_spinner_style(self, caplog, set_config): |
| 53 | + config_dict = {'shelloracle': {'provider': 'Ollama', 'spinner_style': 'invalid'}, |
| 54 | + 'provider': {'Ollama': {'host': 'localhost', 'port': 11434, 'model': 'dolphin-mistral'}}} |
| 55 | + set_config(config_dict) |
| 56 | + assert get_config().spinner_style is None |
| 57 | + assert "invalid spinner style" in caplog.text |
0 commit comments