Update buildbucket test imports

Updates mcp/buildbucket_test.py to use `from unittest import mock`
instead of `from unittest.mock import ...` since the Google style guide
says to avoid importing specific pieces of a module except in a few
specific (typing-related) cases.

Change-Id: Ibefb62e492fbf48b89e97fc75bf55beda7030d52
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6842579
Reviewed-by: Struan Shrimpton <sshrimp@google.com>
Auto-Submit: Brian Sheedy <bsheedy@chromium.org>
Commit-Queue: Struan Shrimpton <sshrimp@google.com>
changes/79/6842579/2
Brian Sheedy 3 months ago committed by LUCI CQ
parent d1e4bd0ff2
commit 8c832a9622

@ -9,7 +9,7 @@ import pathlib
import subprocess
import sys
import unittest
from unittest.mock import AsyncMock, patch
from unittest import mock
sys.path.insert(
0,
@ -23,10 +23,10 @@ import buildbucket
class BuildbucketTest(unittest.IsolatedAsyncioTestCase):
def setUp(self):
self.mock_context = AsyncMock()
self.mock_context.info = AsyncMock()
self.mock_context = mock.AsyncMock()
self.mock_context.info = mock.AsyncMock()
@patch('subprocess.run')
@mock.patch('subprocess.run')
async def test_get_build_status_success(self, mock_subprocess_run):
build_id = '12345'
expected_status = 'SUCCESS'
@ -54,7 +54,7 @@ class BuildbucketTest(unittest.IsolatedAsyncioTestCase):
text=True,
)
@patch('subprocess.run')
@mock.patch('subprocess.run')
async def test_get_build_status_exception(self, mock_subprocess_run):
build_id = '12345'
mock_subprocess_run.side_effect = Exception('PRPC call failed')
@ -64,7 +64,7 @@ class BuildbucketTest(unittest.IsolatedAsyncioTestCase):
self.assertIn('Exception calling prpc', result)
self.assertIn('PRPC call failed', result)
@patch('subprocess.run')
@mock.patch('subprocess.run')
async def test_get_build_from_id_success(self, mock_subprocess_run):
build_id = '12345'
fields = ['steps', 'tags']
@ -91,7 +91,7 @@ class BuildbucketTest(unittest.IsolatedAsyncioTestCase):
check=False,
text=True)
@patch('subprocess.run')
@mock.patch('subprocess.run')
async def test_get_build_from_id_exception(self, mock_subprocess_run):
build_id = '12345'
fields = ['steps']
@ -106,7 +106,7 @@ class BuildbucketTest(unittest.IsolatedAsyncioTestCase):
self.assertIn('Exception calling prpc', result)
self.assertIn('PRPC call failed', result)
@patch('subprocess.run')
@mock.patch('subprocess.run')
async def test_get_build_from_build_number_success(
self,
mock_subprocess_run,
@ -147,7 +147,7 @@ class BuildbucketTest(unittest.IsolatedAsyncioTestCase):
check=False,
text=True)
@patch('subprocess.run')
@mock.patch('subprocess.run')
async def test_get_build_from_build_number_exception(
self, mock_subprocess_run):
build_number = 987
@ -164,7 +164,7 @@ class BuildbucketTest(unittest.IsolatedAsyncioTestCase):
self.assertIn('Exception calling prpc', result)
self.assertIn('PRPC call failed', result)
@patch('subprocess.run')
@mock.patch('subprocess.run')
async def test_get_build_success(self, mock_subprocess_run):
request = {"id": "12345"}
expected_output = '{"id": "12345"}'
@ -190,7 +190,7 @@ class BuildbucketTest(unittest.IsolatedAsyncioTestCase):
text=True,
)
@patch('subprocess.run')
@mock.patch('subprocess.run')
async def test_get_build_exception(self, mock_subprocess_run):
request = {"id": "12345"}
mock_subprocess_run.side_effect = Exception('PRPC call failed')
@ -200,7 +200,7 @@ class BuildbucketTest(unittest.IsolatedAsyncioTestCase):
self.assertIn('Exception calling prpc', result)
self.assertIn('PRPC call failed', result)
@patch('subprocess.run')
@mock.patch('subprocess.run')
async def test_get_recent_builds_success(self, mock_subprocess_run):
expected_output = '{"builds": [{"id": "1"}]}'
mock_subprocess_run.return_value = subprocess.CompletedProcess(
@ -244,7 +244,7 @@ class BuildbucketTest(unittest.IsolatedAsyncioTestCase):
text=True,
)
@patch('subprocess.run')
@mock.patch('subprocess.run')
async def test_get_recent_builds_with_url_encoding_success(
self, mock_subprocess_run):
builder_name_encoded = 'test%20builder'
@ -291,7 +291,7 @@ class BuildbucketTest(unittest.IsolatedAsyncioTestCase):
text=True,
)
@patch('subprocess.run')
@mock.patch('subprocess.run')
async def test_get_recent_builds_exception(self, mock_subprocess_run):
mock_subprocess_run.side_effect = Exception('PRPC call failed')
@ -317,7 +317,7 @@ class BuildbucketTest(unittest.IsolatedAsyncioTestCase):
0,
)
@patch('subprocess.run')
@mock.patch('subprocess.run')
async def test_get_recent_failed_builds_success(self, mock_subprocess_run):
expected_output = '{"builds": [{"id": "1", "status": "FAILURE"}]}'
mock_subprocess_run.return_value = subprocess.CompletedProcess(
@ -361,7 +361,7 @@ class BuildbucketTest(unittest.IsolatedAsyncioTestCase):
text=True,
)
@patch('subprocess.run')
@mock.patch('subprocess.run')
async def test_get_recent_failed_builds_exception(self,
mock_subprocess_run):
mock_subprocess_run.side_effect = Exception('PRPC call failed')

Loading…
Cancel
Save