File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ [section ]
2+ key = 42
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments