本文整理匯總了Python中pants.binaries.binary_util.BinaryUtil._select_binary_stream方法的典型用法代碼示例。如果您正苦於以下問題:Python BinaryUtil._select_binary_stream方法的具體用法?Python BinaryUtil._select_binary_stream怎麽用?Python BinaryUtil._select_binary_stream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pants.binaries.binary_util.BinaryUtil
的用法示例。
在下文中一共展示了BinaryUtil._select_binary_stream方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_support_url_fallback
# 需要導入模塊: from pants.binaries.binary_util import BinaryUtil [as 別名]
# 或者: from pants.binaries.binary_util.BinaryUtil import _select_binary_stream [as 別名]
def test_support_url_fallback(self):
"""Tests fallback behavior with multiple support baseurls.
Mocks up some dummy baseurls and then swaps out the URL reader to make sure urls are accessed
and others are not.
"""
fake_base, fake_url = self._fake_base, self._fake_url
bases = [fake_base('apple'), fake_base('orange'), fake_base('banana')]
binary_util = BinaryUtil(bases, 30, '/tmp')
binaries = {t[2]: t for t in (('bin/protobuf', '2.4.1', 'protoc'),
('bin/ivy', '4.3.7', 'ivy'),
('bin/bash', '4.4.3', 'bash'))}
reader = self.MapReader({
fake_url(binaries, bases[0], 'protoc'): 'SEEN PROTOC',
fake_url(binaries, bases[0], 'ivy'): 'SEEN IVY',
fake_url(binaries, bases[1], 'bash'): 'SEEN BASH',
fake_url(binaries, bases[1], 'protoc'): 'UNSEEN PROTOC 1',
fake_url(binaries, bases[2], 'protoc'): 'UNSEEN PROTOC 2',
fake_url(binaries, bases[2], 'ivy'): 'UNSEEN IVY 2',
})
unseen = [item for item in reader.values() if item.startswith('SEEN ')]
for supportdir, version, name in binaries.values():
with binary_util._select_binary_stream(supportdir=supportdir,
version=version,
name=name,
url_opener=reader) as stream:
self.assertEqual(stream(), 'SEEN ' + name.upper())
unseen.remove(stream())
self.assertEqual(0, len(unseen)) # Make sure we've seen all the SEENs.
示例2: test_nobases
# 需要導入模塊: from pants.binaries.binary_util import BinaryUtil [as 別名]
# 或者: from pants.binaries.binary_util.BinaryUtil import _select_binary_stream [as 別名]
def test_nobases(self):
"""Tests exception handling if build support urls are improperly specified."""
binary_util = BinaryUtil(baseurls=[], timeout_secs=30, bootstrapdir='/tmp')
with self.assertRaises(binary_util.NoBaseUrlsError):
with binary_util._select_binary_stream(supportdir='bin/protobuf',
version='2.4.1',
name='protoc'):
self.fail('Expected acquisition of the stream to raise.')
示例3: test_timeout
# 需要導入模塊: from pants.binaries.binary_util import BinaryUtil [as 別名]
# 或者: from pants.binaries.binary_util.BinaryUtil import _select_binary_stream [as 別名]
def test_timeout(self):
fetcher = mock.create_autospec(Fetcher, spec_set=True)
binary_util = BinaryUtil(baseurls=['http://binaries.example.com'],
timeout_secs=42,
bootstrapdir='/tmp')
self.assertFalse(fetcher.download.called)
with binary_util._select_binary_stream('a-binary', 'a-binary/v1.2/a-binary', fetcher=fetcher):
fetcher.download.assert_called_once_with('http://binaries.example.com/a-binary/v1.2/a-binary',
listener=mock.ANY,
path_or_fd=mock.ANY,
timeout_secs=42)
示例4: test_support_url_multi
# 需要導入模塊: from pants.binaries.binary_util import BinaryUtil [as 別名]
# 或者: from pants.binaries.binary_util.BinaryUtil import _select_binary_stream [as 別名]
def test_support_url_multi(self):
"""Tests to make sure existing base urls function as expected."""
count = 0
binary_util = BinaryUtil(
baseurls=[
'BLATANTLY INVALID URL',
'https://dl.bintray.com/pantsbuild/bin/reasonably-invalid-url',
'https://dl.bintray.com/pantsbuild/bin/build-support',
'https://dl.bintray.com/pantsbuild/bin/build-support', # Test duplicate entry handling.
'https://dl.bintray.com/pantsbuild/bin/another-invalid-url',
],
timeout_secs=30,
bootstrapdir='/tmp')
with binary_util._select_binary_stream(supportdir='bin/protobuf',
version='2.4.1',
name='protoc') as stream:
stream()
count += 1
self.assertEqual(count, 1)
示例5: test_support_url_multi
# 需要導入模塊: from pants.binaries.binary_util import BinaryUtil [as 別名]
# 或者: from pants.binaries.binary_util.BinaryUtil import _select_binary_stream [as 別名]
def test_support_url_multi(self):
"""Tests to make sure existing base urls function as expected."""
with temporary_dir() as invalid_local_files, temporary_dir() as valid_local_files:
binary_util = BinaryUtil(
baseurls=[
'BLATANTLY INVALID URL',
'https://dl.bintray.com/pantsbuild/bin/reasonably-invalid-url',
invalid_local_files,
valid_local_files,
'https://dl.bintray.com/pantsbuild/bin/another-invalid-url',
],
timeout_secs=30,
bootstrapdir='/tmp')
binary_path = binary_util._select_binary_base_path(supportdir='bin/protobuf',
version='2.4.1',
name='protoc')
contents = b'proof'
with safe_open(os.path.join(valid_local_files, binary_path), 'wb') as fp:
fp.write(contents)
with binary_util._select_binary_stream(name='protoc', binary_path=binary_path) as stream:
self.assertEqual(contents, stream())