本文整理汇总了Python中unittest.mock.MagicMock.assert_any_call方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.assert_any_call方法的具体用法?Python MagicMock.assert_any_call怎么用?Python MagicMock.assert_any_call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.assert_any_call方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_validator_call
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_any_call [as 别名]
def test_validator_call(self):
validator = MagicMock()
attr_val = {
'attr1': validator,
'attr2': validator,
}
with patch('bundlewrap.items.symlinks.ATTRIBUTE_VALIDATORS', new=attr_val):
symlinks.Symlink.validate_attributes(
MagicMock(),
"symlink:/foo",
{'attr1': 1, 'attr2': 2},
)
validator.assert_any_call("symlink:/foo", 1)
validator.assert_any_call("symlink:/foo", 2)
self.assertEqual(validator.call_count, 2)
示例2: test_run
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_any_call [as 别名]
def test_run(self):
mock_function_1 = MagicMock(name="mock_function_1", return_value=5)
mock_function_2 = MagicMock(name="mock_function_2", return_value=10)
args = [1, 2, 3]
kwargs = {"end": "\n", "sep": " "}
function_item_1 = FunctionItem("function_item_1", mock_function_1)
function_item_2 = FunctionItem("function_item_2", mock_function_2, args, kwargs)
function_item_1.action()
function_item_2.action()
self.assertEqual(function_item_1.get_return(), 5)
self.assertEqual(function_item_2.get_return(), 10)
mock_function_1.assert_any_call()
mock_function_2.assert_called_once_with(*args, **kwargs)
示例3: test_validator_call
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_any_call [as 别名]
def test_validator_call(self):
validator = MagicMock()
attr_val = {
'attr1': validator,
'attr2': validator,
}
with patch('bundlewrap.items.files.ATTRIBUTE_VALIDATORS', new=attr_val):
files.File.validate_attributes(
MagicMock(),
"item:id",
{
'attr1': 1,
'attr2': 2,
},
)
validator.assert_any_call("item:id", 1)
validator.assert_any_call("item:id", 2)
self.assertEqual(validator.call_count, 2)
示例4: test_exception
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_any_call [as 别名]
def test_exception(self):
"""
A raised exception gets re-raised
"""
saved_get_logger = process.multiprocessing.get_logger
mock_logger = MagicMock()
def addHandler(ignore):
mock_logger.handlers = [MagicMock()]
mock_logger.addHandler = addHandler
mock_logger.handlers = False
mock_get_logger = MagicMock()
mock_get_logger.return_value = mock_logger
process.multiprocessing.get_logger = mock_get_logger
self.addCleanup(setattr, process.multiprocessing, 'get_logger', saved_get_logger)
def func():
raise AttributeError
l = ProcessLogger(func)
self.assertRaises(AttributeError, l)
mock_get_logger.assert_any_call()
示例5: test_run_custom_factory
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_any_call [as 别名]
def test_run_custom_factory():
import icap.server
assert icap.server._server is None
factory = MagicMock()
with patch("asyncio.get_event_loop") as get_event_loop:
run(factory_class=factory, foo="bar")
factory.assert_any_call(foo="bar")
get_event_loop.assert_any_call()
loop = get_event_loop.return_value
loop.create_server.assert_any_call(factory.return_value, "127.0.0.1", 1334)
server = loop.run_until_complete.return_value
assert icap.server._server == server
stop()
示例6: RunTests
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_any_call [as 别名]
class RunTests(unittest.TestCase):
def setUp(self):
os.environ['kubeproxy'] = "mock8s-host"
os.environ['k8spassword'] = "mock8s-admin-pass"
requests_patcher = patch("deployment.gce.requests")
self.mock_requests = requests_patcher.start()
self.mock_runner = MagicMock()
all_patcher = patch(
'deployment.runners.runners.all',
return_value=[self.mock_runner],
)
all_patcher.start()
self.get_cursor_patcher = patch("deployment.gce.get_cursor")
self.mock_get_cursor = self.get_cursor_patcher.start()
self.mock_get_cursor.return_value.fetchall.return_value = (
[("mock_service_name",
"mock_branch_name",
789, # mock config id
"mock-key=mock-value\nmk=mv\n",
"mock_env_name",
"mockcommithash",
"mock_image_name",
"mock_settings",)]
)
def tearDown(self):
patch.stopall()
def test_gc_repcons(self):
""" Should delete all but the given repcon for the service """
# set up
mock_return = MagicMock()
mock_return.json.return_value = {
'items': [
{
'metadata': {
'name': 'mockfirstname',
'selfLink': '/api/v1/mockfirstselflink',
}
},
{
'metadata': {
'name': 'mocksecondname',
'selfLink': '/api/v1/mocksecondselflink',
}
},
{
'metadata': {
'name': make_rc_name(
'mock_branch_name',
'mock_environment_name',
'mock_commit_hash',
'mock_config_id'
),
'selfLink': '/api/v1/mockmatchingselflink',
}
},
],
"status": {"replicas": 0},
}
self.mock_requests.get.return_value = mock_return
# run SUT
gc_repcons(
'mock_service_name',
'mock_branch_name',
'mock_environment_name',
'mock_commit_hash',
'mock_config_id',
)
# confirm asumptions
# should have gotten the correctly labeled rcs
self.mock_requests.get.assert_any_call(
"http://mock8s-host/api/v1/namespaces/default/replicationcontrollers",
params={
"labelSelector": "service=mock_service_name-mock_branch_name",
},
)
# should have scaled down what came back to 0 other than the current one
self.mock_requests.patch.assert_any_call(
'http://mock8s-host/api/v1/mockfirstselflink',
data='{"spec": {"replicas": 0}}',
headers={"Content-Type": "application/merge-patch+json"},
)
self.mock_requests.patch.assert_any_call(
'http://mock8s-host/api/v1/mocksecondselflink',
data='{"spec": {"replicas": 0}}',
headers={"Content-Type": "application/merge-patch+json"},
)
# actually now that we are just deleting all of the repcons (to get
# updated config), we want to see 3 here.
self.assertEqual(self.mock_requests.patch.call_count, 3)
# should have deleted what came back other than the current one
#.........这里部分代码省略.........
示例7: test_cf_resources
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_any_call [as 别名]
def test_cf_resources(monkeypatch):
summary = [{'LastUpdatedTimestamp': datetime(2016, 7, 20, 7, 3, 7,
108000,
tzinfo=timezone.utc),
'LogicalResourceId': 'AppLoadBalancer',
'PhysicalResourceId': 'myapp1-1',
'ResourceStatus': 'CREATE_COMPLETE',
'ResourceType': 'AWS::ElasticLoadBalancing::LoadBalancer'},
{'LastUpdatedTimestamp': datetime(2016, 7, 20, 7, 3,
45, 70000,
tzinfo=timezone.utc),
'LogicalResourceId': 'AppLoadBalancerMainDomain',
'PhysicalResourceId': 'myapp1.example.com',
'ResourceStatus': 'CREATE_COMPLETE',
'ResourceType': 'AWS::Route53::RecordSet'},
{'LastUpdatedTimestamp': datetime(2016, 7, 20, 7, 3,
45, 70000,
tzinfo=timezone.utc),
'LogicalResourceId': 'ThisWillBeIgnored',
'ResourceStatus': 'CREATE_COMPLETE',
'ResourceType': 'AWS::Route53::RecordSet'},
{'LastUpdatedTimestamp': datetime(2016, 7, 20, 7, 3,
43, 871000,
tzinfo=timezone.utc),
'LogicalResourceId': 'AppLoadBalancerVersionDomain',
'PhysicalResourceId': 'myapp1-1.example.com',
'ResourceStatus': 'CREATE_COMPLETE',
'ResourceType': 'AWS::Route53::RecordSet'},
{'LastUpdatedTimestamp': datetime(2016, 7, 20, 7, 7,
38, 495000,
tzinfo=timezone.utc),
'LogicalResourceId': 'AppServer',
'PhysicalResourceId': 'myapp1-1-AppServer-00000',
'ResourceStatus': 'CREATE_COMPLETE',
'ResourceType': 'AWS::AutoScaling::AutoScalingGroup'},
{'LastUpdatedTimestamp': datetime(2016, 7, 20, 7, 5,
10, 48000,
tzinfo=timezone.utc),
'LogicalResourceId': 'AppServerConfig',
'PhysicalResourceId': 'myapp1-1-AppServerConfig-00000',
'ResourceStatus': 'CREATE_COMPLETE',
'ResourceType': 'AWS::AutoScaling::LaunchConfiguration'},
{'LastUpdatedTimestamp': datetime(2016, 7, 20, 7, 5, 6,
745000,
tzinfo=timezone.utc),
'LogicalResourceId': 'AppServerInstanceProfile',
'PhysicalResourceId': 'myapp1-1-AppServerInstanceProfile-000',
'ResourceStatus': 'CREATE_COMPLETE',
'ResourceType': 'AWS::IAM::InstanceProfile'}]
response = {'ResponseMetadata': {'HTTPStatusCode': 200,
'RequestId': '0000'},
'StackResourceSummaries': summary}
mock_client = MagicMock()
mock_client.return_value = mock_client
mock_client.list_stack_resources.return_value = response
mock_client.describe_stacks.return_value = MOCK_STACK1
monkeypatch.setattr('boto3.client', mock_client)
mock_route53 = MagicMock()
mock_route53.side_effect = [[MagicMock(set_identifier=None)],
[MagicMock(set_identifier='myapp-42')]]
monkeypatch.setattr('senza.manaus.cloudformation.Route53.get_records',
mock_route53)
stack = CloudFormationStack.get_by_stack_name('myapp')
resources = list(stack.resources)
mock_route53.assert_any_call(name='myapp1.example.com')
mock_route53.assert_any_call(name='myapp1-1.example.com')
assert len(resources) == 2