Initial upload: ConfigConvert CLI with full test suite and CI/CD
Some checks failed
CI / test (push) Has been cancelled
CI / lint (push) Has been cancelled

This commit is contained in:
2026-02-04 07:05:32 +00:00
parent 36ee42ea0f
commit 676f949c02

View File

@@ -0,0 +1,78 @@
"""Tests for JSON converter."""
import pytest
import json
import tempfile
import os
from pathlib import Path
from config_convert.converters import JSONConverter
class TestJSONConverter:
@pytest.fixture
def converter(self):
return JSONConverter()
def test_loads_valid_json(self, converter):
data = '{"name": "test", "value": 123}'
result = converter.loads(data)
assert result == {"name": "test", "value": 123}
def test_loads_nested_json(self, converter):
data = '{"database": {"host": "localhost", "port": 5432}}'
result = converter.loads(data)
assert result == {"database": {"host": "localhost", "port": 5432}}
def test_loads_array_json(self, converter):
data = '{"tags": ["a", "b", "c"]}'
result = converter.loads(data)
assert result == {"tags": ["a", "b", "c"]}
def test_dumps_basic_dict(self, converter):
data = {"name": "test", "value": 123}
result = converter.dumps(data)
parsed = json.loads(result)
assert parsed == data
def test_dumps_with_custom_indent(self, converter):
data = {"name": "test"}
result = converter.dumps(data, indent=4)
assert "\n" in result
def test_dumps_nested_dict(self, converter):
data = {"database": {"host": "localhost", "port": 5432}}
result = converter.dumps(data)
parsed = json.loads(result)
assert parsed == data
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_json):
gen = temp_file(json.dumps(sample_json), suffix=".json")
path = next(gen)
try:
result = converter.load(path)
assert result == sample_json
finally:
import os
os.unlink(path)
def test_dump_file(self, converter, temp_dir, sample_json):
import shutil
path = tempfile.mktemp(suffix=".json")
try:
converter.dump(sample_json, path)
result = json.loads(Path(path).read_text())
assert result == sample_json
finally:
if Path(path).exists():
os.unlink(path)
def test_invalid_json_raises(self, converter):
with pytest.raises(json.JSONDecodeError):
converter.loads("{invalid json}")