diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e93a00c..c975c55 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,14 +8,14 @@ Thanks for your interest in contributing! 2. Create a virtual environment: python -m venv .venv && source .venv/bin/activate 3. Install dev dependencies: pip install -e ".[dev]" 4. Run tests: pytest tests/ -v -5. Lint: uff check src/ +5. Lint: `ruff check src/` ## Pull Requests - Fork the repo and create a feature branch - Add tests for any new functionality - Ensure all existing tests pass -- Run uff check src/ --fix before committing +- Run `ruff check src/ --fix` before committing - Keep PRs focused on a single change ## Reporting Issues diff --git a/src/json2sql/__pycache__/__init__.cpython-312.pyc b/src/json2sql/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index d74d106..0000000 Binary files a/src/json2sql/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/src/json2sql/__pycache__/__init__.cpython-314.pyc b/src/json2sql/__pycache__/__init__.cpython-314.pyc deleted file mode 100644 index 53328d5..0000000 Binary files a/src/json2sql/__pycache__/__init__.cpython-314.pyc and /dev/null differ diff --git a/src/json2sql/__pycache__/cli.cpython-312.pyc b/src/json2sql/__pycache__/cli.cpython-312.pyc deleted file mode 100644 index 3499064..0000000 Binary files a/src/json2sql/__pycache__/cli.cpython-312.pyc and /dev/null differ diff --git a/src/json2sql/__pycache__/cli.cpython-314.pyc b/src/json2sql/__pycache__/cli.cpython-314.pyc deleted file mode 100644 index 700dfef..0000000 Binary files a/src/json2sql/__pycache__/cli.cpython-314.pyc and /dev/null differ diff --git a/src/json2sql/__pycache__/converter.cpython-312.pyc b/src/json2sql/__pycache__/converter.cpython-312.pyc deleted file mode 100644 index a5b1d3b..0000000 Binary files a/src/json2sql/__pycache__/converter.cpython-312.pyc and /dev/null differ diff --git a/src/json2sql/__pycache__/converter.cpython-314.pyc b/src/json2sql/__pycache__/converter.cpython-314.pyc deleted file mode 100644 index 16dd35d..0000000 Binary files a/src/json2sql/__pycache__/converter.cpython-314.pyc and /dev/null differ diff --git a/src/json2sql/__pycache__/dialects.cpython-312.pyc b/src/json2sql/__pycache__/dialects.cpython-312.pyc deleted file mode 100644 index 52001fb..0000000 Binary files a/src/json2sql/__pycache__/dialects.cpython-312.pyc and /dev/null differ diff --git a/src/json2sql/__pycache__/dialects.cpython-314.pyc b/src/json2sql/__pycache__/dialects.cpython-314.pyc deleted file mode 100644 index 3cf8804..0000000 Binary files a/src/json2sql/__pycache__/dialects.cpython-314.pyc and /dev/null differ diff --git a/tests/__pycache__/test_converter.cpython-312-pytest-9.0.3.pyc b/tests/__pycache__/test_converter.cpython-312-pytest-9.0.3.pyc deleted file mode 100644 index 1b1664f..0000000 Binary files a/tests/__pycache__/test_converter.cpython-312-pytest-9.0.3.pyc and /dev/null differ diff --git a/tests/__pycache__/test_converter.cpython-314-pytest-9.0.3.pyc b/tests/__pycache__/test_converter.cpython-314-pytest-9.0.3.pyc deleted file mode 100644 index b4c0580..0000000 Binary files a/tests/__pycache__/test_converter.cpython-314-pytest-9.0.3.pyc and /dev/null differ diff --git a/tests/test_converter.py b/tests/test_converter.py index 30582c8..174e180 100644 --- a/tests/test_converter.py +++ b/tests/test_converter.py @@ -129,9 +129,59 @@ def test_generate_schema(self, converter_postgres): assert "CREATE TABLE" in result assert "INSERT INTO" not in result + def test_generate_schema_single_object(self, converter_postgres): + """Single dict root generates schema correctly.""" + data = json.dumps({"name": "Alice", "age": 30}) + result = converter_postgres.generate_schema(data, table_name="users") + assert "CREATE TABLE" in result + assert "name" in result + assert "age" in result + assert "INSERT INTO" not in result + + def test_generate_schema_primitive(self, converter_postgres): + """Primitive root type falls back to 'value' column.""" + data = json.dumps("hello") + result = converter_postgres.generate_schema(data, table_name="single") + assert "CREATE TABLE" in result + assert "value" in result + + def test_generate_schema_with_flatten(self): + """Schema generation with flatten=True and nested arrays.""" + conv = JSONToSQLConverter(dialect=Dialect.POSTGRES, flatten=True) + data = json.dumps({ + "id": 1, + "orders": [ + {"product": "Widget", "qty": 3}, + ], + }) + result = conv.generate_schema(data, table_name="users") + assert "CREATE TABLE" in result + # Should create a separate table for nested array + assert "users_orders" in result or "orders" in result + assert "INSERT INTO" not in result + # --- Edge cases --- +class TestUnsupportedRootTypes: + """Tests for behavior with unsupported root JSON types.""" + + def test_convert_string_root_raises(self, converter_postgres): + """A plain string as JSON root raises ValueError.""" + with pytest.raises(ValueError, match="Unsupported JSON root type"): + converter_postgres.convert(json.dumps("just a string"), table_name="t") + + def test_convert_number_root_raises(self, converter_postgres): + """A plain number as JSON root raises ValueError.""" + with pytest.raises(ValueError, match="Unsupported JSON root type"): + converter_postgres.convert(json.dumps(42), table_name="t") + + def test_convert_boolean_root_raises(self, converter_postgres): + """A plain boolean as JSON root raises ValueError.""" + with pytest.raises(ValueError, match="Unsupported JSON root type"): + converter_postgres.convert(json.dumps(True), table_name="t") + + class TestEdgeCases: def test_string_with_quotes(self, converter_postgres): data = json.dumps({"bio": "It's a test"})