From 9310b2c312c366cb6072fd06986bc8f6c384ec22 Mon Sep 17 00:00:00 2001 From: agatha Date: Sat, 7 Sep 2024 17:36:44 -0400 Subject: [PATCH] chore: add test for config loader --- server/pytest.ini | 2 ++ server/tests/conftest.py | 4 ++++ server/tests/test_config.py | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 server/pytest.ini create mode 100644 server/tests/conftest.py create mode 100644 server/tests/test_config.py 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()