Commit a8145025 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

depot_tools: Use mock from vpython (or unittest.mock) instead of third_party/mock

Change-Id: I3a188b34ae5f62649108afe08fe0e389a408c2ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1947933
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
parent ed0cc5f6
......@@ -21,3 +21,35 @@ wheel: <
name: "infra/python/wheels/six-py2_py3"
version: "version:1.10.0"
>
# Used by:
# tests/auth_test.py
# tests/detect_host_arch_test.py
# tests/gclient_scm_test.py
# tests/gclient_test.py
# tests/gclient_utils_test.py
# tests/gerrit_util_test.py
# tests/git_cl_test.py
# tests/git_drover_test.py
# tests/git_footers_test.py
# tests/metrics_test.py
# tests/presubmit_unittest.py
# tests/scm_unittest.py
# tests/subprocess2_test.py
# tests/watchlists_unittest.py
wheel: <
name: "infra/python/wheels/mock-py2_py3"
version: "version:2.0.0"
>
wheel <
name: "infra/python/wheels/funcsigs-py2_py3"
version: "version:1.0.2"
>
wheel: <
name: "infra/python/wheels/pbr-py2_py3"
version: "version:3.0.0"
>
wheel: <
name: "infra/python/wheels/six-py2_py3"
version: "version:1.10.0"
>
......@@ -17,12 +17,6 @@ import operator
import os
import pipes
import platform
try:
import Queue as queue
except ImportError: # For Py3 compatibility
import queue
import re
import stat
import subprocess
......@@ -30,18 +24,16 @@ import sys
import tempfile
import threading
import time
try:
import urlparse
except ImportError: # For Py3 compatibility
import urllib.parse as urlparse
import subprocess2
if sys.version_info.major == 2:
from cStringIO import StringIO
import Queue as queue
import urlparse
else:
from io import StringIO
import queue
import urllib.parse as urlparse
RETRY_MAX = 3
......
......@@ -12,18 +12,18 @@ import os
import unittest
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from third_party import mock
import auth
import subprocess2
if sys.version_info.major == 2:
import mock
BUILTIN_OPEN = '__builtin__.open'
else:
from unittest import mock
BUILTIN_OPEN = 'builtins.open'
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import auth
import subprocess2
NOW = datetime.datetime(2019, 10, 17, 12, 30, 59, 0)
VALID_EXPIRY = NOW + datetime.timedelta(seconds=31)
......@@ -57,7 +57,7 @@ class AuthenticatorTest(unittest.TestCase):
authenticator._access_token = auth.AccessToken('token', None)
self.assertEqual(
auth.AccessToken('token', None), authenticator.get_access_token())
self.assertEqual(0, len(subprocess2.check_call_out.mock_calls))
subprocess2.check_call_out.assert_not_called()
def testGetAccesstoken_LoggedIn(self):
expiry = calendar.timegm(VALID_EXPIRY.timetuple())
......
......@@ -8,10 +8,14 @@ import platform
import sys
import unittest
if sys.version_info.major == 2:
import mock
else:
from unittest import mock
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import detect_host_arch
from third_party import mock
class DetectHostArchTest(unittest.TestCase):
......
......@@ -22,12 +22,13 @@ import unittest
if sys.version_info.major == 2:
from cStringIO import StringIO
import mock
else:
from io import StringIO
from unittest import mock
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from third_party import mock
from testing_support import fake_repos
from testing_support import test_case_utils
......
......@@ -16,8 +16,10 @@ import sys
import unittest
if sys.version_info.major == 2:
import mock
import Queue
else:
from unittest import mock
import queue as Queue
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
......@@ -30,7 +32,6 @@ import gclient
import gclient_utils
import gclient_scm
from testing_support import trial_dir
from third_party import mock
def write(filename, content):
......
......@@ -16,13 +16,14 @@ import unittest
if sys.version_info.major == 2:
from StringIO import StringIO
import mock
else:
from io import StringIO
from unittest import mock
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from testing_support import trial_dir
from third_party import mock
import gclient_utils
import subprocess2
......
......@@ -14,9 +14,14 @@ import os
import sys
import unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if sys.version_info.major == 2:
from cStringIO import StringIO
import mock
else:
from io import StringIO
from unittest import mock
from third_party import mock
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import gerrit_util
import gclient_utils
......@@ -24,11 +29,6 @@ import metrics
import metrics_utils
import subprocess2
if sys.version_info.major == 2:
from cStringIO import StringIO
else:
from io import StringIO
class CookiesAuthenticatorTest(unittest.TestCase):
_GITCOOKIES = '\n'.join([
......
......@@ -17,10 +17,16 @@ import sys
import tempfile
import unittest
if sys.version_info.major == 2:
from StringIO import StringIO
import mock
else:
from io import StringIO
from unittest import mock
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from testing_support.auto_stub import TestCase
from third_party import mock
import metrics
# We have to disable monitoring before importing git_cl.
......@@ -32,11 +38,6 @@ import git_common
import git_footers
import subprocess2
if sys.version_info.major == 2:
from StringIO import StringIO
else:
from io import StringIO
def callError(code=1, cmd='', cwd='', stdout=b'', stderr=b''):
return subprocess2.CalledProcessError(code, cmd, cwd, stdout, stderr)
......
......@@ -11,9 +11,13 @@ import sys
import tempfile
import unittest
if sys.version_info.major == 2:
import mock
else:
from unittest import mock
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from third_party import mock
import git_drover
......
......@@ -10,12 +10,13 @@ import unittest
if sys.version_info.major == 2:
from StringIO import StringIO
import mock
else:
from io import StringIO
from unittest import mock
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from third_party import mock
import git_footers
class GitFootersTest(unittest.TestCase):
......
......@@ -8,14 +8,17 @@ import os
import sys
import unittest
if sys.version_info.major == 2:
import mock
else:
from unittest import mock
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, ROOT_DIR)
import metrics
import metrics_utils
from third_party import mock
class TimeMock(object):
def __init__(self):
......
......@@ -22,11 +22,21 @@ import threading
import time
import unittest
if sys.version_info.major == 2:
from cStringIO import StringIO
import mock
import urllib2 as urllib_request
BUILTIN_OPEN = '__builtin__.open'
else:
from io import StringIO
from unittest import mock
import urllib.request as urllib_request
BUILTIN_OPEN = 'builtins.open'
_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, _ROOT)
from testing_support.test_case_utils import TestCaseUtils
from third_party import mock
import auth
import gclient_utils
......@@ -39,14 +49,6 @@ import presubmit_support as presubmit
import scm
import subprocess2 as subprocess
if sys.version_info.major == 2:
from cStringIO import StringIO
import urllib2 as urllib_request
BUILTIN_OPEN = '__builtin__.open'
else:
from io import StringIO
import urllib.request as urllib_request
BUILTIN_OPEN = 'builtins.open'
# Shortcut.
presubmit_canned_checks = presubmit.presubmit_canned_checks
......@@ -2576,8 +2578,9 @@ the current line as well!
is_committing=False,
uncovered_files=set())
@mock.patch(BUILTIN_OPEN, mock.mock_open(read_data=''))
@mock.patch(BUILTIN_OPEN, mock.mock_open())
def testCannedRunUnitTests(self):
open().readline.return_value = ''
change = presubmit.Change(
'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
input_api = self.MockInputApi(change, False)
......@@ -2621,8 +2624,9 @@ the current line as well!
self.checkstdout('')
@mock.patch(BUILTIN_OPEN, mock.mock_open(read_data=''))
@mock.patch(BUILTIN_OPEN, mock.mock_open())
def testCannedRunUnitTestsWithTimer(self):
open().readline.return_value = ''
change = presubmit.Change(
'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
input_api = self.MockInputApi(change, False)
......@@ -2646,8 +2650,9 @@ the current line as well!
self.checkstdout('')
@mock.patch(BUILTIN_OPEN, mock.mock_open(read_data=''))
@mock.patch(BUILTIN_OPEN, mock.mock_open())
def testCannedRunUnitTestsWithTimerTimesOut(self):
open().readline.return_value = ''
change = presubmit.Change(
'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
input_api = self.MockInputApi(change, False)
......
......@@ -10,9 +10,13 @@ import os
import sys
import unittest
if sys.version_info.major == 2:
import mock
else:
from unittest import mock
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from third_party import mock
from testing_support import fake_repos
import scm
......
......@@ -9,14 +9,17 @@ import os
import sys
import unittest
if sys.version_info.major == 2:
import mock
else:
from unittest import mock
DEPOT_TOOLS = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, DEPOT_TOOLS)
import subprocess
import subprocess2
from third_party import mock
TEST_COMMAND = [
sys.executable,
......
......@@ -11,9 +11,13 @@ import os
import sys
import unittest
if sys.version_info.major == 2:
import mock
else:
from unittest import mock
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from third_party import mock
import watchlists
......
Copyright (c) 2003-2012, Michael Foord
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
Name: mock
URL: http://www.voidspace.org.uk/python/mock/
Version: 1.0.0
License: BSD
License File: LICENSE.txt
Description:
mock is a library for testing in Python. It allows you to replace parts of your
system under test with mock objects and make assertions about how they have been
used. mock is now part of the Python standard library, available as
unittest.mock in Python 3.3 onwards.
mock provides a core Mock class removing the need to create a host of stubs
throughout your test suite. After performing an action, you can make assertions
about which methods / attributes were used and arguments they were called with.
You can also specify return values and set needed attributes in the normal way.
Additionally, mock provides a patch() decorator that handles patching module and
class level attributes within the scope of a test, along with sentinel for
creating unique objects. Mock is very easy to use and is designed for use with
unittest. Mock is based on the ‘action -> assertion’ pattern instead of
‘record -> replay’ used by many mocking frameworks. mock is tested on Python
versions 2.4-2.7, Python 3 plus the latest versions of Jython and PyPy.
Modifications:
None.
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment