Skip to content

Commit

Permalink
Switch to stdlib's mock instead of a backported one
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Vasilyev <[email protected]>
  • Loading branch information
nolar committed Oct 8, 2023
1 parent 2f9e058 commit 7266d37
Show file tree
Hide file tree
Showing 24 changed files with 25 additions and 29 deletions.
2 changes: 0 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
[pytest]
; The standalone `mock` instead of stdlib `unittest.mock` is only for AsyncMock in Python 3.7.
mock_use_standalone_module = true
asyncio_mode = auto
addopts =
--strict-markers
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ freezegun
import-linter
isort
lxml
# Generally, `unittest.mock` is enough, but it lacks `AsyncMock` for Py 3.7.
# TODO: Once 3.7 is removed (Jun 2023), roll back to unittest.mock.
mock
# Mypy requires typed-ast, which is broken on PyPy 3.7 (could work in PyPy 3.8).
mypy==1.2.0; implementation_name == "cpython"
pre-commit
Expand Down
2 changes: 1 addition & 1 deletion tests/admission/test_admission_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import contextlib
from unittest.mock import Mock

import pytest
from mock import Mock

import kopf
from kopf._cogs.aiokits.aiovalues import Container
Expand Down
3 changes: 2 additions & 1 deletion tests/admission/test_serving_handler_selection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest.mock import Mock

import pytest
from mock import Mock

import kopf
from kopf._cogs.structs.ids import HandlerId
Expand Down
3 changes: 2 additions & 1 deletion tests/admission/test_serving_kwargs_passthrough.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest.mock import Mock

import pytest
from mock import Mock

import kopf
from kopf._core.engines.admission import serve_admission_request
Expand Down
2 changes: 1 addition & 1 deletion tests/apis/test_iterjsonlines.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mock import Mock
from unittest.mock import Mock

from kopf._cogs.clients.api import iter_jsonlines

Expand Down
2 changes: 1 addition & 1 deletion tests/basic-structs/test_memories.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mock import Mock
from unittest.mock import Mock

from kopf._cogs.structs.bodies import Body
from kopf._cogs.structs.ephemera import Memo
Expand Down
2 changes: 1 addition & 1 deletion tests/causation/test_kwargs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import dataclasses
import logging
from typing import Type
from unittest.mock import Mock

import pytest
from mock import Mock

from kopf._cogs.configs.configuration import OperatorSettings
from kopf._cogs.structs import diffs
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import sys
import time
from typing import Set
from unittest.mock import AsyncMock, Mock

import aiohttp.web
import pytest
from mock import AsyncMock, Mock

import kopf
from kopf._cogs.clients.auth import APIContext
Expand Down
2 changes: 1 addition & 1 deletion tests/handling/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"""
import dataclasses
from typing import Callable
from unittest.mock import Mock

import pytest
from mock import Mock

import kopf
from kopf._core.intents.causes import ChangingCause
Expand Down
2 changes: 1 addition & 1 deletion tests/handling/daemons/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio
import contextlib
import time
from unittest.mock import MagicMock, patch

import freezegun
import pytest
from mock import MagicMock, patch

import kopf
from kopf._cogs.aiokits.aiotoggles import ToggleSet
Expand Down
2 changes: 1 addition & 1 deletion tests/handling/subhandling/test_subhandling.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio
import logging
from unittest.mock import Mock

import pytest
from mock import Mock

import kopf
from kopf._cogs.structs.ephemera import Memo
Expand Down
3 changes: 1 addition & 2 deletions tests/handling/test_parametrization.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio

from mock import Mock
from unittest.mock import Mock

import kopf
from kopf._cogs.structs.ephemera import Memo
Expand Down
3 changes: 2 additions & 1 deletion tests/hierarchies/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest.mock import Mock

import pytest
from mock import Mock


class CustomIterable:
Expand Down
2 changes: 1 addition & 1 deletion tests/hierarchies/test_owner_referencing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import copy
from unittest.mock import call

import pytest
from mock import call

import kopf
from kopf._cogs.structs.bodies import Body, RawBody, RawMeta
Expand Down
2 changes: 1 addition & 1 deletion tests/invocations/test_callbacks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import functools
import logging
import traceback
from unittest.mock import Mock

import pytest
from mock import Mock

from kopf._cogs.structs.bodies import Body
from kopf._cogs.structs.patches import Patch
Expand Down
2 changes: 1 addition & 1 deletion tests/persistence/test_states.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import datetime
from unittest.mock import Mock

import freezegun
import pytest
from mock import Mock

from kopf._cogs.configs.progress import SmartProgressStorage, StatusProgressStorage
from kopf._cogs.structs.bodies import Body
Expand Down
2 changes: 1 addition & 1 deletion tests/reactor/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio
import functools
from unittest.mock import AsyncMock

import pytest
from mock import AsyncMock

from kopf._cogs.clients.watching import infinite_watch
from kopf._core.reactor.queueing import watcher, worker as original_worker
Expand Down
2 changes: 1 addition & 1 deletion tests/registries/test_matching_of_callbacks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dataclasses
from unittest.mock import Mock

import pytest
from mock import Mock

from kopf._cogs.structs.bodies import Body
from kopf._cogs.structs.dicts import parse_field
Expand Down
2 changes: 1 addition & 1 deletion tests/registries/test_matching_of_resources.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mock import Mock
from unittest.mock import Mock

from kopf._cogs.structs.references import Resource, Selector
from kopf._core.intents.registries import _matches_resource
Expand Down
3 changes: 1 addition & 2 deletions tests/settings/test_executor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import concurrent.futures
import threading

from mock import MagicMock
from unittest.mock import MagicMock

import kopf
from kopf._core.actions.invocation import invoke
Expand Down
2 changes: 1 addition & 1 deletion tests/timing/test_throttling.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio
import logging
from unittest.mock import call

import pytest
from mock import call

from kopf._core.actions.throttlers import Throttler, throttled

Expand Down
2 changes: 1 addition & 1 deletion tests/utilities/aiotasks/test_coro_cancellation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import asyncio
import gc
import warnings
from unittest.mock import AsyncMock, Mock

import pytest
from mock import AsyncMock, Mock

from kopf._cogs.aiokits.aiotasks import cancel_coro

Expand Down
2 changes: 1 addition & 1 deletion tests/utilities/aiotasks/test_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
from unittest.mock import Mock

import pytest
from mock import Mock

from kopf._cogs.aiokits.aiotasks import Scheduler

Expand Down

0 comments on commit 7266d37

Please sign in to comment.