chore: add test for config loader
This commit is contained in:
parent
6c0eb7f941
commit
9310b2c312
2
server/pytest.ini
Normal file
2
server/pytest.ini
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[pytest]
|
||||||
|
python_files = tests/*.py
|
4
server/tests/conftest.py
Normal file
4
server/tests/conftest.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src')))
|
24
server/tests/test_config.py
Normal file
24
server/tests/test_config.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user