Skip to content

Commit

Permalink
chg: validation aiosettings
Browse files Browse the repository at this point in the history
  • Loading branch information
bossjones committed May 5, 2024
1 parent fb3cf60 commit e9eb32c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/goob_ai/aio_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ class AioSettings(BaseSettings):

# You can change the prefix for all environment variables by setting the env_prefix config setting, or via the _env_prefix keyword argument on instantiation:

model_config = SettingsConfigDict(env_prefix="GOOB_AI_")
model_config = SettingsConfigDict(
env_prefix="GOOB_AI_CONFIG_", env_file=(".env", ".envrc"), env_file_encoding="utf-8"
)

monitor_host: str = "localhost"
monitor_port: int = 50102
Expand All @@ -124,7 +126,13 @@ class AioSettings(BaseSettings):

discord_token: str = ""

openai_token: str = ""
# openai_token: str = ""
openai_api_key: str = ""

discord_admin_user_invited: bool = False

better_exceptions: int = Field(..., env="BETTER_EXCEPTIONS", description="Enable better exceptions")
pythonasynciodebug: int = Field(..., env="PYTHONASYNCIODEBUG", description="enable or disable asyncio debugging")

# Try loading patchmatch
globals_try_patchmatch: bool = True
Expand Down
40 changes: 40 additions & 0 deletions tests/test_aio_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""test_settings"""
# pylint: disable=no-self-use
from __future__ import annotations
import os
from pathlib import Path, PosixPath

import pytest

from goob_ai import aio_settings
from goob_ai.utils.file_functions import tilda

IS_RUNNING_ON_GITHUB_ACTIONS = bool(os.environ.get("GITHUB_ACTOR"))

# TODO: Make sure os,environ unsets values while running tests
@pytest.mark.unittest
class TestSettings:
def test_defaults(
self,
) -> None:
test_settings: aio_settings.AioSettings = aio_settings.AioSettings()
assert test_settings.monitor_host == "localhost"
assert test_settings.monitor_port == 50102
assert test_settings.prefix == "/"
assert test_settings.discord_admin_user_id == 3282
assert test_settings.discord_general_channel == 908894727779258390
assert test_settings.discord_admin_user_invited == False
assert test_settings.better_exceptions == 1
assert test_settings.pythonasynciodebug == 1
assert test_settings.globals_try_patchmatch == True
assert test_settings.globals_always_use_cpu == False
assert test_settings.globals_internet_available == True
assert test_settings.globals_full_precision == False
assert test_settings.globals_ckpt_convert == False
assert test_settings.globals_log_tokenization == False
assert test_settings.redis_host == "localhost"
assert test_settings.redis_port == 7600
assert test_settings.redis_user is None
assert test_settings.redis_pass is None
assert test_settings.redis_base is None
assert str(test_settings.redis_url) == "redis://localhost:7600"

0 comments on commit e9eb32c

Please sign in to comment.