本文整理汇总了Python中testtools.matchers.HasLength方法的典型用法代码示例。如果您正苦于以下问题:Python matchers.HasLength方法的具体用法?Python matchers.HasLength怎么用?Python matchers.HasLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testtools.matchers
的用法示例。
在下文中一共展示了matchers.HasLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_list_with_filters
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def test_list_with_filters(self):
with mock.patch.object(self.dbapi, 'list_containers',
autospec=True) as mock_get_list:
mock_get_list.return_value = [self.fake_capsule]
filt = {'status': 'Running'}
capsules = objects.Capsule.list(self.context,
filters=filt)
self.assertEqual(1, mock_get_list.call_count)
self.assertThat(capsules, HasLength(1))
self.assertIsInstance(capsules[0], objects.Capsule)
self.assertEqual(self.context, capsules[0]._context)
mock_get_list.assert_called_once_with(self.context,
consts.TYPE_CAPSULE,
filters=filt,
limit=None, marker=None,
sort_key=None, sort_dir=None)
示例2: test_list_with_filters
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def test_list_with_filters(self):
with mock.patch.object(self.dbapi, 'list_containers',
autospec=True) as mock_get_list:
mock_get_list.return_value = [self.fake_container]
filt = {'status': 'Running'}
containers = objects.Container.list(self.context,
filters=filt)
self.assertEqual(1, mock_get_list.call_count)
self.assertThat(containers, HasLength(1))
self.assertIsInstance(containers[0], objects.Container)
self.assertEqual(self.context, containers[0]._context)
mock_get_list.assert_called_once_with(self.context,
consts.TYPE_CONTAINER,
filters=filt,
limit=None, marker=None,
sort_key=None, sort_dir=None)
示例3: test_collect_functions
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def test_collect_functions(self):
def f():
pass
def f_():
pass
def f__():
pass
context = contexts.Context()
context2 = context.create_child_context()
context3 = context2.create_child_context()
context.register_function(f)
context.register_function(f_)
context3.register_function(f__)
functions = context3.collect_functions('f')
self.assertThat(functions, testtools.matchers.HasLength(2))
self.assertThat(functions[0], testtools.matchers.HasLength(1))
self.assertThat(functions[1], testtools.matchers.HasLength(2))
示例4: test_delete_function
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def test_delete_function(self):
def f():
pass
def f_():
pass
context = contexts.Context()
context.register_function(f)
context2 = context.create_child_context()
context2.register_function(f_)
functions, is_exclusive = context2.get_functions('f')
spec = functions.pop()
self.assertIn(spec, context2)
context2.delete_function(spec)
self.assertNotIn(spec, context2)
functions, is_exclusive = context.get_functions('f')
self.assertThat(functions, matchers.HasLength(1))
示例5: test_list_with_filters
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def test_list_with_filters(self):
with mock.patch.object(self.dbapi, 'get_federation_list',
autospec=True) as mock_get_list:
mock_get_list.return_value = [self.fake_federation]
filters = {'name': 'federation1'}
federations = objects.Federation.list(self.context,
filters=filters)
mock_get_list.assert_called_once_with(self.context, sort_key=None,
sort_dir=None,
filters=filters, limit=None,
marker=None)
self.assertEqual(1, mock_get_list.call_count)
self.assertThat(federations, HasLength(1))
self.assertIsInstance(federations[0], objects.Federation)
self.assertEqual(self.context, federations[0]._context)
示例6: test_list_with_filters
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def test_list_with_filters(self, mock_cluster_template_get):
with mock.patch.object(self.dbapi, 'get_cluster_list',
autospec=True) as mock_get_list:
mock_get_list.return_value = [self.fake_cluster]
mock_cluster_template_get.return_value = self.fake_cluster_template
filters = {'name': 'cluster1'}
clusters = objects.Cluster.list(self.context, filters=filters)
mock_get_list.assert_called_once_with(self.context, sort_key=None,
sort_dir=None,
filters=filters, limit=None,
marker=None)
self.assertEqual(1, mock_get_list.call_count)
self.assertThat(clusters, HasLength(1))
self.assertIsInstance(clusters[0], objects.Cluster)
self.assertEqual(self.context, clusters[0]._context)
示例7: test_cleanup_pool
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def test_cleanup_pool(self):
self.test_get_context_manager()
newtime = time.time() + self.unused_timeout * 2
non_expired_connection = _memcache_pool._PoolItem(
ttl=(newtime * 2),
connection=mock.MagicMock())
self.connection_pool.queue.append(non_expired_connection)
self.assertThat(self.connection_pool.queue, matchers.HasLength(2))
with mock.patch.object(time, 'time', return_value=newtime):
conn = self.connection_pool.queue[0].connection
with self.connection_pool.acquire():
pass
conn.assert_has_calls(
[mock.call(self.connection_pool.destroyed_value)])
self.assertThat(self.connection_pool.queue, matchers.HasLength(1))
self.assertEqual(0, non_expired_connection.connection.call_count)
示例8: test_items_equals_given_limit
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def test_items_equals_given_limit(self, href_link_mock):
items = [
{"uuid": "123"}
]
req = mock.MagicMock()
params = mock.PropertyMock(return_value=dict(limit=1))
type(req).params = params
builder = common.ViewBuilder()
results = builder._get_collection_links(req, items,
mock.sentinel.coll_key,
"uuid")
href_link_mock.assert_called_once_with(req, "123",
mock.sentinel.coll_key)
self.assertThat(results, matchers.HasLength(1))
示例9: test_items_equals_default_limit
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def test_items_equals_default_limit(self, href_link_mock):
items = [
{"uuid": "123"}
]
req = mock.MagicMock()
params = mock.PropertyMock(return_value=dict())
type(req).params = params
self.flags(osapi_max_limit=1)
builder = common.ViewBuilder()
results = builder._get_collection_links(req, items,
mock.sentinel.coll_key,
"uuid")
href_link_mock.assert_called_once_with(req, "123",
mock.sentinel.coll_key)
self.assertThat(results, matchers.HasLength(1))
示例10: test_items_equals_default_limit_with_given
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def test_items_equals_default_limit_with_given(self, href_link_mock):
items = [
{"uuid": "123"}
]
req = mock.MagicMock()
# Given limit is greater than default max, only return default max
params = mock.PropertyMock(return_value=dict(limit=2))
type(req).params = params
self.flags(osapi_max_limit=1)
builder = common.ViewBuilder()
results = builder._get_collection_links(req, items,
mock.sentinel.coll_key,
"uuid")
href_link_mock.assert_called_once_with(req, "123",
mock.sentinel.coll_key)
self.assertThat(results, matchers.HasLength(1))
示例11: _assert_vertices_status
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def _assert_vertices_status(self, category, vitrage_type,
num_vertices, num_marked_deleted):
vertices = \
self.processor.entity_graph.get_vertices({
VProps.VITRAGE_CATEGORY: category,
VProps.VITRAGE_TYPE: vitrage_type,
})
self.assertThat(vertices, matchers.HasLength(num_vertices))
marked_deleted_vertices = \
self.processor.entity_graph.get_vertices({
VProps.VITRAGE_CATEGORY: category,
VProps.VITRAGE_TYPE: vitrage_type,
VProps.VITRAGE_IS_DELETED: True
})
self.assertThat(marked_deleted_vertices,
matchers.HasLength(num_marked_deleted))
示例12: test_get_topology_with_not_admin_project
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def test_get_topology_with_not_admin_project(self):
# Setup
graph = self._create_graph()
apis = TopologyApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': False}
# Action
graph_topology = apis.get_topology(
ctx,
graph_type='graph',
depth=10,
query=None,
root=None,
all_tenants=False)
graph_topology = decompress_obj(graph_topology)
# Test assertions
self.assertThat(graph_topology['nodes'], matchers.HasLength(7))
self._check_projects_entities(graph_topology['nodes'],
'project_2',
False)
示例13: test_get_topology_with_all_tenants
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def test_get_topology_with_all_tenants(self):
# Setup
graph = self._create_graph()
apis = TopologyApis(graph, self.api_lock)
ctx = {'tenant': 'project_1', 'is_admin': False}
# Action
graph_topology = apis.get_topology(
ctx,
graph_type='graph',
depth=10,
query=None,
root=None,
all_tenants=True)
graph_topology = decompress_obj(graph_topology)
# Test assertions
self.assertThat(graph_topology['nodes'], matchers.HasLength(12))
示例14: test_resource_list_with_admin_project_and_query
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def test_resource_list_with_admin_project_and_query(self):
# Setup
graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': True}
# Action
resources = apis.get_resources(
ctx,
resource_type=NOVA_INSTANCE_DATASOURCE,
all_tenants=False,
query={'==': {'id': 'instance_3'}})
resources = decompress_obj(resources)['resources']
# Test assertions
self.assertThat(resources, matchers.HasLength(1))
示例15: _add_template_with_missing_param
# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import HasLength [as 别名]
def _add_template_with_missing_param(self, template_filename):
# Setup
files_content = self._load_template_content(template_filename)
params = {'template_name': 'template_with_params_3',
'alarm_name': 'My alarm', 'new_state': 'SUBOPTIMAL'}
# Action
added_templates = \
self.apis.add_template(ctx=None, templates=files_content,
template_type=None, params=params)
self.added_template = added_templates[0]['uuid']
# Test assertions
self.assertThat(added_templates, matchers.HasLength(1))
self.assertEqual('ERROR', added_templates[0]['status'])
self.assert_starts_with('Failed to resolve parameter',
added_templates[0]['status details'])