Skip to content

Commit 05486df

Browse files
adding simple unit test
1 parent 8120a32 commit 05486df

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

tests/test-config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[section]
2+
key = 42

tests/utils/test_load_config.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
import tomllib
5+
6+
from src.utils import load_config # adjust if your import path differs
7+
8+
CONFIG_PATH = Path(__file__).parent.parent / "test-config.toml"
9+
10+
11+
class TestLoadConfigSuccess:
12+
def test_loads_valid_toml_as_dict(self) -> None:
13+
result = load_config(CONFIG_PATH)
14+
15+
assert result == {"section": {"key": 42}}
16+
17+
def test_accepts_str_path(self) -> None:
18+
result = load_config(str(CONFIG_PATH))
19+
20+
assert result == {"section": {"key": 42}}
21+
22+
def test_nested_key_value(self) -> None:
23+
result = load_config(CONFIG_PATH)
24+
25+
assert result["section"]["key"] == 42
26+
27+
28+
class TestLoadConfigMissingFile:
29+
def test_raises_file_not_found_for_missing_path(self) -> None:
30+
missing_path = CONFIG_PATH.parent / "does_not_exist.toml"
31+
32+
with pytest.raises(FileNotFoundError, match=str(missing_path)):
33+
load_config(missing_path)
34+
35+
def test_raises_file_not_found_for_missing_str_path(self) -> None:
36+
missing_path = str(CONFIG_PATH.parent / "does_not_exist.toml")
37+
38+
with pytest.raises(FileNotFoundError):
39+
load_config(missing_path)

0 commit comments

Comments
 (0)