chore: add test for config loader

This commit is contained in:
agatha 2024-09-07 17:36:44 -04:00
parent 6c0eb7f941
commit 9310b2c312
3 changed files with 30 additions and 0 deletions

2
server/pytest.ini Normal file
View File

@ -0,0 +1,2 @@
[pytest]
python_files = tests/*.py

4
server/tests/conftest.py Normal file
View File

@ -0,0 +1,4 @@
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src')))

View File

@ -0,0 +1,24 @@
import unittest
import tempfile
import yaml
from utils.config import load_yaml_config
class TestLoadYamlConfig(unittest.TestCase):
def test_load_valid_yaml(self):
# Create a temporary YAML file
with tempfile.NamedTemporaryFile(mode='w') as f:
yaml.dump({'host': 'example.com', 'port': 8080}, f)
f.flush()
config = load_yaml_config(f.name)
self.assertEqual(config, {'host': 'example.com', 'port': 8080})
def test_load_non_existent_file(self):
# Test loading a non-existent file
config = load_yaml_config('non_existent_file.yaml')
self.assertEqual(config, {'host': '0.0.0.0', 'port': 9999})
if __name__ == '__main__':
unittest.main()