|
12 | 12 | from fsspec.implementations.local import LocalFileSystem |
13 | 13 | from fsspec.registry import register_implementation, _registry |
14 | 14 |
|
| 15 | +from azure.storage.blob import BlobServiceClient |
| 16 | + |
15 | 17 | import fsspec |
16 | 18 |
|
17 | 19 | from .utils import posixify |
@@ -334,3 +336,62 @@ def webdav_fixture(local_testdir, webdav_server): |
334 | 336 | shutil.rmtree(webdav_path) |
335 | 337 | shutil.copytree(local_testdir, webdav_path) |
336 | 338 | yield webdav_url |
| 339 | + |
| 340 | + |
| 341 | +@pytest.fixture(scope="session") |
| 342 | +def azurite_credentials(): |
| 343 | + url = "http://localhost:10000" |
| 344 | + account_name = "devstoreaccount1" |
| 345 | + key = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" # noqa: E501 |
| 346 | + endpoint = f"{url}/{account_name}" |
| 347 | + connection_string = f"DefaultEndpointsProtocol=http;AccountName={account_name};AccountKey={key};BlobEndpoint={endpoint};" # noqa |
| 348 | + |
| 349 | + yield account_name, connection_string |
| 350 | + |
| 351 | + |
| 352 | +@pytest.fixture(scope="session") |
| 353 | +def docker_azurite(azurite_credentials): |
| 354 | + requests = pytest.importorskip("requests") |
| 355 | + |
| 356 | + image = "mcr.microsoft.com/azure-storage/azurite" |
| 357 | + container_name = "azure_test" |
| 358 | + cmd = ( |
| 359 | + f"docker run --rm -d -p 10000:10000 --name {container_name} {image}" # noqa: E501 |
| 360 | + " azurite-blob --loose --blobHost 0.0.0.0" # noqa: E501 |
| 361 | + ) |
| 362 | + url = "http://localhost:10000" |
| 363 | + |
| 364 | + stop_docker(container_name) |
| 365 | + subprocess.run(shlex.split(cmd), check=True) |
| 366 | + |
| 367 | + retries = 10 |
| 368 | + while True: |
| 369 | + try: |
| 370 | + # wait until the container is up, even a 400 status code is ok |
| 371 | + r = requests.get(url, timeout=10) |
| 372 | + if ( |
| 373 | + r.status_code == 400 |
| 374 | + and "Server" in r.headers |
| 375 | + and "Azurite" in r.headers["Server"] |
| 376 | + ): |
| 377 | + yield url |
| 378 | + break |
| 379 | + except Exception as e: # noqa: E722 |
| 380 | + retries -= 1 |
| 381 | + if retries < 0: |
| 382 | + raise SystemError from e |
| 383 | + time.sleep(1) |
| 384 | + |
| 385 | + stop_docker(container_name) |
| 386 | + |
| 387 | + |
| 388 | +@pytest.fixture(scope="session") |
| 389 | +def azure_fixture(azurite_credentials, docker_azurite): |
| 390 | + account_name, connection_string = azurite_credentials |
| 391 | + client = BlobServiceClient.from_connection_string( |
| 392 | + conn_str=connection_string |
| 393 | + ) |
| 394 | + container_name = "data" |
| 395 | + client.create_container(container_name) |
| 396 | + |
| 397 | + yield f"az://{container_name}" |
0 commit comments