Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hey/configs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def create():
"""Create a base config file."""
if not config_exists():
os.makedirs(APP_CONFIG_DIR)
os.makedirs(APP_CONFIG_DIR, exist_ok=True)
init_config()
else:
if Confirm.ask(
Expand Down
3 changes: 2 additions & 1 deletion hey/configs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def read_configs() -> dict:


def init_config():
with open(CONFIG_FILE_PATH, "w+") as conf_file:
os.makedirs(APP_CONFIG_DIR, exist_ok=True)
with open(CONFIG_FILE_PATH, "w+", encoding="utf-8") as conf_file:
conf_file.write(json.dumps(BASE_CONFIG, indent=4))


Expand Down
19 changes: 19 additions & 0 deletions tests/test_configs_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json
from pathlib import Path

from hey.configs import utils
from hey.consts import BASE_CONFIG


def test_init_config_creates_directory_and_file(tmp_path, monkeypatch):
config_dir = tmp_path / "hey"
config_file = config_dir / "config.json"

monkeypatch.setattr(utils, "APP_CONFIG_DIR", config_dir)
monkeypatch.setattr(utils, "CONFIG_FILE_PATH", config_file)

utils.init_config()

assert config_file.exists()
loaded = json.loads(config_file.read_text(encoding="utf-8"))
assert loaded == BASE_CONFIG