本文整理汇总了Python中six.assertCountEqual函数的典型用法代码示例。如果您正苦于以下问题:Python assertCountEqual函数的具体用法?Python assertCountEqual怎么用?Python assertCountEqual使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assertCountEqual函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_write_genre_list
def test_write_genre_list(self):
mediafile = self._mediafile_fixture('empty')
mediafile.genres = [u'one', u'two']
mediafile.save()
mediafile = MediaFile(mediafile.path)
assertCountEqual(self, mediafile.genres, [u'one', u'two'])
示例2: test_with_binary_media_types
def test_with_binary_media_types(self):
template = {
"Resources": {
"Api1": {
"Type": "AWS::Serverless::Api",
"Properties": {
"StageName": "Prod",
"DefinitionBody": make_swagger(self.input_apis, binary_media_types=self.binary_types)
}
}
}
}
expected_binary_types = sorted(self.binary_types)
expected_apis = [
Api(path="/path1", method="GET", function_name="SamFunc1", cors=None,
binary_media_types=expected_binary_types),
Api(path="/path1", method="POST", function_name="SamFunc1", cors=None,
binary_media_types=expected_binary_types),
Api(path="/path2", method="PUT", function_name="SamFunc1", cors=None,
binary_media_types=expected_binary_types),
Api(path="/path2", method="GET", function_name="SamFunc1", cors=None,
binary_media_types=expected_binary_types),
Api(path="/path3", method="DELETE", function_name="SamFunc1", cors=None,
binary_media_types=expected_binary_types)
]
provider = SamApiProvider(template)
assertCountEqual(self, expected_apis, provider.apis)
示例3: test_must_prefer_implicit_api_over_explicit
def test_must_prefer_implicit_api_over_explicit(self):
implicit_apis = {
"Event1": {
"Type": "Api",
"Properties": {
# This API is duplicated between implicit & explicit
"Path": "/path1",
"Method": "get"
}
},
"Event2": {
"Type": "Api",
"Properties": {
"Path": "/path2",
"Method": "POST"
}
}
}
self.template["Resources"]["Api1"]["Properties"]["DefinitionBody"] = self.swagger
self.template["Resources"]["ImplicitFunc"]["Properties"]["Events"] = implicit_apis
expected_apis = [
Api(path="/path1", method="GET", function_name="ImplicitFunc", cors=None), # Comes from Implicit
Api(path="/path2", method="GET", function_name="explicitfunction", cors=None),
Api(path="/path2", method="POST", function_name="ImplicitFunc", cors=None), # Comes from implicit
Api(path="/path3", method="GET", function_name="explicitfunction", cors=None),
]
provider = SamApiProvider(self.template)
assertCountEqual(self, expected_apis, provider.apis)
示例4: test_fit_and_transform
def test_fit_and_transform(self):
augmenter = FeatureAugmenter(column_value="val", column_id="id", column_sort="sort",
column_kind="kind",
kind_to_fc_parameters=self.kind_to_fc_parameters)
# Fit should do nothing
returned_df = augmenter.fit()
six.assertCountEqual(self, returned_df.__dict__, augmenter.__dict__)
self.assertRaises(RuntimeError, augmenter.transform, None)
augmenter.set_timeseries_container(self.test_df)
# Add features to all time series
X_with_index = pd.DataFrame([{"feature_1": 1}]*2, index=[10, 500])
X_transformed = augmenter.transform(X_with_index)
# Require same shape
for i in X_transformed.index:
self.assertIn(i, X_with_index.index)
for i in X_with_index.index:
self.assertIn(i, X_transformed.index)
self.assertEqual(X_transformed.shape, (2, 3))
# Preserve old features
six.assertCountEqual(self, list(X_transformed.columns), ["feature_1", "a__length", "b__length"])
# Features are not allowed to be NaN
for index, row in X_transformed.iterrows():
print((index, row))
self.assertFalse(np.isnan(row["a__length"]))
self.assertFalse(np.isnan(row["b__length"]))
示例5: test_with_swagger_as_both_body_and_uri
def test_with_swagger_as_both_body_and_uri(self, SamSwaggerReaderMock):
body = {"some": "body"}
filename = "somefile.txt"
template = {
"Resources": {
"Api1": {
"Type": "AWS::Serverless::Api",
"Properties": {
"StageName": "Prod",
"DefinitionUri": filename,
"DefinitionBody": body
}
}
}
}
SamSwaggerReaderMock.return_value.read.return_value = make_swagger(self.input_apis)
cwd = "foo"
provider = SamApiProvider(template, cwd=cwd)
assertCountEqual(self, self.input_apis, provider.apis)
SamSwaggerReaderMock.assert_called_with(definition_body=body, definition_uri=filename, working_dir=cwd)
示例6: test_get_multiple_albums_by_id
def test_get_multiple_albums_by_id(self):
response = self.client.get('/album/1,2')
response.json = json.loads(response.data.decode('utf-8'))
self.assertEqual(response.status_code, 200)
response_albums = [album['album'] for album in response.json['albums']]
assertCountEqual(self, response_albums, [u'album', u'another album'])
示例7: test_delete_stacks_uses_the_correct_order
def test_delete_stacks_uses_the_correct_order(self,
custom_resource_mock,
stack_mock,
template_loader_mock,
dependency_resolver_mock,
parameter_resolver_mock,
cfn_mock):
dependency_resolver_mock.return_value.get_stack_order.return_value = ['a', 'c']
cfn_mock.return_value.get_stack_names.return_value = ['a', 'c']
stack_a = CloudFormationStack('', [], 'a', '')
stack_c = CloudFormationStack('', [], 'c', '')
def stack_side_effect(*args):
if args[2] == 'a':
return stack_a
if args[2] == 'c':
return stack_c
return None
stack_mock.side_effect = stack_side_effect
handler = StackActionHandler(Mock())
handler.delete_stacks()
expected_calls = [call(stack_c), call(stack_a)]
six.assertCountEqual(self, expected_calls, cfn_mock.return_value.delete_stack.mock_calls)
示例8: test_group
def test_group(self):
assign_perm("view_collection", self.group1, self.collection)
assign_perm("edit_collection", self.group1, self.collection)
user_perms, group_perms = get_user_group_perms(self.group1, self.collection)
self.assertEqual(len(group_perms), 1)
six.assertCountEqual(self, group_perms[0][2], ["view_collection", "edit_collection"])
self.assertEqual(len(user_perms), 0)
示例9: test_numeric_range_filter
def test_numeric_range_filter(self):
# https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
numeric_range_filter_options = {
"fields": ["start", "end", "age"],
"field_validators": {
"start": ["date"],
"end": ["date"],
}
}
filter = filters.NumericRangeFilter
query_params = {'start.gte': '2016-01-01', 'start.lte': '2001-06-01', 'start.tz': 'Pacific/Auckland', 'age.gt': '18'}
queryset = self.get_queryset_for_filter(filter=filter, query_params=query_params,
options=numeric_range_filter_options)
self.assertEqual(len(queryset.filters), 2)
self.assertEqual(len(queryset.queries), 0)
# raw
six.assertCountEqual(self, queryset.filters,[
('range', {'start': {'gte': '2016-01-01', 'lte': '2001-06-01', 'time_zone': 'Pacific/Auckland'}}),
('range', {'age': {'gt': '18'}})
])
示例10: test_search_with_nodes_and_duplicate_label
def test_search_with_nodes_and_duplicate_label(self):
self.fake_authentication()
response = self.client.get(
'/%d/search' % self.test_project_id,
{'substring': 'uncertain end'})
self.assertEqual(response.status_code, 200)
parsed_response = json.loads(response.content.decode('utf-8'))
# Expect only one result that has a node linked
expected_result = [
{"id":2342, "name":"uncertain end", "class_name":"label", "nodes":[
{"id":403, "x":7840, "y":2380, "z":0, "skid":373}]},
]
six.assertCountEqual(self, expected_result, parsed_response)
# Add a duplicate record of the label, without any node links
label = ClassInstance.objects.get(id=2342)
label.id = None
label.save()
response2 = self.client.get(
'/%d/search' % self.test_project_id,
{'substring': 'uncertain end'})
self.assertEqual(response2.status_code, 200)
parsed_response2 = json.loads(response2.content.decode(('utf-8')))
# Expect the nodes to be not linked to the duplicate record
expected_result2 = [
{"id":label.id, "name":"uncertain end", "class_name":"label"},
{"id":2342, "name":"uncertain end", "class_name":"label", "nodes":[
{"id":403, "x":7840, "y":2380, "z":0, "skid":373}]}
]
six.assertCountEqual(self, expected_result2, parsed_response2)
示例11: test_parse_stream
def test_parse_stream(
self, structure_and_messages1, structure_and_messages2, structure_and_messages3
):
"""
L{Parser.parse_stream} returns an iterable of completed and then
incompleted tasks.
"""
_, messages1 = structure_and_messages1
_, messages2 = structure_and_messages2
_, messages3 = structure_and_messages3
# Need at least one non-dropped message in partial tree:
assume(len(messages3) > 1)
# Need unique UUIDs per task:
assume(
len(set(m[0][TASK_UUID_FIELD] for m in (messages1, messages2, messages3)))
== 3
)
# Two complete tasks, one incomplete task:
all_messages = (messages1, messages2, messages3[:-1])
all_tasks = list(
Parser.parse_stream(
[m for m in chain(*zip_longest(*all_messages)) if m is not None]
)
)
assertCountEqual(
self, all_tasks, [parse_to_task(msgs) for msgs in all_messages]
)
示例12: assertSearchResults
def assertSearchResults(self, results=None, resultCode=0):
"""
Shortcut for checking results returned by test server on LDAPSearchRequest.
Results must be prepared as a list of dictionaries with 'objectName' and 'attributes' keys
"""
if results is None:
results = []
messages = []
for result in results:
message = pureldap.LDAPMessage(
pureldap.LDAPSearchResultEntry(
objectName=result['objectName'],
attributes=result['attributes']
),
id=2
)
messages.append(message)
messages.append(
pureldap.LDAPMessage(
pureldap.LDAPSearchResultDone(resultCode=resultCode),
id=2
)
)
six.assertCountEqual(
self,
self._makeResultList(self.server.transport.value()),
[msg.toWire() for msg in messages]
)
示例13: test_uniform_noise_4_bots_no_noise_manhattan
def test_uniform_noise_4_bots_no_noise_manhattan(self):
test_layout = (
""" ##################
# #. . # . 2 #
# ##### #####3#
# 0 . # . .#1#
################## """)
universe = CTFUniverse.create(test_layout, 4)
noiser = ManhattanNoiser(universe.copy())
expected_0 = [ (1, 1), (3, 1), (4, 1), (5, 1), (6, 1),
(1, 2), (1, 3), (2, 3), (3, 3), (4, 3), (5, 3),
(6, 3), (7, 3), (7, 2) ]
position_bucket_0 = collections.defaultdict(int)
bot_2_pos = (13, 1)
position_bucket_2 = {bot_2_pos : 0}
for i in range(200):
new = noiser.uniform_noise(universe.copy(), 1)
self.assertTrue(new.bots[0].noisy)
self.assertFalse(new.bots[2].noisy)
position_bucket_0[new.bots[0].current_pos] += 1
position_bucket_2[new.bots[2].current_pos] += 1
self.assertEqual(200, sum(position_bucket_0.values()))
self.assertEqual(200, sum(position_bucket_2.values()))
# Since this is a randomized algorithm we need to be a bit lenient with
# our tests. We check that each position was selected at least once.
six.assertCountEqual(self, position_bucket_0, expected_0, position_bucket_0)
# bots should never have been noised
self.assertEqual(200, position_bucket_2[bot_2_pos])
示例14: test_uniform_noise_4_bots_a_star
def test_uniform_noise_4_bots_a_star(self):
test_layout = (
""" ##################
# #. 2. # . #
# ##### #####3#
# 0 . # . .#1#
################## """)
universe = CTFUniverse.create(test_layout, 4)
noiser = AStarNoiser(universe.copy())
expected_0 = [(1, 2), (7, 3), (1, 3), (3, 3), (6, 3),
(2, 3), (4, 3), (1, 1), (5, 3)]
position_bucket_0 = collections.defaultdict(int)
expected_2 = [(7, 3), (8, 2), (7, 1), (8, 1), (6, 1), (3, 1), (5, 1),
(4, 1), (7, 2)]
position_bucket_2 = collections.defaultdict(int)
for i in range(100):
new = noiser.uniform_noise(universe.copy(), 1)
self.assertTrue(new.bots[0].noisy)
self.assertTrue(new.bots[2].noisy)
position_bucket_0[new.bots[0].current_pos] += 1
position_bucket_2[new.bots[2].current_pos] += 1
self.assertEqual(100, sum(position_bucket_0.values()))
self.assertEqual(100, sum(position_bucket_2.values()))
# Since this is a randomized algorithm we need to be a bit lenient with
# our tests. We check that each position was selected at least once.
six.assertCountEqual(self, position_bucket_0, expected_0, sorted(position_bucket_0.keys()))
six.assertCountEqual(self, position_bucket_2, expected_2, sorted(position_bucket_2.keys()))
示例15: test_many_elements
def test_many_elements(self):
expected_data = []
for i in range(20):
self.d.add(i, i)
expected_data.append((i, i))
gevent.sleep(TestFlushingDict.FLUSH_LATENCY_SECONDS + 0.1)
six.assertCountEqual(self, expected_data, sum(self.received_data, []))