Skip to content

Commit

Permalink
Use build in unittest.mock (#1695)
Browse files Browse the repository at this point in the history
Since Python 3.3 the unittest module provides mock.
  • Loading branch information
jelly authored Feb 2, 2024
1 parent dfe3d5d commit 1375775
Show file tree
Hide file tree
Showing 28 changed files with 28 additions and 31 deletions.
5 changes: 2 additions & 3 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ An example is listed below:
[project.optional-dependencies]
test = [
"mock",
"requests",
"pytest >=7.2.1",
"pytest-cov",
Expand All @@ -45,7 +44,7 @@ before running the following:

.. code-block:: shell
pip install -U mock requests pytest pytest-cov
pip install -U requests pytest pytest-cov
It should be simpler to run the regular method, but if you have some reason to do this manually,
those are the steps.
Expand Down Expand Up @@ -308,4 +307,4 @@ This will test method ``test_method`` of class ``TestClass`` in ``test_file.py``
$ pytest tests/unit/test_file.py::TestClass::test_method
. [100%]
1 passed in 0.31s
1 passed in 0.31s
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ dependencies = [

[project.optional-dependencies]
test = [
"mock",
"requests",
"pytest >=7.2.1",
"pytest-cov",
Expand Down Expand Up @@ -78,7 +77,6 @@ exclude = [
[tool.hatch.envs.test]
dependencies = [
"coverage[toml]",
"mock",
"requests",
"pytest >=7.2.1",
"pytest-cov",
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_es_repo_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# class TestLoggingModules(CuratorTestCase):
# def test_logger_without_null_handler(self):
# from mock import patch, Mock
# from unittest.mock import patch, Mock
# mock = Mock()
# modules = {'logger': mock, 'logger.NullHandler': mock.module}
# self.write_config(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import random
import string
from unittest import SkipTest, TestCase
from mock import Mock
from unittest.mock import Mock
from .testvars import *

class CLITestCase(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_alias.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Alias unit tests"""
# pylint: disable=missing-function-docstring, missing-class-docstring, invalid-name, line-too-long, attribute-defined-outside-init
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator import IndexList
from curator.exceptions import ActionError, FailedExecution, MissingArgument, NoIndices
from curator.actions.alias import Alias
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_allocation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Alias unit tests"""
# pylint: disable=missing-function-docstring, missing-class-docstring, invalid-name, line-too-long, attribute-defined-outside-init
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator import IndexList
from curator.exceptions import MissingArgument
from curator.actions.allocation import Allocation
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_close.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Alias unit tests"""
# pylint: disable=missing-function-docstring, missing-class-docstring, invalid-name, line-too-long, attribute-defined-outside-init
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator import IndexList
from curator.exceptions import FailedExecution
from curator.actions.close import Close
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_clusterrouting.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""test_action_clusterrouting"""
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator.actions import ClusterRouting
# Get test variables and constants from a single source
from . import testvars
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_cold2frozen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""test_action_cold2frozen"""
# pylint: disable=attribute-defined-outside-init
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
import pytest
from curator.actions import Cold2Frozen
from curator.exceptions import CuratorException, SearchableSnapshotException
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_create_index.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Unit tests for create_index action"""
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator.actions import CreateIndex
from curator.exceptions import ConfigurationError, FailedExecution
# Get test variables and constants from a single source
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_delete_indices.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""test_action_delete_indices"""
# pylint: disable=missing-function-docstring, missing-class-docstring, protected-access, attribute-defined-outside-init
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator.actions import DeleteIndices
from curator.exceptions import FailedExecution
from curator import IndexList
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_delete_snapshots.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""test_action_delete_snapshots"""
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator.actions import DeleteSnapshots
from curator.exceptions import FailedExecution
from curator import SnapshotList
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_forcemerge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""test_action_forcemerge"""
# pylint: disable=missing-function-docstring, missing-class-docstring, protected-access, attribute-defined-outside-init
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator.actions import ForceMerge
from curator.exceptions import FailedExecution, MissingArgument
from curator import IndexList
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_indexsettings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""test_action_indexsettings"""
# pylint: disable=missing-function-docstring, missing-class-docstring, protected-access, attribute-defined-outside-init
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator.actions import IndexSettings
from curator.exceptions import ActionError, ConfigurationError, MissingArgument
from curator import IndexList
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_open.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""test_action_open"""
# pylint: disable=missing-function-docstring, missing-class-docstring, protected-access, attribute-defined-outside-init
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator.actions import Open
from curator.exceptions import FailedExecution
from curator import IndexList
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_reindex.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""test_action_reindex"""
# pylint: disable=missing-function-docstring, missing-class-docstring, protected-access, attribute-defined-outside-init
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator.actions import Reindex
from curator.exceptions import ConfigurationError, CuratorException, FailedExecution, NoIndices
from curator import IndexList
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_replicas.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""test_action_replicas"""
# pylint: disable=missing-function-docstring, missing-class-docstring, protected-access, attribute-defined-outside-init
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator.actions import Replicas
from curator.exceptions import FailedExecution, MissingArgument
from curator import IndexList
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_restore.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""test_action_restore"""
# pylint: disable=missing-function-docstring, missing-class-docstring, protected-access, attribute-defined-outside-init
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator.actions import Restore
from curator.exceptions import CuratorException, FailedExecution, FailedRestore, SnapshotInProgress
from curator import SnapshotList
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_rollover.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""test_action_rollover"""
# pylint: disable=missing-function-docstring, missing-class-docstring, protected-access, attribute-defined-outside-init
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator.actions import Rollover
from curator.exceptions import ConfigurationError

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_shrink.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""test_action_shrink"""
# pylint: disable=missing-function-docstring, missing-class-docstring, line-too-long, protected-access, attribute-defined-outside-init
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator.actions import Shrink
from curator.exceptions import ActionError, ConfigurationError
from curator import IndexList
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_action_snapshot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""test_action_snapshot"""
# pylint: disable=missing-function-docstring, missing-class-docstring, line-too-long, protected-access, attribute-defined-outside-init
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
from curator.actions import Snapshot
from curator.exceptions import ActionError, CuratorException, FailedExecution, FailedSnapshot, MissingArgument, SnapshotInProgress
from curator import IndexList
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_class_index_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# pylint: disable=missing-function-docstring, missing-class-docstring, line-too-long, attribute-defined-outside-init, protected-access
from unittest import TestCase
from copy import deepcopy
from mock import Mock
from unittest.mock import Mock
import yaml
from es_client.exceptions import FailedValidation
from curator.exceptions import ActionError, ConfigurationError, FailedExecution, MissingArgument, NoIndices
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_class_snapshot_list.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""test_class_snapshot_list"""
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
import yaml
from es_client.exceptions import FailedValidation
from curator import SnapshotList
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_helpers_date_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from unittest import TestCase
from datetime import datetime
import pytest
from mock import Mock
from unittest.mock import Mock
from elasticsearch8 import NotFoundError
from elastic_transport import ApiResponseMeta
from curator.exceptions import ConfigurationError
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_helpers_getters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Unit testing for helpers.creators functions"""
from unittest import TestCase
from mock import Mock
from unittest.mock import Mock
import pytest
from elastic_transport import ApiResponseMeta
from elasticsearch8 import NotFoundError, TransportError
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_helpers_testers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Unit tests for utils"""
from unittest import TestCase
import pytest
from mock import Mock
from unittest.mock import Mock
from elastic_transport import ApiResponseMeta
from elasticsearch8 import Elasticsearch
from elasticsearch8.exceptions import AuthenticationException, NotFoundError
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_helpers_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Unit tests for utils"""
from unittest import TestCase
# import pytest
from mock import Mock
from unittest.mock import Mock
# from curator.exceptions import MissingArgument
from curator.indexlist import IndexList
from curator.helpers.utils import chunk_index_list, show_dry_run, to_csv
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_helpers_waiters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Unit tests for utils"""
from unittest import TestCase
import pytest
from mock import Mock
from unittest.mock import Mock
from curator.exceptions import ActionTimeout, ConfigurationError, CuratorException, MissingArgument
from curator.helpers.waiters import (
health_check, restore_check, snapshot_check,task_check, wait_for_it)
Expand Down

0 comments on commit 1375775

Please sign in to comment.