|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 |
|
5 | | -from sidemantic.db.postgres import PostgreSQLAdapter |
6 | 5 |
|
7 | | - |
8 | | -def test_postgres_adapter_missing_dependency(): |
9 | | - """Test that missing psycopg raises helpful error.""" |
10 | | - # This will fail if psycopg is not installed |
11 | | - # We test the error message is helpful |
| 6 | +def test_postgres_adapter_import(): |
| 7 | + """Test that PostgreSQL adapter can be imported.""" |
12 | 8 | try: |
13 | | - PostgreSQLAdapter() |
| 9 | + from sidemantic.db.postgres import PostgreSQLAdapter |
| 10 | + |
| 11 | + assert hasattr(PostgreSQLAdapter, "from_url") |
| 12 | + assert hasattr(PostgreSQLAdapter, "execute") |
14 | 13 | except ImportError as e: |
| 14 | + # If psycopg is not installed, should get helpful error |
15 | 15 | assert "psycopg" in str(e).lower() |
16 | | - assert "sidemantic[postgres]" in str(e) or "psycopg[binary]" in str(e) |
17 | 16 |
|
18 | 17 |
|
19 | | -def test_postgres_adapter_from_url_parsing(): |
20 | | - """Test URL parsing (without actually connecting).""" |
21 | | - # Just verify the from_url method exists and accepts the URL format |
22 | | - # It will fail on connection but that's ok for this test |
| 18 | +def test_postgres_url_parsing(): |
| 19 | + """Test URL parsing logic (without connecting).""" |
| 20 | + try: |
| 21 | + from sidemantic.db.postgres import PostgreSQLAdapter |
| 22 | + except ImportError: |
| 23 | + pytest.skip("psycopg not installed") |
| 24 | + |
| 25 | + # Test that from_url method exists |
23 | 26 | assert hasattr(PostgreSQLAdapter, "from_url") |
| 27 | + # URL parsing is tested in integration tests where we can actually connect |
24 | 28 |
|
25 | 29 |
|
26 | 30 | @pytest.mark.skipif(True, reason="Requires running PostgreSQL instance") |
27 | 31 | def test_postgres_adapter_execute(): |
28 | 32 | """Test executing queries against real Postgres. |
29 | 33 |
|
30 | 34 | This test is skipped by default since it requires a running Postgres instance. |
31 | | - To run: pytest -v --run-postgres tests/db/test_postgres_adapter.py |
| 35 | + Use integration tests instead. |
32 | 36 | """ |
| 37 | + from sidemantic.db.postgres import PostgreSQLAdapter |
| 38 | + |
33 | 39 | adapter = PostgreSQLAdapter(host="localhost", database="test") |
34 | 40 | result = adapter.execute("SELECT 1 as x, 2 as y") |
35 | 41 | row = result.fetchone() |
|
0 commit comments