-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
226ec8b
commit 135bc85
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import os | ||
from collections.abc import Iterator | ||
from typing import BinaryIO | ||
|
||
import pytest | ||
from pytest import MonkeyPatch | ||
|
||
|
||
class ContainerClient: | ||
def __init__(self, account_url: str, container_name: str) -> None: | ||
self.account_url = account_url | ||
self.container_name = container_name | ||
|
||
def list_blob_names(self, name_starts_with: str = "") -> Iterator[str]: | ||
prefix = os.path.join(self.account_url, self.container_name) | ||
for root, dirs, files in os.walk(prefix): | ||
for file in files: | ||
name = os.path.join(root, file).replace(prefix + os.sep, "", 1) | ||
if name.startswith(name_starts_with): | ||
yield name | ||
|
||
def download_blob(self, blob: str) -> BinaryIO: | ||
path = os.path.join(self.account_url, self.container_name, blob) | ||
# TODO: filehandle leak | ||
f = open(path, "rb", buffering=0) | ||
return f | ||
|
||
|
||
@pytest.fixture | ||
def container_client(monkeypatch: MonkeyPatch) -> None: | ||
asb = pytest.importorskip("azure.storage.blob", minversion="12.4") | ||
monkeypatch.setattr(asb, "ContainerClient", ContainerClient) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters