Bug 1714684: Remove usages of vendored "mock" library r=perftest-reviewers,ahal,sparky

Python 3 has access to `unittest.mock` in the standard library.

Differential Revision: https://phabricator.services.mozilla.com/D117073
This commit is contained in:
Mitchell Hentges 2021-06-14 15:34:46 +00:00
parent 14e9ec13ca
commit e389cc4cc4
43 changed files with 67 additions and 168 deletions

View File

@ -64,7 +64,6 @@ mozilla.pth:third_party/python/jsmin
mozilla.pth:third_party/python/json-e
mozilla.pth:third_party/python/jsonschema
mozilla.pth:third_party/python/MarkupSafe/src
mozilla.pth:third_party/python/mock-1.0.0
mozilla.pth:third_party/python/mohawk
mozilla.pth:third_party/python/more-itertools
mozilla.pth:third_party/python/mozilla-version

View File

@ -5,7 +5,7 @@
from __future__ import print_function, absolute_import
import sys
from mock import Mock
from unittest.mock import Mock
class NoopTelemetry(object):
@ -38,9 +38,7 @@ class GleanTelemetry(object):
during this mach invocation.
"""
def __init__(
self,
):
def __init__(self,):
self._metrics_cache = {}
def metrics(self, metrics_path):

View File

@ -7,7 +7,7 @@ from __future__ import absolute_import, unicode_literals
import os
import pytest
from mock import Mock
from unittest.mock import Mock
from mozbuild.base import MachCommandBase
from mozunit import main

View File

@ -10,7 +10,7 @@ import sys
from mach.base import MachError
from mach.test.conftest import TestBase
from mock import patch
from unittest.mock import patch
from mozunit import main

View File

@ -4,7 +4,7 @@
from __future__ import absolute_import, unicode_literals, print_function
import os
import unittest
import mock
from unittest import mock
from mozunit import main
from mach.registrar import Registrar

View File

@ -4,32 +4,22 @@
from __future__ import absolute_import, print_function, unicode_literals
from mock import patch
from unittest.mock import patch
from six import StringIO
import os
import sys
import textwrap
import unittest
from mozunit import (
main,
MockedOpen,
)
from mozunit import main, MockedOpen
from mozbuild.configure import (
ConfigureError,
ConfigureSandbox,
)
from mozbuild.configure import ConfigureError, ConfigureSandbox
from mozbuild.util import exec_
from mozbuild.shellutil import quote as shell_quote
from mozpack import path as mozpath
from buildconfig import topsrcdir
from common import (
ConfigureTestSandbox,
ensure_exe_extension,
fake_short_path,
)
from common import ConfigureTestSandbox, ensure_exe_extension, fake_short_path
class TestChecksConfigure(unittest.TestCase):
@ -119,11 +109,7 @@ class TestChecksConfigure(unittest.TestCase):
):
config = {}
out = StringIO()
paths = {
self.KNOWN_A: None,
self.KNOWN_B: None,
self.KNOWN_C: None,
}
paths = {self.KNOWN_A: None, self.KNOWN_B: None, self.KNOWN_C: None}
if extra_paths:
paths.update(extra_paths)
environ = dict(environ)
@ -624,13 +610,7 @@ class TestChecksConfigure(unittest.TestCase):
config, out, status = run_configure_java(paths)
self.assertEqual(status, 0)
self.assertEqual(
config,
{
"JAVA": java,
"MOZ_JAVA_CODE_COVERAGE": False,
},
)
self.assertEqual(config, {"JAVA": java, "MOZ_JAVA_CODE_COVERAGE": False})
self.assertEqual(
out,
textwrap.dedent(
@ -650,13 +630,7 @@ class TestChecksConfigure(unittest.TestCase):
alt_path = mozpath.dirname(java)
config, out, status = run_configure_java(paths, alt_java_home, alt_path)
self.assertEqual(status, 0)
self.assertEqual(
config,
{
"JAVA": alt_java,
"MOZ_JAVA_CODE_COVERAGE": False,
},
)
self.assertEqual(config, {"JAVA": alt_java, "MOZ_JAVA_CODE_COVERAGE": False})
self.assertEqual(
out,
textwrap.dedent(
@ -675,13 +649,7 @@ class TestChecksConfigure(unittest.TestCase):
args=["--with-java-bin-path=%s" % mozpath.dirname(alt_java)],
)
self.assertEqual(status, 0)
self.assertEqual(
config,
{
"JAVA": alt_java,
"MOZ_JAVA_CODE_COVERAGE": False,
},
)
self.assertEqual(config, {"JAVA": alt_java, "MOZ_JAVA_CODE_COVERAGE": False})
self.assertEqual(
out,
textwrap.dedent(
@ -701,13 +669,7 @@ class TestChecksConfigure(unittest.TestCase):
args=["--with-java-bin-path=%s" % mozpath.dirname(alt_java)],
)
self.assertEqual(status, 0)
self.assertEqual(
config,
{
"JAVA": alt_java,
"MOZ_JAVA_CODE_COVERAGE": False,
},
)
self.assertEqual(config, {"JAVA": alt_java, "MOZ_JAVA_CODE_COVERAGE": False})
self.assertEqual(
out,
textwrap.dedent(
@ -727,13 +689,7 @@ class TestChecksConfigure(unittest.TestCase):
args=["--enable-java-coverage"],
)
self.assertEqual(status, 0)
self.assertEqual(
config,
{
"JAVA": java,
"MOZ_JAVA_CODE_COVERAGE": True,
},
)
self.assertEqual(config, {"JAVA": java, "MOZ_JAVA_CODE_COVERAGE": True})
# Any missing tool is fatal when these checks run.
paths = {}
@ -806,9 +762,7 @@ and/or set $JAVA_HOME.
includes=(),
)
extra_paths = {
mock_pkg_config_path: mock_pkg_config,
}
extra_paths = {mock_pkg_config_path: mock_pkg_config}
config, output, status = get_result("pkg_check_modules('MOZ_VALID', 'valid')")
self.assertEqual(status, 1)
@ -869,12 +823,7 @@ and/or set $JAVA_HOME.
% (mock_pkg_config_path, mock_pkg_config_version)
),
)
self.assertEqual(
config,
{
"PKG_CONFIG": mock_pkg_config_path,
},
)
self.assertEqual(config, {"PKG_CONFIG": mock_pkg_config_path})
config, output, status = get_result(
"pkg_check_modules('MOZ_NEW', 'new > 1.1')", extra_paths=extra_paths
@ -892,12 +841,7 @@ and/or set $JAVA_HOME.
% (mock_pkg_config_path, mock_pkg_config_version)
),
)
self.assertEqual(
config,
{
"PKG_CONFIG": mock_pkg_config_path,
},
)
self.assertEqual(config, {"PKG_CONFIG": mock_pkg_config_path})
# allow_missing makes missing packages non-fatal.
cmd = textwrap.dedent(
@ -925,12 +869,7 @@ and/or set $JAVA_HOME.
% (mock_pkg_config_path, mock_pkg_config_version)
),
)
self.assertEqual(
config,
{
"PKG_CONFIG": mock_pkg_config_path,
},
)
self.assertEqual(config, {"PKG_CONFIG": mock_pkg_config_path})
config, output, status = get_result(
cmd, args=["--disable-compile-environment"], extra_paths=extra_paths
@ -944,9 +883,7 @@ and/or set $JAVA_HOME.
return 0, "0.8.10", ""
self.fail("Unexpected arguments to mock_old_pkg_config: %s" % args)
extra_paths = {
mock_pkg_config_path: mock_old_pkg_config,
}
extra_paths = {mock_pkg_config_path: mock_old_pkg_config}
config, output, status = get_result(
"pkg_check_modules('MOZ_VALID', 'valid')", extra_paths=extra_paths
@ -979,12 +916,7 @@ and/or set $JAVA_HOME.
"""
),
)
self.assertEqual(
config,
{
"MOZ_MOZILLA_API_KEY": "no-mozilla-api-key",
},
)
self.assertEqual(config, {"MOZ_MOZILLA_API_KEY": "no-mozilla-api-key"})
config, output, status = self.get_result(
"simple_keyfile('Mozilla API')",
@ -1036,12 +968,7 @@ and/or set $JAVA_HOME.
"""
),
)
self.assertEqual(
config,
{
"MOZ_MOZILLA_API_KEY": "fake-key",
},
)
self.assertEqual(config, {"MOZ_MOZILLA_API_KEY": "fake-key"})
with MockedOpen({"default": "default-key\n"}):
config, output, status = self.get_result(
@ -1056,12 +983,7 @@ and/or set $JAVA_HOME.
"""
),
)
self.assertEqual(
config,
{
"MOZ_MOZILLA_API_KEY": "default-key",
},
)
self.assertEqual(config, {"MOZ_MOZILLA_API_KEY": "default-key"})
with MockedOpen({"default": "default-key\n", "key": "fake-key\n"}):
config, output, status = self.get_result(
@ -1076,12 +998,7 @@ and/or set $JAVA_HOME.
"""
),
)
self.assertEqual(
config,
{
"MOZ_MOZILLA_API_KEY": "fake-key",
},
)
self.assertEqual(config, {"MOZ_MOZILLA_API_KEY": "fake-key"})
def test_id_and_secret_keyfile(self):
includes = ("util.configure", "checks.configure", "keyfiles.configure")
@ -1158,10 +1075,7 @@ and/or set $JAVA_HOME.
)
self.assertEqual(
config,
{
"MOZ_BING_API_CLIENTID": "fake-id",
"MOZ_BING_API_KEY": "fake-key",
},
{"MOZ_BING_API_CLIENTID": "fake-id", "MOZ_BING_API_KEY": "fake-key"},
)
with MockedOpen({"key": "fake-key\n"}):
@ -1223,10 +1137,7 @@ and/or set $JAVA_HOME.
)
self.assertEqual(
config,
{
"MOZ_BING_API_CLIENTID": "fake-id",
"MOZ_BING_API_KEY": "fake-key",
},
{"MOZ_BING_API_CLIENTID": "fake-id", "MOZ_BING_API_KEY": "fake-key"},
)

View File

@ -9,7 +9,7 @@ from unittest.mock import Mock
import pytest
import mock
from unittest import mock
import mozunit
import requests
@ -25,18 +25,11 @@ from mozbuild.settings import TelemetrySettings
@SettingsProvider
class OtherSettings:
config_settings = [
("foo.bar", "int", "", 1),
("build.abc", "string", "", ""),
]
config_settings = [("foo.bar", "int", "", 1), ("build.abc", "string", "", "")]
def record_enabled_telemetry(mozbuild_path, settings):
record_telemetry_settings(
settings,
mozbuild_path,
True,
)
record_telemetry_settings(settings, mozbuild_path, True)
@pytest.fixture
@ -166,8 +159,7 @@ def test_resolve_is_employee():
"mach.telemetry.resolve_is_employee_by_credentials",
return_value=is_employee_bugzilla,
), mock.patch(
"mach.telemetry.resolve_is_employee_by_vcs",
return_value=is_employee_vcs,
"mach.telemetry.resolve_is_employee_by_vcs", return_value=is_employee_vcs
):
return resolve_is_employee(None)

View File

@ -10,7 +10,7 @@ import subprocess
import tempfile
from buildconfig import topsrcdir
from mock import Mock
from unittest.mock import Mock
from mozbuild.vendor.vendor_python import VendorPython
import mozunit

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
import pytest
import mock
from unittest import mock
import mozunit
from mozperftest.environment import METRICS
from mozperftest.tests.support import BT_DATA, EXAMPLE_TEST, get_running_env, temp_file

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
from pathlib import Path
import pytest
import mock
from unittest import mock
import mozunit
from mozperftest.metrics.notebook.constant import Constant

View File

@ -9,7 +9,7 @@ import json
from pprint import pprint
import pytest
from mock import patch
from unittest.mock import patch
from mozunit import main, MockedOpen
from taskgraph import actions, create

View File

@ -6,7 +6,7 @@ from __future__ import absolute_import, print_function, unicode_literals
import unittest
import mock
from unittest import mock
from taskgraph import create
from taskgraph.config import GraphConfig

View File

@ -10,7 +10,7 @@ import shutil
import unittest
import tempfile
from mock import patch
from unittest.mock import patch
from mozunit import main, MockedOpen
from taskgraph import decision
from taskgraph.util.yaml import load_yaml

View File

@ -10,7 +10,7 @@ import stat
import tarfile
import tempfile
import unittest
import mock
from unittest import mock
import taskcluster_urls as liburls
from taskgraph.util import docker

View File

@ -6,7 +6,7 @@ from __future__ import absolute_import, print_function, unicode_literals
import unittest
import datetime
import mock
from unittest import mock
import os
from mozunit import main

View File

@ -5,7 +5,7 @@ from random import randint, seed
import mozdevice
import pytest
from mock import patch
from unittest.mock import patch
from six import StringIO
# set up required module-level variables/objects

View File

@ -4,7 +4,7 @@ from __future__ import absolute_import
import logging
from mock import patch
from unittest.mock import patch
import mozunit
import pytest

View File

@ -12,7 +12,7 @@ import requests
import threading
import time
import re
import mock
from unittest import mock
import six
from mozgeckoprofiler import view_gecko_profile

View File

@ -7,7 +7,7 @@
from __future__ import absolute_import
import json
import mock
from unittest import mock
import os
import shutil
import sys

View File

@ -12,7 +12,7 @@ from distutils.spawn import find_executable
import moznetwork
import pytest
import mock
from unittest import mock
import mozinfo
import mozunit

View File

@ -1,6 +1,6 @@
from __future__ import absolute_import, print_function
import mock
from unittest import mock
import os
import pytest
import tempfile

View File

@ -3,7 +3,7 @@
from __future__ import absolute_import
import datetime
import mock
from unittest import mock
import mozunit
import os
import pytest

View File

@ -2,7 +2,7 @@
from __future__ import absolute_import
import mock
from unittest import mock
import mozunit
import time

View File

@ -2,7 +2,7 @@
from __future__ import absolute_import
import mock
from unittest import mock
import mozunit
import pytest
import subprocess

View File

@ -2,7 +2,7 @@
from __future__ import absolute_import
import mock
from unittest import mock
import mozunit
import pytest

View File

@ -4,7 +4,7 @@ from __future__ import absolute_import, print_function
import json
import os
import mock
from unittest import mock
import mozunit
here = os.path.dirname(__file__)

View File

@ -2,7 +2,7 @@
from __future__ import absolute_import, print_function
import os
import mock
from unittest import mock
import mozunit
import mozinfo
import requests

View File

@ -3,7 +3,7 @@ from __future__ import absolute_import, print_function
import os
import shutil
import mock
from unittest import mock
import mozunit
from mozproxy.utils import download_file_from_url

View File

@ -5,7 +5,7 @@
from __future__ import absolute_import
from mock import patch
from unittest.mock import patch
import mozunit
import pytest

View File

@ -5,7 +5,7 @@ from __future__ import absolute_import
from time import sleep
import mozunit
from mock import patch
from unittest.mock import patch
from pytest import raises
from mozrunner import RunnerNotStartedError

View File

@ -1,5 +1,5 @@
from __future__ import absolute_import
import mock
from unittest import mock
import unittest
from mozharness.base.diskutils import convert_to, DiskutilsError, DiskSize, DiskInfo

View File

@ -1,7 +1,7 @@
from __future__ import absolute_import, print_function
import gc
import mock
from unittest import mock
import os
import re
import shutil

View File

@ -3,7 +3,7 @@ import os
import shutil
import unittest
import mock
from unittest import mock
import mozharness.base.script as script
import mozharness.mozilla.l10n.locales as locales

View File

@ -8,7 +8,6 @@ deps =
nose
rednose
{toxinidir}/../mozbase/mozlog
{toxinidir}/../../third_party/python/mock-1.0.0/
mozbase = {toxinidir}/../mozbase/

View File

@ -4,7 +4,7 @@ import mozunit
import os
import requests
import sys
import mock
from unittest import mock
import shutil
try:

View File

@ -6,7 +6,7 @@ from __future__ import absolute_import, division, unicode_literals
import os
import sys
import mock
from unittest import mock
import mozunit
# need this so the raptor unit tests can find output & filter classes

View File

@ -6,7 +6,7 @@ from __future__ import absolute_import, unicode_literals
import sys
import os
import mock
from unittest import mock
import tempfile
import mozunit

View File

@ -5,9 +5,9 @@ import sys
import threading
import time
import traceback
import mock
from unittest import mock
import pytest
from mock import Mock
from unittest.mock import Mock
from six import reraise
import mozunit

View File

@ -3,7 +3,7 @@ from __future__ import absolute_import
import copy
import os
import mock
from unittest import mock
import mozunit
import pytest

View File

@ -3,7 +3,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import mock
from unittest import mock
import mozunit
import os
import shutil
@ -14,7 +14,7 @@ import tempfile
import unittest
import buildconfig
from mock import patch
from unittest.mock import patch
from mozpack.manifests import InstallManifest
import mozpack.path as mozpath

View File

@ -1,5 +1,5 @@
import contextlib
import mock
from unittest import mock
import os
import pytest
import shutil

View File

@ -1,5 +1,5 @@
import contextlib
import mock
from unittest import mock
import os
import shutil
import tempfile

View File

@ -8,7 +8,7 @@ import os
import pytest
import yaml
from mock import MagicMock
from unittest.mock import MagicMock
from moztest.resolve import TestResolver
from taskgraph.graph import Graph
from taskgraph.task import Task