本文整理汇总了Python中mock.call.info函数的典型用法代码示例。如果您正苦于以下问题:Python info函数的具体用法?Python info怎么用?Python info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_services
def test_update_services(self):
mock_as_foo = Mock(spec_set=AwsLimit)
mock_as_bar = Mock(spec_set=AwsLimit)
mock_ec2_baz = Mock(spec_set=AwsLimit)
mock_vpc = Mock(spec_set=AwsLimit)
ta_services = {
'AutoScaling': {
'foo': mock_as_foo,
'bar': mock_as_bar
},
'EC2': {
'baz': mock_ec2_baz
},
'VPC': {
'VPC Elastic IP addresses (EIPs)': mock_vpc
},
}
ta_results = {
'AutoScaling': {
'foo': 20,
'bar': 40,
},
'EC2': {
'baz': 5,
'blam': 10,
},
'OtherService': {
'blarg': 1,
},
'VPC': {
'VPC Elastic IP addresses (EIPs)': 11,
}
}
with patch('awslimitchecker.trustedadvisor'
'.logger', autospec=True) as mock_logger:
self.cls.ta_services = ta_services
self.cls._update_services(ta_results)
assert mock_logger.mock_calls == [
call.debug("Updating TA limits on all services"),
call.info("TrustedAdvisor returned check results for unknown "
"limit '%s' (service %s)", 'blam', 'EC2'),
call.info("TrustedAdvisor returned check results for unknown "
"service '%s'", 'OtherService'),
call.info("Done updating TA limits on all services"),
]
assert mock_as_foo.mock_calls == [
call._set_ta_limit(20)
]
assert mock_as_bar.mock_calls == [
call._set_ta_limit(40)
]
assert mock_ec2_baz.mock_calls == [
call._set_ta_limit(5)
]
assert mock_vpc.mock_calls == [
call._set_ta_limit(11)
]
示例2: test_update_services
def test_update_services(self):
def se_set(lname, val):
if lname == 'blam':
raise ValueError("foo")
mock_autoscale = Mock(spec_set=_AwsService)
mock_ec2 = Mock(spec_set=_AwsService)
mock_ec2._set_ta_limit.side_effect = se_set
mock_vpc = Mock(spec_set=_AwsService)
services = {
'AutoScaling': mock_autoscale,
'EC2': mock_ec2,
'VPC': mock_vpc,
}
ta_results = {
'AutoScaling': {
'foo': 20,
'bar': 40,
},
'EC2': {
'baz': 5,
'blam': 10,
},
'OtherService': {
'blarg': 1,
},
'VPC': {
'VPC Elastic IP addresses (EIPs)': 11,
}
}
with patch('awslimitchecker.trustedadvisor'
'.logger', autospec=True) as mock_logger:
self.cls._update_services(ta_results, services)
assert mock_logger.mock_calls == [
call.debug("Updating TA limits on all services"),
call.info("TrustedAdvisor returned check results for unknown "
"limit '%s' (service %s)", 'blam', 'EC2'),
call.info("TrustedAdvisor returned check results for unknown "
"service '%s'", 'OtherService'),
call.info("Done updating TA limits on all services"),
]
assert mock_autoscale.mock_calls == [
call._set_ta_limit('bar', 40),
call._set_ta_limit('foo', 20),
]
assert mock_ec2.mock_calls == [
call._set_ta_limit('baz', 5),
call._set_ta_limit('blam', 10),
call._set_ta_limit('VPC Elastic IP addresses (EIPs)', 11)
]
示例3: test_load
def test_load(self):
self._write_banks()
self._create_dealer()
self.dealer.load()
self.mocked_log.assert_has_calls(
[
call.debug("Loading banks"),
call.info("Loading features bank '%s'", BANK_PATH_1),
call.info("Loading features bank '%s'", BANK_PATH_2),
]
)
self.mocked_log.warning.assert_not_called()
示例4: test_poll_dont_have_ta
def test_poll_dont_have_ta(self):
self.cls.have_ta = False
tmp = self.mock_conn.describe_trusted_advisor_check_result
with patch('%s._get_limit_check_id' % pb, autospec=True) as mock_id:
with patch('awslimitchecker.trustedadvisor'
'.logger', autospec=True) as mock_logger:
res = self.cls._poll()
assert tmp.mock_calls == []
assert mock_id.mock_calls == [
call(self.cls)
]
assert mock_logger.mock_calls == [
call.info('Beginning TrustedAdvisor poll'),
call.info('TrustedAdvisor.have_ta is False; not polling TA')
]
assert res == {}
示例5: test_healthcheck_no_active
def test_healthcheck_no_active(self):
type(self.mock_redir).active_node_ip_port = None
type(self.mock_redir).log_enabled = True
if sys.version_info[0] < 3:
type(self.mock_request).uri = '/vault-redirector-health'
type(self.mock_request).path = '/vault-redirector-health'
expected = 'foobar'
expected_msg = 'No Active Vault'
else:
# in py3 these are byte literals
type(self.mock_request).uri = b'/vault-redirector-health'
type(self.mock_request).path = b'/vault-redirector-health'
expected = b'foobar'
expected_msg = b'No Active Vault'
with patch('%s.logger' % pbm) as mock_logger:
with patch('%s.VaultRedirectorSite.status_response' % pbm
) as mock_status:
mock_status.return_value = 'foobar'
resp = self.cls.healthcheck(self.mock_request)
assert self.mock_request.mock_calls == [
call.setResponseCode(503, message=expected_msg),
call.setHeader("Content-Type", "application/json")
]
assert resp == expected
assert mock_logger.mock_calls == [
call.info('RESPOND %d for %s%s request for /vault-redirector-health'
' from %s:%s', 503, '', 'GET', '1.2.3.4', 12345)
]
示例6: test_get_api_id_aws
def test_get_api_id_aws(self):
def se_exc(*args, **kwargs):
raise Exception()
conf = Mock()
args = Mock(tf_path='tfpath')
with patch.multiple(
pbm,
autospec=True,
logger=DEFAULT,
TerraformRunner=DEFAULT,
AWSInfo=DEFAULT
) as mocks:
mocks['TerraformRunner'].return_value._get_outputs.side_effect = \
se_exc
mocks['AWSInfo'].return_value.get_api_id.return_value = 'myaid'
res = get_api_id(conf, args)
assert res == 'myaid'
assert mocks['TerraformRunner'].mock_calls == [
call(conf, 'tfpath'),
call()._get_outputs()
]
assert mocks['AWSInfo'].mock_calls == [
call(conf),
call().get_api_id()
]
assert mocks['logger'].mock_calls == [
call.debug('Trying to get Terraform rest_api_id output'),
call.info('Unable to find API rest_api_id from Terraform state; '
'querying AWS.', exc_info=1),
call.debug('AWS API ID: \'%s\'', 'myaid')
]
示例7: test_connect
def test_connect(self):
mock_conn = Mock()
mock_cc = Mock()
type(mock_cc).region_name = 'myregion'
type(mock_conn)._client_config = mock_cc
cls = ConnectableTester()
cls.api_name = 'myapi'
kwargs = {'foo': 'fooval', 'bar': 'barval'}
with patch('%s._boto3_connection_kwargs' % pb,
new_callable=PropertyMock, create=True) as mock_kwargs:
mock_kwargs.return_value = kwargs
with patch('%s.logger' % pbm) as mock_logger:
with patch('%s.boto3.client' % pbm) as mock_client:
mock_client.return_value = mock_conn
cls.connect()
assert mock_kwargs.mock_calls == [call()]
assert mock_logger.mock_calls == [
call.info("Connected to %s in region %s",
'myapi',
'myregion')
]
assert mock_client.mock_calls == [
call(
'myapi',
foo='fooval',
bar='barval'
)
]
assert cls.conn == mock_client.return_value
示例8: test_handle_input_on
def test_handle_input_on(self):
mock_evt = Mock(spec_set=InterruptEvent)
type(mock_evt).pin_num = 3
type(mock_evt).timestamp = 1234.5678
self.cls.current_values = [5, 5, 5, 5]
with patch('%s.handle_change' % pb) as mock_handle:
with patch('%s.logger' % pbm) as mock_logger:
with patch('%s.no_state_change' % pb) as mock_no_change:
with patch('%s.set_output' % pb) as mock_set:
mock_no_change.return_value = False
self.cls.handle_input_on(mock_evt)
assert mock_logger.mock_calls == [
call.info("Received ON event for pin %s", 3),
]
assert mock_handle.mock_calls == [call(3, 1, 1234.5678)]
assert self.mock_chip.mock_calls == []
assert self.opin0.mock_calls == []
assert self.opin1.mock_calls == []
assert self.opin2.mock_calls == []
assert self.opin3.mock_calls == []
assert self.cls.current_values == [5, 5, 5, 1]
assert mock_no_change.mock_calls == [call(3, 1)]
assert mock_set.mock_calls == [call(3, 1)]
示例9: test_dont_log_stderr_on_success_if_disabled
def test_dont_log_stderr_on_success_if_disabled(self, proc, file, logger):
proc.return_value.returncode = 0
file.return_value = BytesIO(b'stderr')
job = TestLogStderrOnFailureOnlyTask()
job.run()
self.assertNotIn(call.info('Program stderr:\nstderr'), logger.mock_calls)
示例10: test_render
def test_render(self):
expected_location = 'http://mynode:1234/foo/bar'
expected_server = 'vault-redirector/%s/TwistedWeb/16.1.0' % _VERSION
if sys.version_info[0] < 3:
type(self.mock_request).uri = '/foo/bar'
type(self.mock_request).path = '/foo/bar'
else:
# in py3 these are byte literals
type(self.mock_request).uri = b'/foo/bar'
type(self.mock_request).path = b'/foo/bar'
self.mock_request.reset_mock()
with patch('%s.logger' % pbm) as mock_logger:
resp = self.cls.render(self.mock_request)
assert self.mock_request.mock_calls == [
call.setHeader('server', expected_server),
call.setResponseCode(307),
call.setHeader('Location', expected_location),
call.setHeader("Content-Type", "text/html; charset=UTF-8")
]
assert resp == self.empty_resp
assert mock_logger.mock_calls == [
call.info('RESPOND 307 to %s for %s%s request for %s from %s:%s',
expected_location, '', 'GET', '/foo/bar', '1.2.3.4',
12345)
]
示例11: test_register_callbacks
def test_register_callbacks(self):
mock_listener = Mock(spec_set=InputEventListener)
self.cls.listener = mock_listener
with patch('%s.logger' % pbm) as mock_logger:
self.cls.register_callbacks()
assert mock_logger.mock_calls == [
call.debug("registering callbacks"),
call.debug('registering callback for %s ON', 0),
call.debug('registering callback for %s OFF', 0),
call.debug('registering callback for %s ON', 1),
call.debug('registering callback for %s OFF', 1),
call.debug('registering callback for %s ON', 2),
call.debug('registering callback for %s OFF', 2),
call.debug('registering callback for %s ON', 3),
call.debug('registering callback for %s OFF', 3),
call.debug('done registering callbacks'),
call.info('Initial pin states: %s', [10, 11, 12, 13])
]
assert mock_listener.mock_calls == [
call.register(0, IODIR_ON, self.cls.handle_input_on),
call.register(0, IODIR_OFF, self.cls.handle_input_off),
call.register(1, IODIR_ON, self.cls.handle_input_on),
call.register(1, IODIR_OFF, self.cls.handle_input_off),
call.register(2, IODIR_ON, self.cls.handle_input_on),
call.register(2, IODIR_OFF, self.cls.handle_input_off),
call.register(3, IODIR_ON, self.cls.handle_input_on),
call.register(3, IODIR_OFF, self.cls.handle_input_off),
]
assert self.cls.current_values == [10, 11, 12, 13]
示例12: test_set_account_info_env
def test_set_account_info_env(self):
self.cls.aws_account_id = None
self.cls.aws_region = None
with patch('%s.logger' % pbm, autospec=True) as mock_logger:
with patch('%s.client' % pbm, autospec=True) as mock_client:
mock_client.return_value.get_user.return_value = {
'User': {'Arn': 'arn:aws:iam::123456789:user/foo'}
}
type(mock_client.return_value)._client_config = Mock(
region_name='myregion')
with patch.dict(
'%s.os.environ' % pbm,
{'AWS_REGION': 'ar'},
clear=True):
self.cls._set_account_info()
assert self.cls.aws_account_id == '123456789'
assert self.cls.aws_region == 'myregion'
assert mock_client.mock_calls == [
call('iam', region_name='ar'),
call().get_user(),
call('lambda', region_name='ar')
]
assert mock_logger.mock_calls == [
call.debug('Connecting to IAM with region_name=%s', 'ar'),
call.info('Found AWS account ID as %s; region: %s',
'123456789', 'myregion')
]
示例13: test_clone_repo_dry_run
def test_clone_repo_dry_run(self):
type(self.bi).ssh_clone_url = 'ssh_url'
type(self.bi).https_clone_url = 'https_url'
self.cls.dry_run = True
ex = Exception('foo')
def se_clone(url, path, branch=None):
if url == 'ssh_url':
raise ex
return True
with patch('%s.path_for_repo' % pb) as mock_path, \
patch('%s.Repo' % pbm) as mock_repo, \
patch('%s.logger' % pbm) as mock_logger:
mock_path.return_value = '/repo/path'
mock_repo.clone_from.side_effect = se_clone
res = self.cls.clone_repo()
assert mock_path.mock_calls == [call()]
assert mock_repo.mock_calls == []
assert mock_logger.mock_calls == [
call.debug("Cloning %s branch %s into: %s", 'my/repo', 'master',
'/repo/path'),
call.info("DRY RUN - not actually cloning %s into %s", 'my/repo',
'/repo/path')
]
assert res == ('/repo/path', '(DRY RUN)')
示例14: test_update_limits_from_api_low_max_instances
def test_update_limits_from_api_low_max_instances(self):
fixtures = result_fixtures.VPC()
response = fixtures.test_update_limits_from_api_low_max_instances
mock_conn = Mock()
mock_client_conn = Mock()
mock_client_conn.describe_account_attributes.return_value = response
cls = _VpcService(21, 43)
cls.resource_conn = mock_conn
cls.conn = mock_client_conn
with patch('awslimitchecker.services.vpc.logger') as mock_logger:
cls._update_limits_from_api()
assert mock_conn.mock_calls == []
assert mock_client_conn.mock_calls == [
call.describe_account_attributes()
]
assert mock_logger.mock_calls == [
call.info("Querying EC2 DescribeAccountAttributes for limits"),
call.debug('Done setting limits from API')
]
limit_name = 'Network interfaces per Region'
assert cls.limits[limit_name].api_limit is None
assert cls.limits[limit_name].get_limit() == DEFAULT_ENI_LIMIT
示例15: test_run
def test_run(self):
def se_ras(klass):
if mock_ras.call_count < 4:
return None
raise RuntimeError()
with patch('%s.read_and_send' % pb, autospec=True) as mock_ras:
with patch('%s.sleep' % pbm, autospec=True) as mock_sleep:
with patch('%s.logger' % pbm, autospec=True) as mock_logger:
mock_ras.side_effect = se_ras
with pytest.raises(RuntimeError):
self.cls.run()
assert mock_ras.mock_calls == [
call(self.cls),
call(self.cls),
call(self.cls),
call(self.cls)
]
assert mock_sleep.mock_calls == [
call(60.0),
call(60.0),
call(60.0)
]
assert mock_logger.mock_calls == [
call.info('Running sensor daemon loop...'),
call.debug('Sleeping %ss', 60.0),
call.debug('Sleeping %ss', 60.0),
call.debug('Sleeping %ss', 60.0)
]