Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions python/sedonadb/python/sedonadb/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,24 @@ class BigQuery(DBEngine):
much faster as opening a connection to BigQuery is slow).
"""

_CACHE_DIR = Path(__file__).resolve().parent.parent.parent / "tests" / "geography"
_CACHE_DIR: "Path | None" = None
_shared_cache: "ArrowSQLCache | None" = None

@classmethod
def set_cache_dir(cls, cache_dir: "Path | str") -> None:
"""Set the directory containing bigquery_cache.yml.

Call this before any BigQuery instances are created to configure
where the cache file is located. This is typically called from a
conftest.py in the test directory.
"""
cls._CACHE_DIR = Path(cache_dir)
cls._shared_cache = None # Reset so next instance uses new path

def __init__(self, cache_path: "Path | None" = None):
self._cache_path = cache_path or self._CACHE_DIR / "bigquery_cache.yml"
if cache_path is None and BigQuery._CACHE_DIR is not None:
cache_path = BigQuery._CACHE_DIR / "bigquery_cache.yml"
self._cache_path = cache_path
if cache_path is not None or BigQuery._shared_cache is None:
BigQuery._shared_cache = ArrowSQLCache("bigquery", self._cache_path)
self._file_cache = BigQuery._shared_cache
Expand Down
24 changes: 24 additions & 0 deletions python/sedonadb/tests/geography/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from pathlib import Path
from sedonadb.testing import BigQuery

# Set the BigQuery cache directory based on this file's location.
# This ensures the cache is found when tests run from an installed wheel
# (where the testing.py module's relative path calculation would fail).
BigQuery.set_cache_dir(Path(__file__).resolve().parent)