diff --git a/server/pytest.ini b/server/pytest.ini new file mode 100644 index 0000000..7dab082 --- /dev/null +++ b/server/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +python_files = tests/*.py diff --git a/server/tests/conftest.py b/server/tests/conftest.py new file mode 100644 index 0000000..37115e9 --- /dev/null +++ b/server/tests/conftest.py @@ -0,0 +1,4 @@ +import sys +import os + +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src'))) \ No newline at end of file diff --git a/server/tests/test_config.py b/server/tests/test_config.py new file mode 100644 index 0000000..55ea2c1 --- /dev/null +++ b/server/tests/test_config.py @@ -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()