test_189_lagom_functions_should_be_mockable   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 5

4 Functions

Rating   Name   Duplication   Size   Complexity  
A _fake_async() 0 2 1
A test_an_async_bound_function_can_be_mocked() 0 7 1
A test_a_bound_function_can_be_mocked() 0 6 2
A test_autospec_for_async_bound_function() 0 6 1
1
from unittest import mock
2
from unittest.mock import Mock
3
4
import pytest
5
6
7
async def _fake_async(_):
8
    return "mocked"
9
10
11
@mock.patch("tests.bug_fixes.resources_for_189.a_bound_function", lambda _: "mocked")
12
def test_a_bound_function_can_be_mocked():
13
    from tests.bug_fixes.resources_for_189 import a_bound_function
14
    from tests.test_context_based_executions import SomeDep
15
16
    assert a_bound_function(SomeDep()) == "mocked"
17
18
19
@mock.patch("tests.bug_fixes.resources_for_189.an_async_bound_function", _fake_async)
20
@pytest.mark.asyncio
21
async def test_an_async_bound_function_can_be_mocked():
22
    from tests.bug_fixes.resources_for_189 import an_async_bound_function
23
    from tests.test_context_based_executions import SomeDep
24
25
    assert await an_async_bound_function(SomeDep()) == "mocked"
26
27
28
@pytest.mark.asyncio
29
async def test_autospec_for_async_bound_function():
30
    from tests.bug_fixes.resources_for_189 import an_async_bound_function
31
32
    mock = Mock(spec=an_async_bound_function)
33
    assert mock
34