本文整理汇总了Python中botocore.loaders.Loader类的典型用法代码示例。如果您正苦于以下问题:Python Loader类的具体用法?Python Loader怎么用?Python Loader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Loader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ServiceWaiterFunctionalTest
class ServiceWaiterFunctionalTest(BaseEnvVar):
"""
This class is used as a base class if you want to functionally test the
waiters for a specific service.
"""
def setUp(self):
super(ServiceWaiterFunctionalTest, self).setUp()
self.data_path = os.path.join(
os.path.dirname(botocore.__file__), 'data')
self.environ['BOTO_DATA_PATH'] = self.data_path
self.loader = Loader(self.data_path)
def get_waiter_model(self, service, api_version=None):
"""Get the waiter model for the service."""
return WaiterModel(
self.loader.load_service_model(
service, type_name='waiters-2', api_version=api_version))
def get_service_model(self, service, api_version=None):
"""Get the service model for the service."""
return ServiceModel(
self.loader.load_service_model(
service, type_name='service-2', api_version=api_version),
service_name=service)
示例2: test_search_path_on_windows
def test_search_path_on_windows(self):
# On windows, the search path is separated by ';' chars.
self.environ['BOTO_DATA_PATH'] = 'c:\\path1;c:\\path2'
# The builtin botocore data path is added as the last element
# so we're only interested in checking the two that we've added.
loader = Loader(data_path=self.environ['BOTO_DATA_PATH'])
paths = loader.get_search_paths()[:-1]
self.assertEqual(paths, ['c:\\path1', 'c:\\path2'])
示例3: test_data_not_found_raises_exception
def test_data_not_found_raises_exception(self):
class FakeLoader(object):
def load_file(self, name):
# Returning None indicates that the
# loader couldn't find anything.
return None
loader = Loader(file_loader=FakeLoader())
with self.assertRaises(DataNotFoundError):
loader.load_data('baz')
示例4: test_load_service_model
def test_load_service_model(self):
class FakeLoader(object):
def load_file(self, name):
return ['loaded data']
loader = Loader(extra_search_paths=['foo'],
file_loader=FakeLoader(),
include_default_search_paths=False)
loader.determine_latest_version = mock.Mock(return_value='2015-03-01')
loaded = loader.load_service_model('baz', type_name='service-2')
self.assertEqual(loaded, ['loaded data'])
示例5: test_load_service_model_enforces_case
def test_load_service_model_enforces_case(self):
class FakeLoader(object):
def load_file(self, name):
return ['loaded data']
loader = Loader(extra_search_paths=['foo'],
file_loader=FakeLoader(),
include_default_search_paths=False)
loader.determine_latest_version = mock.Mock(return_value='2015-03-01')
loader.list_available_services = mock.Mock(return_value=['baz'])
with self.assertRaises(ValidationError):
loader.load_service_model('BAZ', type_name='service-2')
示例6: test_load_data_uses_loader
def test_load_data_uses_loader(self):
search_paths = ['foo', 'bar', 'baz']
class FakeLoader(object):
def load_file(self, name):
expected_ending = os.path.join('bar', 'baz')
if name.endswith(expected_ending):
return ['loaded data']
loader = Loader(extra_search_paths=search_paths,
file_loader=FakeLoader())
loaded = loader.load_data('baz')
self.assertEqual(loaded, ['loaded data'])
示例7: test_load_service_model_uses_provided_type_name
def test_load_service_model_uses_provided_type_name(self):
loader = Loader(extra_search_paths=['foo'],
file_loader=mock.Mock(),
include_default_search_paths=False)
loader.list_available_services = mock.Mock(return_value=['baz'])
# Should have a) the unknown service name and b) list of valid
# service names.
provided_type_name = 'not-service-2'
with self.assertRaisesRegexp(UnknownServiceError,
'Unknown service.*BAZ.*baz'):
loader.load_service_model(
'BAZ', type_name=provided_type_name)
loader.list_available_services.assert_called_with(provided_type_name)
示例8: test_load_service_model_enforces_case
def test_load_service_model_enforces_case(self):
class FakeLoader(object):
def load_file(self, name):
return ['loaded data']
loader = Loader(extra_search_paths=['foo'],
file_loader=FakeLoader(),
include_default_search_paths=False)
loader.determine_latest_version = mock.Mock(return_value='2015-03-01')
loader.list_available_services = mock.Mock(return_value=['baz'])
# Should have a) the unknown service name and b) list of valid
# service names.
with self.assertRaisesRegexp(UnknownServiceError,
'Unknown service.*BAZ.*baz'):
loader.load_service_model('BAZ', type_name='service-2')
示例9: setUp
def setUp(self):
super(LoaderTestCase, self).setUp()
self.data_path = os.path.join(os.path.dirname(__file__), 'data')
self.environ['BOTO_DATA_PATH'] = self.data_path
self.loader = Loader(data_path=self.environ['BOTO_DATA_PATH'])
# Make sure the cache is clear.
self.loader._cache.clear()
示例10: _test_model_is_not_lost
def _test_model_is_not_lost(service_name, type_name,
previous_version, latest_version):
# Make sure if a paginator and/or waiter exists in previous version,
# there will be a successor existing in latest version.
loader = Loader()
try:
previous = loader.load_service_model(
service_name, type_name, previous_version)
except DataNotFoundError:
pass
else:
try:
latest = loader.load_service_model(
service_name, type_name, latest_version)
except DataNotFoundError as e:
raise AssertionError(
"%s must exist for %s: %s" % (type_name, service_name, e))
示例11: test_load_data_overridden
def test_load_data_overridden(self):
self.overrides_path = os.path.join(
os.path.dirname(__file__),
'data_overrides'
)
self.environ['BOTO_DATA_PATH'] = "{0}{1}{2}".format(
self.overrides_path,
os.pathsep,
self.data_path
)
loader = Loader(data_path=self.environ['BOTO_DATA_PATH'])
# This should load the data the first data it finds.
data = loader.load_service_model(
'someservice',
api_version='2012-10-01'
)
# An overridden key.
self.assertEqual(data['api_version'], '2012-10-01')
# A key unique to the base.
self.assertEqual(data['something-else'], 'another')
# Ensure a key present in other variants is not there.
self.assertTrue('Purpose' not in data)
示例12: setUp
def setUp(self):
super(TestMergeExtras, self).setUp()
self.file_loader = mock.Mock()
self.data_loader = Loader(
extra_search_paths=['datapath'], file_loader=self.file_loader,
include_default_search_paths=False)
self.data_loader.determine_latest_version = mock.Mock(
return_value='2015-03-01')
self.data_loader.list_available_services = mock.Mock(
return_value=['myservice'])
isdir_mock = mock.Mock(return_value=True)
self.isdir_patch = mock.patch('os.path.isdir', isdir_mock)
self.isdir_patch.start()
示例13: ServiceWaiterFunctionalTest
class ServiceWaiterFunctionalTest(BaseEnvVar):
"""
This class is used as a base class if you want to functionally test the
waiters for a specific service.
"""
def setUp(self):
super(ServiceWaiterFunctionalTest, self).setUp()
self.data_path = os.path.join(
os.path.dirname(botocore.__file__), 'data')
self.environ['BOTO_DATA_PATH'] = self.data_path
self.loader = Loader(self.data_path)
def get_waiter_model(self, service, api_version=None):
"""
Get the waiter model for the service
"""
service = os.path.join('aws', service)
model_version = self.loader.determine_latest(service, api_version)
# Some wierd formatting required to get the name of the model
# correct. Right now this is returned: YYYY-MM-DD.api
# We need: YYYY-MM-DD
model_version = ''.join(model_version.split('.')[:-1])
waiter_model = model_version + '.waiters'
return WaiterModel(self.loader.load_data(waiter_model))
示例14: test_include_default_extras
def test_include_default_extras(self):
self.data_loader = Loader(
extra_search_paths=['datapath'], file_loader=self.file_loader,
include_default_search_paths=False,
include_default_extras=False)
self.data_loader.determine_latest_version = mock.Mock(
return_value='2015-03-01')
self.data_loader.list_available_services = mock.Mock(
return_value=['myservice'])
service_data = {'foo': 'service', 'bar': 'service'}
service_data_copy = copy.copy(service_data)
sdk_extras = {'merge': {'foo': 'sdk'}}
self.file_loader.load_file.side_effect = [service_data, sdk_extras]
loaded = self.data_loader.load_service_model('myservice', 'service-2')
self.assertEqual(loaded, service_data_copy)
示例15: TestMergeExtras
class TestMergeExtras(BaseEnvVar):
def setUp(self):
super(TestMergeExtras, self).setUp()
self.file_loader = mock.Mock()
self.data_loader = Loader(
extra_search_paths=['datapath'], file_loader=self.file_loader,
include_default_search_paths=False)
self.data_loader.determine_latest_version = mock.Mock(
return_value='2015-03-01')
self.data_loader.list_available_services = mock.Mock(
return_value=['myservice'])
isdir_mock = mock.Mock(return_value=True)
self.isdir_patch = mock.patch('os.path.isdir', isdir_mock)
self.isdir_patch.start()
def tearDown(self):
super(TestMergeExtras, self).tearDown()
self.isdir_patch.stop()
def test_merge_extras(self):
service_data = {'foo': 'service', 'bar': 'service'}
sdk_extras = {'merge': {'foo': 'sdk'}}
self.file_loader.load_file.side_effect = [service_data, sdk_extras]
loaded = self.data_loader.load_service_model('myservice', 'service-2')
expected = {'foo': 'sdk', 'bar': 'service'}
self.assertEqual(loaded, expected)
call_args = self.file_loader.load_file.call_args_list
call_args = [c[0][0] for c in call_args]
base_path = os.path.join('datapath', 'myservice', '2015-03-01')
expected_call_args = [
os.path.join(base_path, 'service-2'),
os.path.join(base_path, 'service-2.sdk-extras')
]
self.assertEqual(call_args, expected_call_args)
def test_extras_not_found(self):
service_data = {'foo': 'service', 'bar': 'service'}
service_data_copy = copy.copy(service_data)
self.file_loader.load_file.side_effect = [service_data, None]
loaded = self.data_loader.load_service_model('myservice', 'service-2')
self.assertEqual(loaded, service_data_copy)
def test_no_merge_in_extras(self):
service_data = {'foo': 'service', 'bar': 'service'}
service_data_copy = copy.copy(service_data)
self.file_loader.load_file.side_effect = [service_data, {}]
loaded = self.data_loader.load_service_model('myservice', 'service-2')
self.assertEqual(loaded, service_data_copy)
def test_include_default_extras(self):
self.data_loader = Loader(
extra_search_paths=['datapath'], file_loader=self.file_loader,
include_default_search_paths=False,
include_default_extras=False)
self.data_loader.determine_latest_version = mock.Mock(
return_value='2015-03-01')
self.data_loader.list_available_services = mock.Mock(
return_value=['myservice'])
service_data = {'foo': 'service', 'bar': 'service'}
service_data_copy = copy.copy(service_data)
sdk_extras = {'merge': {'foo': 'sdk'}}
self.file_loader.load_file.side_effect = [service_data, sdk_extras]
loaded = self.data_loader.load_service_model('myservice', 'service-2')
self.assertEqual(loaded, service_data_copy)
def test_append_extra_type(self):
service_data = {'foo': 'service', 'bar': 'service'}
sdk_extras = {'merge': {'foo': 'sdk'}}
cli_extras = {'merge': {'cli': True}}
self.file_loader.load_file.side_effect = [
service_data, sdk_extras, cli_extras]
self.data_loader.extras_types.append('cli')
loaded = self.data_loader.load_service_model('myservice', 'service-2')
expected = {'foo': 'sdk', 'bar': 'service', 'cli': True}
self.assertEqual(loaded, expected)
call_args = self.file_loader.load_file.call_args_list
call_args = [c[0][0] for c in call_args]
base_path = os.path.join('datapath', 'myservice', '2015-03-01')
expected_call_args = [
os.path.join(base_path, 'service-2'),
os.path.join(base_path, 'service-2.sdk-extras'),
os.path.join(base_path, 'service-2.cli-extras')
]
self.assertEqual(call_args, expected_call_args)
def test_sdk_empty_extras_skipped(self):
service_data = {'foo': 'service', 'bar': 'service'}
cli_extras = {'merge': {'foo': 'cli'}}
self.file_loader.load_file.side_effect = [
service_data, None, cli_extras]
#.........这里部分代码省略.........