Skip to content

Commit a41b4fb

Browse files
authored
Merge pull request openwallet-foundation#3338 from didx-xyz/fix-deprecations
🎨 Fix current test warnings
2 parents b7d27fa + d84a384 commit a41b4fb

File tree

16 files changed

+441
-460
lines changed

16 files changed

+441
-460
lines changed

acapy_agent/anoncreds/tests/test_revocation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,6 @@ async def test_create_credential_w3c(self, mock_supports_revocation):
14141414
assert isinstance(result, tuple)
14151415
assert mock_supports_revocation.call_count == 1
14161416

1417-
@pytest.mark.asyncio
14181417
@mock.patch.object(AskarAnoncredsProfileSession, "handle")
14191418
async def test_create_credential_w3c_keyerror(self, mock_handle):
14201419
mock_handle.fetch = mock.CoroutineMock(side_effect=[MockEntry(), MockEntry()])

acapy_agent/config/logging/configurator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def load_resource(path: str, encoding: Optional[str] = None):
5252
else:
5353
# Package resource
5454
package, resource = components
55-
bstream = resources.open_binary(package, resource)
55+
bstream = resources.files(package).joinpath(resource).open("rb")
5656
if encoding:
5757
return io.TextIOWrapper(bstream, encoding=encoding)
5858
return bstream

acapy_agent/config/tests/test_logging.py

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import contextlib
2-
from io import StringIO
2+
from io import BufferedReader, StringIO, TextIOWrapper
33
from tempfile import NamedTemporaryFile
44
from unittest import IsolatedAsyncioTestCase, mock
55

@@ -110,24 +110,55 @@ def test_banner_did(self):
110110
def test_load_resource(self):
111111
# Testing local file access
112112
with mock.patch("builtins.open", mock.MagicMock()) as mock_open:
113-
test_module.load_resource("abc", encoding="utf-8")
113+
# First call succeeds
114+
file_handle = mock.MagicMock(spec=TextIOWrapper)
115+
mock_open.return_value = file_handle
116+
result = test_module.load_resource("abc", encoding="utf-8")
117+
mock_open.assert_called_once_with("abc", encoding="utf-8")
118+
assert result == file_handle # Verify the returned file handle
119+
120+
mock_open.reset_mock()
121+
# Simulate IOError on second call
114122
mock_open.side_effect = IOError("insufficient privilege")
115123
# load_resource should absorb IOError
116-
test_module.load_resource("abc", encoding="utf-8")
124+
result = test_module.load_resource("abc", encoding="utf-8")
125+
mock_open.assert_called_once_with("abc", encoding="utf-8")
126+
assert result is None
117127

118128
# Testing package resource access with encoding (text mode)
119-
with mock.patch(
120-
"importlib.resources.open_binary", mock.MagicMock()
121-
) as mock_open_binary, mock.patch(
129+
with mock.patch("importlib.resources.files") as mock_files, mock.patch(
122130
"io.TextIOWrapper", mock.MagicMock()
123131
) as mock_text_io_wrapper:
124-
test_module.load_resource("abc:def", encoding="utf-8")
125-
mock_open_binary.assert_called_once_with("abc", "def")
126-
mock_text_io_wrapper.assert_called_once()
132+
# Setup the mocks
133+
mock_resource_path = mock.MagicMock()
134+
mock_files.return_value.joinpath.return_value = mock_resource_path
135+
mock_resource_handle = mock.MagicMock(spec=BufferedReader)
136+
mock_resource_path.open.return_value = mock_resource_handle
137+
mock_text_io_wrapper.return_value = mock.MagicMock(spec=TextIOWrapper)
138+
139+
result = test_module.load_resource("abc:def", encoding="utf-8")
140+
141+
# Assertions
142+
mock_files.assert_called_once_with("abc")
143+
mock_files.return_value.joinpath.assert_called_once_with("def")
144+
mock_resource_path.open.assert_called_once_with("rb")
145+
mock_text_io_wrapper.assert_called_once_with(
146+
mock_resource_handle, encoding="utf-8"
147+
)
148+
assert result is mock_text_io_wrapper.return_value
127149

128150
# Testing package resource access without encoding (binary mode)
129-
with mock.patch(
130-
"importlib.resources.open_binary", mock.MagicMock()
131-
) as mock_open_binary:
132-
test_module.load_resource("abc:def", encoding=None)
133-
mock_open_binary.assert_called_once_with("abc", "def")
151+
with mock.patch("importlib.resources.files") as mock_files:
152+
# Setup the mocks
153+
mock_resource_path = mock.MagicMock()
154+
mock_files.return_value.joinpath.return_value = mock_resource_path
155+
mock_resource_handle = mock.MagicMock(spec=BufferedReader)
156+
mock_resource_path.open.return_value = mock_resource_handle
157+
158+
result = test_module.load_resource("abc:def", encoding=None)
159+
160+
# Assertions
161+
mock_files.assert_called_once_with("abc")
162+
mock_files.return_value.joinpath.assert_called_once_with("def")
163+
mock_resource_path.open.assert_called_once_with("rb")
164+
assert result == mock_resource_handle # Verify the returned binary stream

acapy_agent/connections/tests/test_base_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from unittest import IsolatedAsyncioTestCase
44
from unittest.mock import call
55

6+
import pytest
67
from pydid import DID, DIDDocument, DIDDocumentBuilder
78
from pydid.doc.builder import ServiceBuilder
89
from pydid.verification_method import (
@@ -27,9 +28,7 @@
2728
from ...protocols.connections.v1_0.messages.connection_invitation import (
2829
ConnectionInvitation,
2930
)
30-
from ...protocols.coordinate_mediation.v1_0.models.mediation_record import (
31-
MediationRecord,
32-
)
31+
from ...protocols.coordinate_mediation.v1_0.models.mediation_record import MediationRecord
3332
from ...protocols.coordinate_mediation.v1_0.route_manager import (
3433
CoordinateMediationV1RouteManager,
3534
RouteManager,
@@ -1065,6 +1064,7 @@ async def test_resolve_connection_targets_x_bad_key_material(self):
10651064
await self.manager.resolve_connection_targets(did)
10661065
assert "not supported" in str(cm.exception)
10671066

1067+
@pytest.mark.filterwarnings("ignore::UserWarning")
10681068
async def test_resolve_connection_targets_x_unsupported_key(self):
10691069
did = "did:sov:" + self.test_did
10701070
doc_builder = DIDDocumentBuilder(did)

acapy_agent/core/tests/test_conductor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,7 @@ async def test_dispatch_complete_fatal_x(self):
11861186
conductor.dispatch_complete(message, mock_task)
11871187
mock_notify.assert_called_once_with()
11881188

1189+
@pytest.mark.filterwarnings("ignore:Aries RFC 0160.*:DeprecationWarning")
11891190
async def test_print_invite_connection(self):
11901191
builder: ContextBuilder = StubContextBuilder(self.test_settings)
11911192
builder.update_settings(

acapy_agent/didcomm_v2/tests/test_adapters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from ..adapters import ResolverAdapter, SecretsAdapter, SecretsAdapterError
1616

1717

18-
class TestDIDResolver(BaseDIDResolver):
18+
class MockDIDResolver(BaseDIDResolver):
1919
async def setup(self, context: InjectionContext):
2020
return await super().setup(context)
2121

@@ -26,7 +26,7 @@ async def resolve(
2626
self,
2727
profile,
2828
did,
29-
sercive_accept=None,
29+
service_accept=None,
3030
):
3131
return {"did": did, "test": "didDoc"}
3232

@@ -46,7 +46,7 @@ async def asyncSetUp(self):
4646
self.test_did = "did:test:0"
4747
self.invalid_did = "this shouldn't work"
4848
resolver = DIDResolver()
49-
resolver.register_resolver(TestDIDResolver())
49+
resolver.register_resolver(MockDIDResolver())
5050
self.res_adapter = ResolverAdapter(profile=self.profile, resolver=resolver)
5151

5252
async def test_resolver_adapter_resolve_did(self):

acapy_agent/multitenant/admin/tests/test_routes.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from unittest import IsolatedAsyncioTestCase
22

3-
import pytest
43
from marshmallow.exceptions import ValidationError
54

65
from ....admin.request_context import AdminRequestContext
@@ -143,7 +142,6 @@ async def test_wallets_list_query(self):
143142
}
144143
)
145144

146-
@pytest.mark.asyncio(scope="function")
147145
async def test_wallet_create_tenant_settings(self):
148146
body = {
149147
"wallet_name": "test",
@@ -796,7 +794,6 @@ async def test_wallet_create_token_x(self):
796794
)
797795
await test_module.wallet_create_token(self.request)
798796

799-
@pytest.mark.asyncio(scope="function")
800797
async def test_wallet_remove_managed(self):
801798
self.request.has_body = False
802799
self.request.match_info = {"wallet_id": "dummy"}

acapy_agent/protocols/connections/v1_0/tests/test_manager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from unittest import IsolatedAsyncioTestCase
22

3+
import pytest
4+
35
from .....cache.base import BaseCache
46
from .....cache.in_memory import InMemoryCache
57
from .....connections.models.conn_record import ConnRecord
@@ -29,6 +31,7 @@
2931
from ..models.connection_detail import ConnectionDetail
3032

3133

34+
@pytest.mark.filterwarnings("ignore:Aries RFC 0160.*:DeprecationWarning")
3235
class TestConnectionManager(IsolatedAsyncioTestCase):
3336
def make_did_doc(self, did, verkey):
3437
doc = DIDDoc(did=did)

acapy_agent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from unittest import IsolatedAsyncioTestCase
22

3-
import pytest
4-
53
from ......connections.models import connection_target
64
from ......connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service
75
from ......messaging.decorators.attach_decorator import AttachDecorator
@@ -75,7 +73,6 @@ async def asyncSetUp(self):
7573
did_doc_attach=self.did_doc_attach,
7674
)
7775

78-
@pytest.mark.asyncio(scope="function")
7976
@mock.patch.object(test_module, "DIDXManager")
8077
async def test_called(self, mock_didx_mgr):
8178
mock_didx_mgr.return_value.accept_response = mock.CoroutineMock()
@@ -89,7 +86,6 @@ async def test_called(self, mock_didx_mgr):
8986
)
9087
assert not responder.messages
9188

92-
@pytest.mark.asyncio(scope="function")
9389
@mock.patch.object(test_module, "DIDXManager")
9490
async def test_called_auto_ping(self, mock_didx_mgr):
9591
self.ctx.update_settings({"auto_ping_connection": True})
@@ -107,7 +103,6 @@ async def test_called_auto_ping(self, mock_didx_mgr):
107103
result, _ = messages[0]
108104
assert isinstance(result, Ping)
109105

110-
@pytest.mark.asyncio(scope="function")
111106
@mock.patch.object(test_module, "DIDXManager")
112107
@mock.patch.object(connection_target, "ConnectionTarget")
113108
async def test_problem_report(self, mock_conn_target, mock_didx_mgr):
@@ -144,7 +139,6 @@ async def test_problem_report(self, mock_conn_target, mock_didx_mgr):
144139
)
145140
assert target == {"target_list": [mock_conn_target]}
146141

147-
@pytest.mark.asyncio(scope="function")
148142
@mock.patch.object(test_module, "DIDXManager")
149143
@mock.patch.object(connection_target, "ConnectionTarget")
150144
async def test_problem_report_did_doc(
@@ -191,7 +185,6 @@ async def test_problem_report_did_doc(
191185
)
192186
assert target == {"target_list": [mock_conn_target]}
193187

194-
@pytest.mark.asyncio(scope="function")
195188
@mock.patch.object(test_module, "DIDXManager")
196189
@mock.patch.object(connection_target, "ConnectionTarget")
197190
async def test_problem_report_did_doc_no_conn_target(

acapy_agent/protocols/issue_credential/v2_0/formats/vc_di/tests/test_handler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,6 @@ async def test_issue_credential_non_revocable(self):
727727
# assert data is encoded as base64
728728
assert attachment.data.base64
729729

730-
@pytest.mark.asyncio
731730
async def test_match_sent_cred_def_id_error(self):
732731
tag_query = {"tag": "test_tag"}
733732

@@ -737,7 +736,6 @@ async def test_match_sent_cred_def_id_error(self):
737736
context.exception
738737
)
739738

740-
@pytest.mark.asyncio
741739
async def test_store_credential(self):
742740
attr_values = {
743741
"legalName": "value",

0 commit comments

Comments
 (0)