Fix urllib import + add test

Unblocks the chromium to webrtc roller.

Bug: webrtc:13607
Change-Id: I877d8d25624bdc924425ef338f392ce7686207f2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/251984
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Christoffer Jansson <jansson@google.com>
Cr-Commit-Position: refs/heads/main@{#36038}
This commit is contained in:
Christoffer Jansson 2022-02-21 16:32:18 +01:00 committed by WebRTC LUCI CQ
parent 808531653e
commit c13caac2d5
2 changed files with 35 additions and 1 deletions

View File

@ -18,7 +18,7 @@ import os
import re
import subprocess
import sys
import urllib
import urllib.request
def FindSrcDirPath():

View File

@ -323,6 +323,40 @@ class TestChooseCQMode(unittest.TestCase):
self.assertEqual(ChooseCQMode(False, 100, 500000, 500100), 2)
class TestReadUrlContent(unittest.TestCase):
def setUp(self):
self.url = 'http://localhost+?format=TEXT'
def testReadUrlContent(self):
url_mock = mock.Mock()
roll_deps.urllib.request.urlopen = url_mock
roll_deps.ReadUrlContent(self.url)
calls = [
mock.call('http://localhost+?format=TEXT'),
mock.call().readlines(),
mock.call().close()
]
self.assertEqual(url_mock.mock_calls, calls)
def testReadUrlContentError(self):
roll_deps.logging = mock.Mock()
readlines_mock = mock.Mock()
readlines_mock.readlines = mock.Mock(
side_effect=IOError('Connection error'))
readlines_mock.close = mock.Mock()
url_mock = mock.Mock(return_value=readlines_mock)
roll_deps.urllib.request.urlopen = url_mock
try:
roll_deps.ReadUrlContent(self.url)
except OSError:
self.assertTrue(roll_deps.logging.exception.called)
def _SetupGitLsRemoteCall(cmd_fake, url, revision):
cmd = ['git', 'ls-remote', url, revision]
cmd_fake.AddExpectation(cmd, _returns=(revision, None))