pyc2/server/tests/test_config.py

25 lines
738 B
Python
Raw Normal View History

2024-09-07 21:36:44 +00:00
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()