Skip to content

Commit e893c05

Browse files
committed
tmp
1 parent 5be2e08 commit e893c05

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed

docs/examples/usage/conftest.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1-
pytest_plugins = ["pytest_databases.docker.postgres", "pytest_databases.docker.mysql", "pytest_databases.docker.oracle"]
1+
pytest_plugins = ["pytest_databases.docker.postgres", "pytest_databases.docker.mysql",
2+
"pytest_databases.docker.oracle", "pytest_databases.docker.bigquery"]
3+
4+
from collections.abc import Generator
5+
from typing import Any
6+
7+
import pytest
8+
from google.api_core.client_options import ClientOptions
9+
from google.auth.credentials import AnonymousCredentials
10+
from pytest_databases.docker.bigquery import BigQueryService
11+
12+
from sqlspec.adapters.bigquery.config import BigQueryConfig
13+
from sqlspec.adapters.bigquery.driver import BigQueryDriver
14+
15+
16+
@pytest.fixture
17+
def table_schema_prefix(bigquery_service: "BigQueryService") -> str:
18+
"""Create a table schema prefix."""
19+
return f"`{bigquery_service.project}`.`{bigquery_service.dataset}`"
20+
21+
22+
@pytest.fixture
23+
def bigquery_config(bigquery_service: "BigQueryService", table_schema_prefix: str) -> BigQueryConfig:
24+
"""Create a BigQuery config object."""
25+
return BigQueryConfig(
26+
connection_config={
27+
"project": bigquery_service.project,
28+
"dataset_id": table_schema_prefix,
29+
"client_options": ClientOptions(api_endpoint=f"http://{bigquery_service.host}:{bigquery_service.port}"),
30+
"credentials": AnonymousCredentials(), # type: ignore[no-untyped-call]
31+
}
32+
)
33+
34+
35+
@pytest.fixture
36+
def bigquery_session(bigquery_config: BigQueryConfig) -> Generator[BigQueryDriver, Any, None]:
37+
"""Create a BigQuery sync session."""
38+
39+
with bigquery_config.provide_session() as session:
40+
yield session
41+
Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
11
# Test module converted from docs example - code-block 12
22
"""Minimal smoke test for drivers_and_querying example 12."""
33

4-
from sqlspec.adapters.bigquery import BigQueryConfig
54

5+
from sqlspec.adapters.bigquery import BigQueryDriver
66

7-
def test_example_12_bigquery_config() -> None:
8-
config = BigQueryConfig(pool_config={"project": "my-project", "credentials": None})
9-
assert config.pool_config["project"] == "my-project"
7+
8+
def test_example_12_bigquery_config(bigquery_session: BigQueryDriver) -> None:
9+
10+
11+
from sqlspec import SQLSpec
12+
spec = SQLSpec()
13+
14+
result = bigquery_session.execute("SELECT 1 AS value")
15+
16+
# Create the test table
17+
18+
create_table_query = """
19+
CREATE TABLE events (
20+
timestamp TIMESTAMP,
21+
event_type STRING
22+
)
23+
"""
24+
bigquery_session.execute_script(create_table_query)
25+
26+
result = bigquery_session.execute("""
27+
SELECT DATE(timestamp) as date,
28+
COUNT(*) as events
29+
FROM events
30+
WHERE timestamp >= @start_date
31+
GROUP BY date
32+
""", start_date=datetime.date(2025, 1, 1))

0 commit comments

Comments
 (0)