[GEMINI] Refactor tests to use Config class and autouse test isolation fixture
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
# tests/test_config.py
|
||||
import toml
|
||||
from pathlib import Path
|
||||
from ctf.config import load_config, write_config
|
||||
from ctf.config import Config
|
||||
|
||||
TEST_ENV = Path("tests/env")
|
||||
|
||||
# {{{ test_load_config_static
|
||||
def test_load_config_static():
|
||||
"""Verifies load_config using the persistent test file."""
|
||||
"""Verifies Config loading using a persistent test file."""
|
||||
config_file = TEST_ENV / "config.toml"
|
||||
test_data = {
|
||||
"Competition": {"name": "PersistentComp"},
|
||||
@@ -17,17 +17,19 @@ def test_load_config_static():
|
||||
with open(config_file, "w") as f:
|
||||
toml.dump(test_data, f)
|
||||
|
||||
loaded_data = load_config(str(config_file))
|
||||
assert loaded_data["Competition"]["name"] == "PersistentComp"
|
||||
cfg = Config(config_file)
|
||||
assert cfg.data["Competition"]["name"] == "PersistentComp"
|
||||
# }}}
|
||||
|
||||
# {{{ test_write_config_static
|
||||
def test_write_config_static():
|
||||
"""Verifies write_config by writing and reloading."""
|
||||
"""Verifies Config writing by saving and reloading."""
|
||||
config_file = TEST_ENV / "test_write_config.toml"
|
||||
test_data = {"TestKey": "TestVal"}
|
||||
|
||||
write_config(test_data, str(config_file))
|
||||
loaded = load_config(str(config_file))
|
||||
assert loaded == test_data
|
||||
cfg = Config(config_file)
|
||||
cfg.save(test_data)
|
||||
|
||||
reloaded = Config(config_file)
|
||||
assert reloaded.data == test_data
|
||||
# }}}
|
||||
|
||||
Reference in New Issue
Block a user