Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit eaef0fb

Browse files
committed
fixing tests
1 parent b4fb17b commit eaef0fb

7 files changed

Lines changed: 59 additions & 33 deletions

File tree

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
# aiohttp < 3.10.0 which is a bug. Investigate and remove the pinned aiohttp version.
7878
"aiohttp < 3.10.0",
7979
"mock; python_version < '3.8'",
80+
"asyncmock; python_version < '3.8'",
8081
"freezegun",
8182
]
8283

tests/test__exponential_backoff.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from unittest import mock
16-
try:
15+
import sys
16+
if sys.version_info >= (3, 8):
17+
from unittest import mock
1718
from unittest.mock import AsyncMock
18-
except ImportError:
19-
# Fallback for Python < 3.8
20-
from mock import AsyncMock
19+
else:
20+
import mock
21+
22+
try:
23+
from mock import AsyncMock
24+
except ImportError:
25+
from asyncmock import AsyncMock
2126

2227
import pytest # type: ignore
2328

@@ -100,4 +105,4 @@ def test_minimum_total_attempts_async():
100105
_exponential_backoff.AsyncExponentialBackoff(total_attempts=0)
101106
with pytest.raises(exceptions.InvalidValue):
102107
_exponential_backoff.AsyncExponentialBackoff(total_attempts=-1)
103-
_exponential_backoff.AsyncExponentialBackoff(total_attempts=1)
108+
_exponential_backoff.AsyncExponentialBackoff(total_attempts=1)

tests_async/oauth2/test__client_async.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@
1515
import datetime
1616
import http.client as http_client
1717
import json
18-
from unittest import mock
19-
try:
20-
from unittest.mock import AsyncMock
21-
except ImportError:
22-
# Fallback for Python < 3.8
23-
from mock import AsyncMock
18+
import sys
2419
import urllib
2520

21+
if sys.version_info >= (3, 8):
22+
from unittest import mock
23+
from unittest.mock import AsyncMock
24+
else:
25+
import mock
26+
27+
try:
28+
from mock import AsyncMock
29+
except ImportError:
30+
from asyncmock import AsyncMock
31+
2632
import freezegun
2733
import pytest # type: ignore
2834

tests_async/oauth2/test_credentials_async.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
import os
1818
import pickle
1919
import sys
20-
from unittest import mock
21-
try:
20+
if sys.version_info >= (3, 8):
21+
from unittest import mock
2222
from unittest.mock import AsyncMock
23-
except ImportError:
24-
# Fallback for Python < 3.8
25-
from mock import AsyncMock
23+
else:
24+
import mock
25+
try:
26+
from mock import AsyncMock
27+
except ImportError:
28+
from asyncmock import AsyncMock
2629

2730
import pytest # type: ignore
2831

tests_async/oauth2/test_id_token.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
import json
1616
import os
17-
from unittest import mock
18-
try:
17+
import sys
18+
if sys.version_info >= (3, 8):
19+
from unittest import mock
1920
from unittest.mock import AsyncMock
20-
except ImportError:
21-
# Fallback for Python < 3.8
21+
else:
22+
import mock
2223
from mock import AsyncMock
2324

2425
import pytest # type: ignore

tests_async/oauth2/test_service_account_async.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313
# limitations under the License.
1414

1515
import datetime
16-
from unittest import mock
17-
try:
16+
import sys
17+
if sys.version_info >= (3, 8):
18+
from unittest import mock
1819
from unittest.mock import AsyncMock
19-
except ImportError:
20-
# Fallback for Python < 3.8
21-
from mock import AsyncMock
20+
else:
21+
import mock
22+
try:
23+
from mock import AsyncMock
24+
except ImportError:
25+
from asyncmock import AsyncMock
2226

2327
import pytest # type: ignore
2428

tests_async/transport/test_aiohttp_requests.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from unittest import mock
16-
try:
15+
import sys
16+
if sys.version_info >= (3, 8):
17+
from unittest import mock
1718
from unittest.mock import AsyncMock
18-
except ImportError:
19-
from mock import AsyncMock
19+
else:
20+
import mock
21+
22+
try:
23+
from mock import AsyncMock
24+
except ImportError:
25+
from asyncmock import AsyncMock
2026

2127
import aiohttp # type: ignore
2228
from aioresponses import aioresponses, core # type: ignore
@@ -44,7 +50,7 @@ def test__is_compressed_not(self):
4450

4551
@pytest.mark.asyncio
4652
async def test_raw_content(self):
47-
mock_response = mock.AsyncMock()
53+
mock_response = AsyncMock()
4854
mock_response.content.read.return_value = mock.sentinel.read
4955
combined_response = aiohttp_requests._CombinedResponse(response=mock_response)
5056
raw_content = await combined_response.raw_content()
@@ -57,7 +63,7 @@ async def test_raw_content(self):
5763

5864
@pytest.mark.asyncio
5965
async def test_content(self):
60-
mock_response = mock.AsyncMock()
66+
mock_response = AsyncMock()
6167
mock_response.content.read.return_value = mock.sentinel.read
6268
combined_response = aiohttp_requests._CombinedResponse(response=mock_response)
6369
content = await combined_response.content()
@@ -104,7 +110,7 @@ async def test_status_prop(self):
104110

105111
@pytest.mark.asyncio
106112
async def test_data_prop(self):
107-
mock_response = mock.AsyncMock()
113+
mock_response = AsyncMock()
108114
mock_response.content.read.return_value = mock.sentinel.read
109115
response = aiohttp_requests._Response(mock_response)
110116
data = await response.data.read()

0 commit comments

Comments
 (0)