From 83aab6ce376590078823ec5a649e16373cf7f90c Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Wed, 4 Feb 2026 07:05:34 +0000 Subject: [PATCH] Initial upload: ConfigConvert CLI with full test suite and CI/CD --- tests/test_converters/test_env.py | 117 ++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 tests/test_converters/test_env.py diff --git a/tests/test_converters/test_env.py b/tests/test_converters/test_env.py new file mode 100644 index 0000000..b19145d --- /dev/null +++ b/tests/test_converters/test_env.py @@ -0,0 +1,117 @@ +"""Tests for ENV converter.""" + +import pytest +import tempfile +import os +from pathlib import Path + +from config_convert.converters import ENVConverter + + +class TestENVConverter: + @pytest.fixture + def converter(self): + return ENVConverter() + + def test_loads_valid_env(self, converter): + data = "NAME=test\nVALUE=123" + result = converter.loads(data) + assert result == {"NAME": "test", "VALUE": 123} + + def test_loads_with_spaces(self, converter): + data = "NAME = test" + result = converter.loads(data) + assert result == {"NAME": "test"} + + def test_loads_boolean_strings(self, converter): + data = "ENABLED=true\nDISABLED=false" + result = converter.loads(data) + assert result == {"ENABLED": True, "DISABLED": False} + + def test_loads_integer_strings(self, converter): + data = "COUNT=42\nNEGATIVE=-10" + result = converter.loads(data) + assert result == {"COUNT": 42, "NEGATIVE": -10} + + def test_loads_float_strings(self, converter): + data = "RATE=3.14" + result = converter.loads(data) + assert result == {"RATE": 3.14} + + def test_loads_array_strings(self, converter): + data = "TAGS=a,b,c" + result = converter.loads(data) + assert result["TAGS"] == "a,b,c" + + def test_loads_empty_value(self, converter): + data = "EMPTY=" + result = converter.loads(data) + assert result["EMPTY"] == "" or result["EMPTY"] is None + + def test_loads_quoted_value(self, converter): + data = 'NAME="quoted value"' + result = converter.loads(data) + assert result["NAME"] == "quoted value" + + def test_skips_comments(self, converter): + data = "# This is a comment\nNAME=test" + result = converter.loads(data) + assert result == {"NAME": "test"} + + def test_skips_empty_lines(self, converter): + data = "NAME=test\n\nVALUE=123" + result = converter.loads(data) + assert result == {"NAME": "test", "VALUE": 123} + + def test_dumps_basic_dict(self, converter): + data = {"NAME": "test", "VALUE": 123} + result = converter.dumps(data) + assert "NAME=test" in result + + def test_dumps_boolean(self, converter): + data = {"ENABLED": True, "DISABLED": False} + result = converter.dumps(data) + assert "ENABLED=true" in result + assert "DISABLED=false" in result + + def test_dumps_list(self, converter): + data = {"TAGS": ["a", "b", "c"]} + result = converter.dumps(data) + assert "TAGS=a,b,c" in result + + def test_roundtrip(self, converter): + original = {"NAME": "test", "ENABLED": True, "COUNT": 42} + dumped = converter.dumps(original) + loaded = converter.loads(dumped) + assert loaded["NAME"] == "test" + assert loaded["ENABLED"] is True + assert loaded["COUNT"] == 42 + + def test_load_file(self, converter, temp_file, sample_env): + gen = temp_file(sample_env, suffix=".env") + 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_env): + import shutil + path = tempfile.mktemp(suffix=".env") + try: + data = converter.loads(sample_env) + converter.dump(data, path) + result = converter.load(path) + assert result == data + finally: + if Path(path).exists(): + os.unlink(path) + + def test_invalid_env_raises(self, converter): + with pytest.raises(ValueError): + converter.loads("invalid line without equals") + + def test_invalid_env_with_space(self, converter): + with pytest.raises(ValueError): + converter.loads("NAME test")