50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
import pytest
|
|
import os
|
|
import sys
|
|
from unittest.mock import patch, mock_open
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
from ..src.config import Config
|
|
|
|
|
|
class TestConfig:
|
|
"""Test suite for the Config class."""
|
|
testing_dir = Path(str(os.path.dirname(__file__)))
|
|
|
|
def test_config_init(self):
|
|
self.config = Config(self.testing_dir.joinpath("test_config.json"))
|
|
assert self.config is not None
|
|
|
|
def test_config_to_dict(self):
|
|
self.config = Config(self.testing_dir.joinpath("test_config.json"))
|
|
config_dict = self.config.to_dict()
|
|
assert isinstance(config_dict, dict)
|
|
assert "data_path" in config_dict
|
|
assert "host" in config_dict
|
|
assert "abs_api_key" in config_dict
|
|
|
|
def test_config_save_and_load(self):
|
|
self.config = Config(self.testing_dir.joinpath("test_config.json"))
|
|
self.config.data_path = self.testing_dir.joinpath("data")
|
|
self.config.host = "testhost"
|
|
self.config.abs_api_key = "testkey"
|
|
|
|
# Save the configuration
|
|
save_result = self.config.save()
|
|
assert save_result is True
|
|
assert self.config.path.exists()
|
|
|
|
# Load the configuration into a new instance
|
|
new_config = Config(self.testing_dir.joinpath("test_config.json"))
|
|
assert new_config.data_path == self.config.data_path
|
|
assert new_config.host == self.config.host
|
|
assert new_config.abs_api_key == self.config.abs_api_key
|
|
# Clean up
|
|
if self.config.path.exists():
|
|
self.config.path.unlink()
|
|
if self.config.data_path.exists():
|
|
self.config.data_path.rmdir()
|
|
|