From 9e4297276f982466aaaab3459efa247b2c6a906a Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Wed, 4 Feb 2026 07:05:33 +0000 Subject: [PATCH] Initial upload: ConfigConvert CLI with full test suite and CI/CD --- tests/test_converters/test_yaml.py | 83 ++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/test_converters/test_yaml.py diff --git a/tests/test_converters/test_yaml.py b/tests/test_converters/test_yaml.py new file mode 100644 index 0000000..2248f94 --- /dev/null +++ b/tests/test_converters/test_yaml.py @@ -0,0 +1,83 @@ +"""Tests for YAML converter.""" + +import pytest +import tempfile +import os +from pathlib import Path + +from config_convert.converters import YAMLConverter + + +class TestYAMLConverter: + @pytest.fixture + def converter(self): + return YAMLConverter() + + def test_loads_valid_yaml(self, converter): + data = "name: test\nvalue: 123" + result = converter.loads(data) + assert result == {"name": "test", "value": 123} + + def test_loads_nested_yaml(self, converter): + data = """database: + host: localhost + port: 5432 + """ + result = converter.loads(data) + assert result == {"database": {"host": "localhost", "port": 5432}} + + def test_loads_array_yaml(self, converter): + data = "tags:\n - a\n - b\n - c" + result = converter.loads(data) + assert result == {"tags": ["a", "b", "c"]} + + def test_loads_multiline_string(self, converter): + data = """description: | + This is a + multiline string + """ + result = converter.loads(data) + assert result["description"] == "This is a\nmultiline string\n" + + def test_dumps_basic_dict(self, converter): + data = {"name": "test", "value": 123} + result = converter.dumps(data) + assert "name: test" in result + + def test_dumps_nested_dict(self, converter): + data = {"database": {"host": "localhost", "port": 5432}} + result = converter.dumps(data) + assert "host: localhost" in result + + def test_roundtrip(self, converter): + original = {"name": "test", "version": "1.0.0", "enabled": True, "count": 42} + dumped = converter.dumps(original) + loaded = converter.loads(dumped) + assert loaded == original + + def test_load_file(self, converter, temp_file, sample_yaml): + import yaml + gen = temp_file(sample_yaml, suffix=".yaml") + path = next(gen) + try: + result = converter.load(path) + assert result["name"] == "test-project" + finally: + os.unlink(path) + + def test_dump_file(self, converter, temp_dir, sample_yaml): + import yaml + import shutil + path = tempfile.mktemp(suffix=".yaml") + try: + data = yaml.safe_load(sample_yaml) + converter.dump(data, path) + result = converter.load(path) + assert result == data + finally: + if Path(path).exists(): + os.unlink(path) + + def test_invalid_yaml_raises(self, converter): + with pytest.raises(Exception): + converter.loads("[invalid yaml")