Skip to content

Commit

Permalink
Merge pull request hyperledger#2755 from ff137/remove-asynctest
Browse files Browse the repository at this point in the history
Remove asynctest dependency and fix "coroutine not awaited" warnings
  • Loading branch information
dbluhm committed Feb 2, 2024
2 parents 563aaa6 + 5c65652 commit 9ed0fd8
Show file tree
Hide file tree
Showing 20 changed files with 294 additions and 295 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ jobs:
pip install poetry
poetry install -E "askar bbs"
- name: Tests
run: poetry run pytest
run: |
poetry run pytest 2>&1 | tee pytest.log
PYTEST_EXIT_CODE=${PIPESTATUS[0]}
if grep -Eq "RuntimeWarning: coroutine .* was never awaited" pytest.log; then
echo "Failure: Detected unawaited coroutine warning in pytest output."
exit 1
fi
exit $PYTEST_EXIT_CODE
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import json
import re
from unittest import IsolatedAsyncioTestCase

import pytest
from asynctest import TestCase
from base58 import alphabet

from aries_cloudagent.anoncreds.base import (
Expand Down Expand Up @@ -64,8 +64,8 @@


@pytest.mark.anoncreds
class TestLegacyIndyRegistry(TestCase):
def setUp(self):
class TestLegacyIndyRegistry(IsolatedAsyncioTestCase):
async def asyncSetUp(self):
self.profile = InMemoryProfile.test_profile(
settings={"wallet-type": "askar-anoncreds"},
profile_class=AskarAnoncredsProfile,
Expand Down
6 changes: 3 additions & 3 deletions aries_cloudagent/anoncreds/tests/test_holder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from copy import deepcopy
from unittest import IsolatedAsyncioTestCase

import anoncreds
import pytest
Expand All @@ -16,7 +17,6 @@
Schema,
)
from aries_askar import AskarError, AskarErrorCode
from asynctest import TestCase

from aries_cloudagent.anoncreds.holder import AnonCredsHolder, AnonCredsHolderError
from aries_cloudagent.anoncreds.tests.mock_objects import (
Expand Down Expand Up @@ -107,8 +107,8 @@ class MockMimeTypeRecord:


@pytest.mark.anoncreds
class TestAnonCredsHolder(TestCase):
def setUp(self) -> None:
class TestAnonCredsHolder(IsolatedAsyncioTestCase):
async def asyncSetUp(self):
self.profile = InMemoryProfile.test_profile(
settings={"wallet-type": "askar-anoncreds"},
profile_class=AskarAnoncredsProfile,
Expand Down
6 changes: 3 additions & 3 deletions aries_cloudagent/anoncreds/tests/test_issuer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from typing import Optional
from unittest import IsolatedAsyncioTestCase

import pytest
from anoncreds import (
Expand All @@ -8,7 +9,6 @@
CredentialOffer,
)
from aries_askar import AskarError, AskarErrorCode
from asynctest import TestCase

from aries_cloudagent.anoncreds.base import (
AnonCredsObjectAlreadyExists,
Expand Down Expand Up @@ -126,8 +126,8 @@ def get_mock_schema_result(


@pytest.mark.anoncreds
class TestAnonCredsIssuer(TestCase):
def setUp(self) -> None:
class TestAnonCredsIssuer(IsolatedAsyncioTestCase):
async def asyncSetUp(self) -> None:
self.profile = InMemoryProfile.test_profile(
settings={"wallet-type": "askar-anoncreds"},
profile_class=AskarAnoncredsProfile,
Expand Down
6 changes: 3 additions & 3 deletions aries_cloudagent/anoncreds/tests/test_revocation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import http
import json
import os
from unittest import IsolatedAsyncioTestCase

import pytest
from anoncreds import (
Expand All @@ -12,7 +13,6 @@
Schema,
)
from aries_askar import AskarError, AskarErrorCode
from asynctest import TestCase
from requests import RequestException, Session

from aries_cloudagent.anoncreds.issuer import AnonCredsIssuer
Expand Down Expand Up @@ -120,8 +120,8 @@ class MockRevListEntry:


@pytest.mark.anoncreds
class TestAnonCredsRevocation(TestCase):
def setUp(self) -> None:
class TestAnonCredsRevocation(IsolatedAsyncioTestCase):
async def asyncSetUp(self) -> None:
self.profile = InMemoryProfile.test_profile(
settings={
"wallet-type": "askar-anoncreds",
Expand Down
6 changes: 3 additions & 3 deletions aries_cloudagent/anoncreds/tests/test_routes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
from unittest import IsolatedAsyncioTestCase

import pytest
from aiohttp import web
from asynctest import TestCase as AsyncTestCase

from aries_cloudagent.admin.request_context import AdminRequestContext
from aries_cloudagent.anoncreds.base import AnonCredsObjectNotFound
Expand Down Expand Up @@ -50,8 +50,8 @@ def serialize(self):


@pytest.mark.anoncreds
class TestAnoncredsRoutes(AsyncTestCase):
async def setUp(self) -> None:
class TestAnoncredsRoutes(IsolatedAsyncioTestCase):
async def asyncSetUp(self) -> None:
self.session_inject = {}
self.profile = InMemoryProfile.test_profile(
settings={"wallet-type": "askar-anoncreds"},
Expand Down
6 changes: 3 additions & 3 deletions aries_cloudagent/anoncreds/tests/test_verifier.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from copy import deepcopy
from unittest import IsolatedAsyncioTestCase

import pytest
from asynctest import TestCase

from aries_cloudagent.anoncreds.models.anoncreds_cred_def import (
CredDef,
Expand Down Expand Up @@ -38,8 +38,8 @@


@pytest.mark.anoncreds
class TestAnonCredsVerifier(TestCase):
def setUp(self) -> None:
class TestAnonCredsVerifier(IsolatedAsyncioTestCase):
async def asyncSetUp(self) -> None:
self.profile = InMemoryProfile.test_profile(
settings={"wallet-type": "askar-anoncreds"},
profile_class=AskarAnoncredsProfile,
Expand Down
31 changes: 25 additions & 6 deletions aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from .....storage.error import StorageNotFoundError
from .....transport.inbound.receipt import MessageReceipt
from .....wallet.did_info import DIDInfo
from .....wallet.did_method import PEER2, SOV, DIDMethods
from .....wallet.did_method import PEER2, PEER4, SOV, DIDMethods
from .....wallet.error import WalletError
from .....wallet.in_memory import InMemoryWallet
from .....wallet.key_type import ED25519
Expand Down Expand Up @@ -554,11 +554,20 @@ async def test_create_request_emit_did_peer_2(self):
my_did=None,
save=mock.CoroutineMock(),
)
mock_did_info = DIDInfo(
TestConfig.test_did_peer_2,
TestConfig.test_verkey,
None,
method=PEER2,
key_type=ED25519,
)

self.profile.context.update_settings({"emit_did_peer_2": True})

with mock.patch.object(
self.manager, "create_did_peer_2", mock.AsyncMock()
self.manager,
"create_did_peer_2",
mock.AsyncMock(return_value=mock_did_info),
) as mock_create_did_peer_2:
request = await self.manager.create_request(
mock_conn_rec, use_public_did=True
Expand All @@ -577,11 +586,20 @@ async def test_create_request_emit_did_peer_4(self):
my_did=None,
save=mock.CoroutineMock(),
)
mock_did_info = DIDInfo(
TestConfig.test_did_peer_4,
TestConfig.test_verkey,
None,
method=PEER4,
key_type=ED25519,
)

self.profile.context.update_settings({"emit_did_peer_4": True})

with mock.patch.object(
self.manager, "create_did_peer_4", mock.AsyncMock()
self.manager,
"create_did_peer_4",
mock.AsyncMock(return_value=mock_did_info),
) as mock_create_did_peer_4:
request = await self.manager.create_request(
mock_conn_rec, use_public_did=True
Expand Down Expand Up @@ -1702,7 +1720,7 @@ async def test_create_response_inkind_peer_did_4(self):
TestConfig.test_did_peer_4,
TestConfig.test_verkey,
None,
method=PEER2,
method=PEER4,
key_type=ED25519,
)
response = await self.manager.create_response(
Expand Down Expand Up @@ -2018,10 +2036,11 @@ async def test_accept_response_find_by_thread_id_bad_state(self):
await self.manager.accept_response(mock_response, receipt)

async def test_accept_response_find_by_thread_id_no_did_doc_attached(self):
mock_response = mock.AsyncMock()
mock_response._thread = mock.AsyncMock()
mock_response = mock.MagicMock()
mock_response._thread = mock.MagicMock()
mock_response.did = TestConfig.test_target_did
mock_response.did_doc_attach = None
mock_response.did_rotate_attach.data.verify = mock.AsyncMock(return_value=True)

receipt = MessageReceipt(
recipient_did=TestConfig.test_did,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest
from time import time

from asynctest import mock as async_mock
from unittest import IsolatedAsyncioTestCase
from aries_cloudagent.tests import mock
from marshmallow import ValidationError
Expand Down Expand Up @@ -228,11 +227,11 @@ async def asyncSetUp(self):
self.context.injector.bind_instance(BaseCache, self.cache)

# Issuer
self.issuer = async_mock.MagicMock(AnonCredsIssuer, autospec=True)
self.issuer = mock.MagicMock(AnonCredsIssuer, autospec=True)
self.context.injector.bind_instance(AnonCredsIssuer, self.issuer)

# Holder
self.holder = async_mock.MagicMock(AnonCredsHolder, autospec=True)
self.holder = mock.MagicMock(AnonCredsHolder, autospec=True)
self.context.injector.bind_instance(AnonCredsHolder, self.holder)

self.handler = AnonCredsCredFormatHandler(self.profile)
Expand Down Expand Up @@ -1042,7 +1041,7 @@ async def test_issue_credential_rr_full(self):
state=V20CredExRecord.STATE_REQUEST_RECEIVED,
)

self.issuer.create_credential = async_mock.CoroutineMock(
self.issuer.create_credential = mock.AsyncMock(
side_effect=AnonCredsRevocationRegistryFullError("Nope")
)
with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc:
Expand Down Expand Up @@ -1261,7 +1260,7 @@ async def test_store_credential_holder_store_indy_error(self):
)

cred_id = "cred-id"
self.holder.store_credential = async_mock.CoroutineMock(
self.holder.store_credential = mock.AsyncMock(
side_effect=test_module.AnonCredsHolderError("Problem", {"message": "Nope"})
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from aries_cloudagent.tests import mock
from unittest import IsolatedAsyncioTestCase
from asynctest import mock as async_mock

from ......core.oob_processor import OobMessageProcessor
from ......messaging.request_context import RequestContext
Expand Down Expand Up @@ -142,7 +141,7 @@ async def test_called_auto_request_x_anoncreds(self):
mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock(
return_value=mock.MagicMock(save_error_state=mock.CoroutineMock())
)
mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock(
mock_cred_mgr.return_value.create_request = mock.AsyncMock(
side_effect=test_module.AnonCredsHolderError()
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from aries_cloudagent.tests import mock
from unittest import IsolatedAsyncioTestCase
from asynctest import mock as async_mock

from ......messaging.request_context import RequestContext
from ......messaging.responder import MockResponder
Expand Down Expand Up @@ -108,7 +107,7 @@ async def test_called_auto_offer_x_anoncreds(self):
return_value=mock.MagicMock(save_error_state=mock.CoroutineMock())
)
mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True
mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock(
mock_cred_mgr.return_value.create_offer = mock.AsyncMock(
side_effect=test_module.AnonCredsIssuerError()
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from aries_cloudagent.tests import mock
from unittest import IsolatedAsyncioTestCase
from asynctest import mock as async_mock

from ......core.oob_processor import OobMessageProcessor
from ......messaging.request_context import RequestContext
Expand Down Expand Up @@ -157,7 +156,7 @@ async def test_called_auto_issue_x_anoncreds(self):
return_value=cred_ex_rec
)
mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True
mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock(
mock_cred_mgr.return_value.issue_credential = mock.AsyncMock(
side_effect=test_module.AnonCredsIssuerError()
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from .....vc.ld_proofs.error import LinkedDataProofException
from aries_cloudagent.tests import mock
from unittest import IsolatedAsyncioTestCase
from asynctest import mock as async_mock

from .....admin.request_context import AdminRequestContext

Expand Down Expand Up @@ -1353,7 +1352,7 @@ async def test_credential_exchange_issue_rev_reg_full_anoncreds(self):
mock_conn_rec.retrieve_by_id = mock.CoroutineMock()
mock_conn_rec.retrieve_by_id.return_value.is_ready = True

mock_issue_cred = async_mock.CoroutineMock(
mock_issue_cred = mock.AsyncMock(
side_effect=test_module.AnonCredsIssuerError()
)
mock_cred_mgr.return_value.issue_credential = mock_issue_cred
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from aries_cloudagent.tests import mock
from unittest import IsolatedAsyncioTestCase
from asynctest import mock as async_mock

from ......anoncreds.holder import AnonCredsHolder
from ......core.oob_processor import OobMessageProcessor
Expand Down Expand Up @@ -418,7 +417,7 @@ async def test_called_auto_present_x_anoncreds(self):
return_value=mock_px_rec
)

mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock(
mock_pres_mgr.return_value.create_pres = mock.AsyncMock(
side_effect=test_module.AnonCredsHolderError()
)

Expand Down
Loading

0 comments on commit 9ed0fd8

Please sign in to comment.