Skip to content

Commit

Permalink
Remove use of mock (#1228)
Browse files Browse the repository at this point in the history
As of Python 3.3, mock is now included in the standard library, and
since the lowest version of Python supported is below that, we can
remove the dependency. Switch to using unittest.mock everywhere,
cleaning up some imports as a side benefit.
  • Loading branch information
s-t-e-v-e-n-k committed Jul 15, 2022
1 parent cd6a3c9 commit 30b5a97
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mock

4 changes: 2 additions & 2 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from unittest.mock import patch
from urllib.parse import urlencode

import tornado.testing
Expand All @@ -6,7 +7,6 @@
from tornado.concurrent import Future

import celery
import mock

from flower.app import Flower
from flower.urls import handlers
Expand Down Expand Up @@ -37,4 +37,4 @@ def post(self, url, **kwargs):
return self.fetch(url, method='POST', **kwargs)

def mock_option(self, name, value):
return mock.patch.object(options.mockable(), name, value)
return patch.object(options.mockable(), name, value)
5 changes: 2 additions & 3 deletions tests/unit/api/test_control.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from mock import MagicMock
import mock
from unittest.mock import MagicMock, patch
from flower.api.control import ControlHandler

from tests.unit import AsyncHTTPTestCase
Expand Down Expand Up @@ -174,7 +173,7 @@ def test_terminate_signal(self):

class ControlAuthTests(WorkerControlTests):
def test_auth(self):
with mock.patch.object(options.mockable(), 'basic_auth', ['user1:password1']):
with patch.object(options.mockable(), 'basic_auth', ['user1:password1']):
app = self._app.capp
app.control.broadcast = MagicMock()
r = self.post('/api/worker/shutdown/test', body={})
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/api/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mock import Mock, patch
from unittest.mock import Mock, patch, PropertyMock
from datetime import datetime, timedelta

from celery.result import AsyncResult
Expand All @@ -16,7 +16,6 @@

class ApplyTests(AsyncHTTPTestCase):
def test_apply(self):
from mock import patch, PropertyMock
import json

result = 'result'
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/api/test_workers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json

import mock
from unittest import mock

from flower.api.control import ControlHandler
from flower.inspector import Inspector
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import subprocess
from unittest.mock import Mock, patch

import mock
from prometheus_client import Histogram

from flower.command import apply_options, warn_about_celery_args_used_in_flower_command, apply_env_options
Expand Down Expand Up @@ -49,7 +48,7 @@ def test_autodiscovery(self):
- create flower command
"""
celery_app = self._get_celery_app()
with mock.patch.object(celery_app, '_autodiscover_tasks') as autodiscover:
with patch.object(celery_app, '_autodiscover_tasks') as autodiscover:
celery_app.autodiscover_tasks()

self.get_app(capp=celery_app)
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/utils/test_broker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import unittest

from mock import MagicMock
from unittest.mock import MagicMock

from flower.utils import broker
from flower.utils.broker import RabbitMQ, Redis, RedisBase, RedisSocket, Broker, RedisSentinel
Expand Down
7 changes: 1 addition & 6 deletions tests/unit/views/test_dashboard.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import time
import unittest
from unittest.mock import patch
import sys

from tests.unit import AsyncHTTPTestCase
from tests.unit.utils import task_succeeded_events, task_failed_events
from tests.unit.utils import HtmlTableParser

if sys.version_info >= (2, 7):
from mock import patch
else:
from unittest.mock import patch


from celery.events import Event
from celery.utils import uuid

Expand Down

0 comments on commit 30b5a97

Please sign in to comment.