Skip to content

Commit

Permalink
Use our own AsyncMock
Browse files Browse the repository at this point in the history
The one from unittest doesn't exist in Python 3.7.
Also consolidate a second async mock wrapper for code reuse.
  • Loading branch information
clenk committed Apr 21, 2023
1 parent 933bae0 commit c2d4e69
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Expand Up @@ -2,7 +2,6 @@
import os.path

import pytest
from unittest.mock import AsyncMock
import random
import string
import uuid
Expand Down Expand Up @@ -63,6 +62,7 @@
from app.api.rest_api import RestApi

from app import version
from tests import AsyncMock

DIR = os.path.dirname(os.path.abspath(__file__))
CONFIG_DIR = os.path.join(DIR, '..', 'conf')
Expand Down
12 changes: 3 additions & 9 deletions tests/services/test_planning_svc.py
Expand Up @@ -11,6 +11,7 @@
from app.objects.secondclass.c_fact import Fact
from app.objects.secondclass.c_requirement import Requirement
from app.utility.base_world import BaseWorld
from tests import AsyncMock


stop_bucket_exhaustion_params = [
Expand Down Expand Up @@ -69,13 +70,6 @@ def __init__(self, **kwargs):
return PlannerStub(**kwargs)


def async_wrapper(return_value):
"""Creates an async method that returns a constant value for mocking purposes."""
async def wrap(*args, **kwargs):
return return_value
return wrap


@pytest.fixture
async def setup_planning_test(executor, ability, agent, operation, data_svc, event_svc, init_base_world):
texecutor = executor(name='sh', platform='darwin', command='mkdir test', cleanup='rm -rf test')
Expand Down Expand Up @@ -355,9 +349,9 @@ async def test_trim_links(self, setup_planning_test, planning_svc):
Fact(trait='a.b.e', value='3'),
]

operation.all_facts = async_wrapper(facts)
operation.all_facts = AsyncMock(return_value=facts)
operation.planner = MagicMock()
planning_svc.load_module = async_wrapper(RequirementFake())
planning_svc.load_module = AsyncMock(return_value=RequirementFake())
link.ability.requirements = [Requirement('fake_requirement', [{'fake': 'relationship'}])]

trimmed_links = await planning_svc.trim_links(operation, [link], agent)
Expand Down

0 comments on commit c2d4e69

Please sign in to comment.