29 lines
892 B
Python
29 lines
892 B
Python
from pathlib import Path
|
|
import toml
|
|
from ctf.utils import load_config
|
|
|
|
def test_load_config_valid_file(tmp_path):
|
|
# 1. Setup: Create a temporary TOML file
|
|
config_file = tmp_path / "test_config.toml"
|
|
test_data = {
|
|
"Competition": {"name": "TestComp"},
|
|
"Environment": {"data_dir": "/tmp/ctf"}
|
|
}
|
|
with open(config_file, "w") as f:
|
|
toml.dump(test_data, f)
|
|
|
|
# 2. Act: Load the config using our function
|
|
loaded_data = load_config(str(config_file))
|
|
|
|
# 3. Assert: Verify the data matches
|
|
assert loaded_data["Competition"]["name"] == "TestComp"
|
|
assert loaded_data["Environment"]["data_dir"] == "/tmp/ctf"
|
|
|
|
def test_load_config_missing_file():
|
|
# Act: Try to load a file that doesn't exist
|
|
loaded_data = load_config("nonexistent_file.toml")
|
|
|
|
# Assert: Should return an empty dictionary
|
|
assert loaded_data == {}
|
|
|