Skip to content

Commit

Permalink
Migrate to unittest.mock
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderrichards committed Feb 6, 2020
1 parent 3281d70 commit 93a8716
Show file tree
Hide file tree
Showing 21 changed files with 21 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/pdm/framework/RESTClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ def patch_client(target, test_client, base_uri='/'):
# We import mock here as TestClient is only meant for use in the tests
# If we import it globally, it'll break importing this module in
# production.
import mock
import unittest.mock
# We patch away the base class of the target, replacing it with
# RESTClientTest instead.
patcher = mock.patch.object(target, '__bases__', (RESTClientTest, ))
patcher = unittest.mock.patch.object(target, '__bases__', (RESTClientTest, ))
patcher.start()
# is_local is required to prevent mock from attempting to delete
# __bases__ when stop is called (which would throw an exception)
Expand Down
2 changes: 1 addition & 1 deletion test/pdm/CLI/test_usercommand.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mock
import unittest
import unittest.mock as mock
import argparse
import tempfile
import datetime
Expand Down
2 changes: 1 addition & 1 deletion test/pdm/demo/test_DemoClient.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

import mock
import unittest
import unittest.mock as mock

from pdm.demo.DemoClient import DemoClient
from pdm.demo.DemoService import DemoService
Expand Down
2 changes: 1 addition & 1 deletion test/pdm/framework/test_Database.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env
""" Framework database object tests. """

import mock
import json
import datetime
import unittest
import unittest.mock as mock

from pdm.framework.Database import MemSafeSQLAlchemy
from pdm.framework.Database import JSONMixin, JSONTableEncoder
Expand Down
2 changes: 1 addition & 1 deletion test/pdm/framework/test_RESTClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
""" Test RESTClient framework module. """

import json
import mock
import unittest
import unittest.mock as mock
import functools
import requests

Expand Down
2 changes: 1 addition & 1 deletion test/pdm/framework/test_WSGIServer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
""" Tests for the WSGIServer module. """

import mock
import unittest
import unittest.mock as mock

from pdm.framework.WSGIServer import WSGIAuth, WSGIServer

Expand Down
2 changes: 1 addition & 1 deletion test/pdm/site/test_SiteClient.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python
""" Test SiteService client class. """

import mock
import logging
import datetime
import unittest
import unittest.mock as mock

from pdm.site.SiteClient import SiteClient
from pdm.site.SiteService import SiteService
Expand Down
2 changes: 1 addition & 1 deletion test/pdm/site/test_SiteService.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import copy
import json
import mock
import logging
import datetime
import unittest
import unittest.mock as mock

from flask import current_app
from pdm.site.SiteService import SiteService
Expand Down
2 changes: 1 addition & 1 deletion test/pdm/userservicedesk/test_HRClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import json
import unittest
import mock
import unittest.mock as mock
import datetime

from pdm.userservicedesk.HRClient import HRClient
Expand Down
2 changes: 1 addition & 1 deletion test/pdm/userservicedesk/test_HRService.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import time
import unittest
import mock
import unittest.mock as mock
import copy
import datetime
import smtplib
Expand Down
2 changes: 1 addition & 1 deletion test/pdm/userservicedesk/test_TransferClient.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mock
import unittest
import unittest.mock as mock
import datetime
from pdm.userservicedesk.TransferClientFacade import TransferClientFacade
from pdm.framework.FlaskWrapper import FlaskServer
Expand Down
2 changes: 1 addition & 1 deletion test/pdm/utils/test_X509.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python

import os
import mock
import unittest
import unittest.mock as mock
from functools import partial

from pdm.utils.X509 import X509Utils
Expand Down
2 changes: 1 addition & 1 deletion test/pdm/utils/test_db.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
""" Test DB utils. """

import mock
import unittest
import unittest.mock as mock

from pdm.utils.db import managed_session

Expand Down
2 changes: 1 addition & 1 deletion test/pdm/utils/test_lockfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
""" Test of utils lockfile module. """

import os
import mock
import fcntl
import unittest
import unittest.mock as mock

from pdm.utils.lockfile import PIDLockFile, AlreadyLockedError

Expand Down
2 changes: 1 addition & 1 deletion test/pdm/utils/test_myproxy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python

import os
import mock
import unittest
import unittest.mock as mock

from pdm.utils.myproxy import MyProxyUtils

Expand Down
2 changes: 1 addition & 1 deletion test/pdm/web/test_WebPageService.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

import unittest
import mock
import unittest.mock as mock

from pdm.web.WebPageService import WebPageService
from pdm.framework.FlaskWrapper import FlaskServer
Expand Down
2 changes: 1 addition & 1 deletion test/pdm/workqueue/scripts/test_stdout_dump_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest
import logging

import mock
import unittest.mock as mock

from pdm.workqueue.scripts import stdout_dump_helper

Expand Down
2 changes: 1 addition & 1 deletion test/pdm/workqueue/test_Worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
""" Test Worker module. """
import logging
import unittest
import mock
import unittest.mock as mock

from pdm.framework.FlaskWrapper import FlaskServer, jsonify
from pdm.framework.RESTClient import RESTClientTest
Expand Down
2 changes: 1 addition & 1 deletion test/pdm/workqueue/test_WorkqueueClient.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
""" Test WorkqueueClient module. """
import unittest
import mock
import unittest.mock as mock

from pdm.framework.FlaskWrapper import FlaskServer, jsonify
from pdm.framework.RESTClient import RESTClientTest
Expand Down
2 changes: 1 addition & 1 deletion test/pdm/workqueue/test_WorkqueueService.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import unittest
from textwrap import dedent
import mock
import unittest.mock as mock

from pdm.framework.FlaskWrapper import FlaskServer
from pdm.workqueue.WorkqueueDB import JobType, JobStatus, JobProtocol
Expand Down
2 changes: 0 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ sitepackages=True
# Standard unit testing + coverage
[testenv:unit]
deps=
mock
pytest
coverage
commands=
Expand All @@ -26,7 +25,6 @@ commands=

[testenv:lint]
deps=
mock
pylint
commands=
/bin/bash test/bin/run_pylint.sh

0 comments on commit 93a8716

Please sign in to comment.