|
42 | 42 | Generator, |
43 | 43 | List, |
44 | 44 | Optional, |
| 45 | + Tuple, |
45 | 46 | ) |
46 | 47 |
|
47 | 48 | import boto3 |
|
53 | 54 | from pyiceberg.catalog.noop import NoopCatalog |
54 | 55 | from pyiceberg.expressions import BoundReference |
55 | 56 | from pyiceberg.io import ( |
| 57 | + ADLS_ACCOUNT_NAME, |
| 58 | + ADLS_CONNECTION_STRING, |
56 | 59 | GCS_PROJECT_ID, |
57 | 60 | GCS_SERVICE_HOST, |
58 | 61 | GCS_TOKEN, |
59 | 62 | GCS_TOKEN_EXPIRES_AT_MS, |
| 63 | + FileIO, |
60 | 64 | fsspec, |
61 | 65 | load_file_io, |
62 | 66 | ) |
|
90 | 94 |
|
91 | 95 | if TYPE_CHECKING: |
92 | 96 | import pyarrow as pa |
| 97 | + from azure.storage.blob import BlobServiceClient |
93 | 98 | from moto.server import ThreadedMotoServer # type: ignore |
94 | 99 | from pyspark.sql import SparkSession |
95 | 100 |
|
@@ -2077,24 +2082,54 @@ def fixture_dynamodb(_aws_credentials: None) -> Generator[boto3.client, None, No |
2077 | 2082 | yield boto3.client("dynamodb", region_name="us-east-1") |
2078 | 2083 |
|
2079 | 2084 |
|
2080 | | -@pytest.fixture |
2081 | | -def adls_fsspec_fileio(request: pytest.FixtureRequest) -> Generator[FsspecFileIO, None, None]: |
2082 | | - from azure.storage.blob import BlobServiceClient |
2083 | | - |
| 2085 | +def _get_account_name_and_connection_string(request: pytest.FixtureRequest) -> Tuple[str, str]: |
2084 | 2086 | azurite_url = request.config.getoption("--adls.endpoint") |
2085 | 2087 | azurite_account_name = request.config.getoption("--adls.account-name") |
2086 | 2088 | azurite_account_key = request.config.getoption("--adls.account-key") |
2087 | 2089 | azurite_connection_string = f"DefaultEndpointsProtocol=http;AccountName={azurite_account_name};AccountKey={azurite_account_key};BlobEndpoint={azurite_url}/{azurite_account_name};" |
2088 | | - properties = { |
2089 | | - "adls.connection-string": azurite_connection_string, |
2090 | | - "adls.account-name": azurite_account_name, |
2091 | | - } |
| 2090 | + |
| 2091 | + return azurite_account_name, azurite_connection_string |
| 2092 | + |
| 2093 | + |
| 2094 | +def _setup_blob(azurite_connection_string: str) -> "BlobServiceClient": |
| 2095 | + from azure.storage.blob import BlobServiceClient |
2092 | 2096 |
|
2093 | 2097 | bbs = BlobServiceClient.from_connection_string(conn_str=azurite_connection_string) |
| 2098 | + |
| 2099 | + # Recreate container if needed |
| 2100 | + if list(bbs.list_containers(name_starts_with="tests")): |
| 2101 | + bbs.delete_container("tests") |
2094 | 2102 | bbs.create_container("tests") |
2095 | | - yield fsspec.FsspecFileIO(properties=properties) |
2096 | | - bbs.delete_container("tests") |
2097 | | - bbs.close() |
| 2103 | + |
| 2104 | + return bbs |
| 2105 | + |
| 2106 | + |
| 2107 | +@pytest.fixture |
| 2108 | +def adls_fsspec_fileio(request: pytest.FixtureRequest) -> Generator[FileIO, None, None]: |
| 2109 | + azurite_account_name, azurite_connection_string = _get_account_name_and_connection_string(request) |
| 2110 | + |
| 2111 | + with _setup_blob(azurite_connection_string): |
| 2112 | + yield FsspecFileIO( |
| 2113 | + properties={ |
| 2114 | + ADLS_CONNECTION_STRING: azurite_connection_string, |
| 2115 | + ADLS_ACCOUNT_NAME: azurite_account_name, |
| 2116 | + } |
| 2117 | + ) |
| 2118 | + |
| 2119 | + |
| 2120 | +@pytest.fixture |
| 2121 | +def adls_pyarrow_fileio(request: pytest.FixtureRequest) -> Generator[FileIO, None, None]: |
| 2122 | + from pyiceberg.io.pyarrow import PyArrowFileIO |
| 2123 | + |
| 2124 | + azurite_account_name, azurite_connection_string = _get_account_name_and_connection_string(request) |
| 2125 | + |
| 2126 | + with _setup_blob(azurite_connection_string): |
| 2127 | + yield PyArrowFileIO( |
| 2128 | + properties={ |
| 2129 | + ADLS_CONNECTION_STRING: azurite_connection_string, |
| 2130 | + ADLS_ACCOUNT_NAME: azurite_account_name, |
| 2131 | + } |
| 2132 | + ) |
2098 | 2133 |
|
2099 | 2134 |
|
2100 | 2135 | @pytest.fixture(scope="session") |
|
0 commit comments