|
2 | 2 | import os |
3 | 3 | import tempfile |
4 | 4 | from unittest import mock |
5 | | -from unittest.mock import patch |
6 | 5 |
|
7 | 6 | import azure.storage.blob.aio |
8 | 7 | import dask.dataframe as dd |
9 | 8 | import fsspec |
10 | 9 | import numpy as np |
11 | 10 | import pandas as pd |
12 | 11 | import pytest |
13 | | -from azure.storage.blob.aio import BlobServiceClient as AIOBlobServiceClient |
14 | 12 | from packaging.version import parse as parse_version |
15 | 13 | from pandas.testing import assert_frame_equal |
16 | 14 |
|
@@ -2047,100 +2045,3 @@ def test_open_file_x(storage: azure.storage.blob.BlobServiceClient, tmpdir): |
2047 | 2045 | with fs.open("data/afile", "xb") as f: |
2048 | 2046 | pass |
2049 | 2047 | assert fs.cat_file("data/afile") == b"data" |
2050 | | - |
2051 | | - |
2052 | | -def test_user_agent_blob_file_connection_str( |
2053 | | - storage: azure.storage.blob.BlobServiceClient, mocker |
2054 | | -): |
2055 | | - from adlfs import __version__ |
2056 | | - |
2057 | | - fs = AzureBlobFileSystem( |
2058 | | - account_name=storage.account_name, connection_string=CONN_STR |
2059 | | - ) |
2060 | | - mock_client = mocker.patch.object( |
2061 | | - AIOBlobServiceClient, "from_connection_string", return_value=mocker.MagicMock() |
2062 | | - ) |
2063 | | - mock_client.return_value.get_container_client = mocker.MagicMock() |
2064 | | - |
2065 | | - f = AzureBlobFile(fs, "data/root/a/file.txt", mode="rb") |
2066 | | - f.container_name = "data" |
2067 | | - f.connect_client() |
2068 | | - |
2069 | | - mock_client.assert_called_once() |
2070 | | - assert "user_agent" in mock_client.call_args.kwargs |
2071 | | - assert mock_client.call_args.kwargs["user_agent"] == f"adlfs/{__version__}" |
2072 | | - |
2073 | | - |
2074 | | -def test_user_agent_blob_file_initializer( |
2075 | | - storage: azure.storage.blob.BlobServiceClient, mocker |
2076 | | -): |
2077 | | - from adlfs import __version__ |
2078 | | - |
2079 | | - path = "root/a/file.txt" |
2080 | | - mocker.patch("adlfs.spec.filter_blobs", []) |
2081 | | - |
2082 | | - mock_details = mocker.PropertyMock( |
2083 | | - return_value={ |
2084 | | - "name": path, |
2085 | | - "metadata": {}, |
2086 | | - "size": 0, |
2087 | | - "content_settings": {"content_type": ""}, |
2088 | | - } |
2089 | | - ) |
2090 | | - mocker.patch.object(AzureBlobFile, "details", mock_details) |
2091 | | - mock_client = mocker.patch("adlfs.spec.AIOBlobServiceClient", spec=True) |
2092 | | - |
2093 | | - mock_container_client = mocker.MagicMock() |
2094 | | - mock_blob_client = mocker.MagicMock() |
2095 | | - mock_blob_client.get_blob_properties = mocker.AsyncMock(return_value={}) |
2096 | | - mock_blob_client.__aenter__ = mocker.AsyncMock(return_value=mock_blob_client) |
2097 | | - mock_blob_client.__aexit__ = mocker.AsyncMock() |
2098 | | - mock_blob_client.close = mocker.AsyncMock() |
2099 | | - mock_container_client.get_blob_client = mocker.MagicMock( |
2100 | | - return_value=mock_blob_client |
2101 | | - ) |
2102 | | - mock_client.return_value.get_container_client = mocker.MagicMock( |
2103 | | - return_value=mock_container_client |
2104 | | - ) |
2105 | | - |
2106 | | - fs = AzureBlobFileSystem( |
2107 | | - account_name=storage.account_name, |
2108 | | - ) |
2109 | | - AzureBlobFile(fs, "data/root/a/file.txt", mode="rb") |
2110 | | - |
2111 | | - mock_client.assert_called_once() |
2112 | | - assert "user_agent" in mock_client.call_args.kwargs |
2113 | | - assert mock_client.call_args.kwargs["user_agent"] == f"adlfs/{__version__}" |
2114 | | - |
2115 | | - |
2116 | | -@patch("adlfs.spec.AIOBlobServiceClient") |
2117 | | -def test_user_agent_connection_str( |
2118 | | - storage: azure.storage.blob.BlobServiceClient, mocker |
2119 | | -): |
2120 | | - from adlfs import __version__ |
2121 | | - |
2122 | | - mock_client_instance = mocker.MagicMock() |
2123 | | - mock_client_instance.close = mocker.AsyncMock() |
2124 | | - mock_client = mocker.patch( |
2125 | | - "adlfs.spec.AIOBlobServiceClient.from_connection_string", |
2126 | | - return_value=mock_client_instance, |
2127 | | - ) |
2128 | | - |
2129 | | - AzureBlobFileSystem(account_name=storage.account_name, connection_string=CONN_STR) |
2130 | | - mock_client.assert_called_once() |
2131 | | - assert "user_agent" in mock_client.call_args.kwargs |
2132 | | - assert mock_client.call_args.kwargs["user_agent"] == f"adlfs/{__version__}" |
2133 | | - |
2134 | | - |
2135 | | -def test_user_agent_initializer(storage: azure.storage.blob.BlobServiceClient, mocker): |
2136 | | - from adlfs import __version__ |
2137 | | - |
2138 | | - fs = AzureBlobFileSystem( |
2139 | | - account_name=storage.account_name, |
2140 | | - ) |
2141 | | - mock_client = mocker.patch("adlfs.spec.AIOBlobServiceClient", spec=True) |
2142 | | - |
2143 | | - fs.do_connect() |
2144 | | - mock_client.assert_called_once() |
2145 | | - assert "user_agent" in mock_client.call_args.kwargs |
2146 | | - assert mock_client.call_args.kwargs["user_agent"] == f"adlfs/{__version__}" |
0 commit comments