File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ def get_settings() -> CLISettings:
7171 # NOTE: This duplicates the source of truth for the env var slightly so that
7272 # we can use home as the source for the .env file as a 2-phase init.
7373 home = Path (os .getenv ("CONTEXTFORGE_HOME" , DEFAULT_HOME ))
74+ home .mkdir (exist_ok = True )
7475 with _chdir (home ):
7576
7677 settings = CLISettings (client_mode = True )
Original file line number Diff line number Diff line change 66
77Tests for configuration management.
88"""
9+ # Standard
10+ from pathlib import Path
11+ from unittest import mock
12+ import os
13+ import tempfile
914
1015# First-Party
1116from cforge .config import get_settings
@@ -27,3 +32,17 @@ def test_get_settings_singleton(self) -> None:
2732 settings1 = get_settings ()
2833 settings2 = get_settings ()
2934 assert settings1 is settings2
35+
36+ def test_get_settings_make_home (self ) -> None :
37+ """Test that get_settings will create the home dir if needed"""
38+ try :
39+ get_settings .cache_clear ()
40+ with tempfile .TemporaryDirectory () as work_dir :
41+ home_dir = Path (work_dir ) / "some_new_home"
42+ assert not home_dir .exists ()
43+ with mock .patch .dict (os .environ , {"CONTEXTFORGE_HOME" : str (home_dir )}):
44+ settings = get_settings ()
45+ assert settings .contextforge_home == home_dir
46+ assert home_dir .exists ()
47+ finally :
48+ get_settings .cache_clear ()
You can’t perform that action at this time.
0 commit comments