本文整理汇总了Python中testfixtures.LogCapture方法的典型用法代码示例。如果您正苦于以下问题:Python testfixtures.LogCapture方法的具体用法?Python testfixtures.LogCapture怎么用?Python testfixtures.LogCapture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testfixtures
的用法示例。
在下文中一共展示了testfixtures.LogCapture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def setUp(self):
self.my_dir, self.panoptes_test_conf_file = get_test_conf_file()
self._panoptes_resource = PanoptesResource(resource_site="test", resource_class="test",
resource_subclass="test", resource_type="test", resource_id="test",
resource_endpoint="test", resource_creation_timestamp=_TIMESTAMP,
resource_plugin="test")
self._panoptes_context = PanoptesContext(self.panoptes_test_conf_file,
key_value_store_class_list=[PanoptesTestKeyValueStore,
PanoptesResourcesKeyValueStore,
PanoptesPollingPluginKeyValueStore,
PanoptesSecretsStore,
PanoptesPollingPluginAgentKeyValueStore,
PanoptesDiscoveryPluginAgentKeyValueStore,
PanoptesDiscoveryPluginKeyValueStore],
create_message_producer=False, async_message_producer=False,
create_zookeeper_client=True)
self._runner_class = PanoptesPluginWithEnrichmentRunner
self._log_capture = LogCapture(attributes=TestPanoptesPluginRunner.extract)
示例2: test_check_output_bad_isCorrect
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def test_check_output_bad_isCorrect(sys):
with LogCapture() as logs:
docker_mock = MagicMock()
container = {
"Id": "myimageId"
}
args = argparse.Namespace()
args.timeout = 300
args.no_rm = False
docker_mock.wait.return_value = 0
docker_mock.logs.side_effect = [
'',
'{"isCorrect":"true-string-is-not-true","feedback":"You win!"}'
]
# Run the function under test
grade.run_container(docker_mock, container, args)
logs.check(
('root', 'INFO', 'Debug log:'),
('root', 'ERROR', "Field 'isCorrect' is not a boolean value."),
('root', 'DEBUG', "About to remove container: {'Id': 'myimageId'}")
)
sys.exit.assert_called_with(1)
示例3: test_check_output_no_feedback
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def test_check_output_no_feedback(sys):
with LogCapture() as logs:
docker_mock = MagicMock()
container = {
"Id": "myimageId"
}
args = argparse.Namespace()
args.timeout = 300
args.no_rm = False
docker_mock.wait.return_value = 0
docker_mock.logs.side_effect = [
'',
'{"isCorrect":false, "not-feedback": "garbage"}'
]
# Run the function under test
grade.run_container(docker_mock, container, args)
logs.check(
('root', 'INFO', 'Debug log:'),
('root', 'ERROR', "Field 'feedback' not present in parsed output."),
('root', 'DEBUG', "About to remove container: {'Id': 'myimageId'}")
)
sys.exit.assert_called_with(1)
示例4: test_check_output_fractional_score_boolean
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def test_check_output_fractional_score_boolean(sys):
with LogCapture() as logs:
docker_mock = MagicMock()
container = {
"Id": "myimageId"
}
args = argparse.Namespace()
args.timeout = 300
args.no_rm = False
docker_mock.wait.return_value = 0
docker_mock.logs.side_effect = [
'',
'{"fractionalScore": false, "feedback": "wheeeee"}'
]
# Run the function under test
grade.run_container(docker_mock, container, args)
logs.check(
('root', 'INFO', 'Debug log:'),
('root', 'ERROR', "Field 'fractionalScore' must be a decimal."),
('root', 'DEBUG', "About to remove container: {'Id': 'myimageId'}")
)
sys.exit.assert_called_with(1)
示例5: test_check_output_fractional_score_string
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def test_check_output_fractional_score_string(sys):
with LogCapture() as logs:
docker_mock = MagicMock()
container = {
"Id": "myimageId"
}
args = argparse.Namespace()
args.timeout = 300
args.no_rm = False
docker_mock.wait.return_value = 0
docker_mock.logs.side_effect = [
'',
'{"fractionalScore": "0.3", "feedback": "wheeeee"}'
]
# Run the function under test
grade.run_container(docker_mock, container, args)
logs.check(
('root', 'INFO', 'Debug log:'),
('root', 'ERROR', "Field 'fractionalScore' must be a decimal."),
('root', 'DEBUG', "About to remove container: {'Id': 'myimageId'}")
)
sys.exit.assert_called_with(1)
示例6: test_check_output_fractional_score_too_low
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def test_check_output_fractional_score_too_low(sys):
with LogCapture() as logs:
docker_mock = MagicMock()
container = {
"Id": "myimageId"
}
args = argparse.Namespace()
args.timeout = 300
args.no_rm = False
docker_mock.wait.return_value = 0
docker_mock.logs.side_effect = [
'',
'{"fractionalScore":-1.1, "feedback": "wheeeee"}'
]
# Run the function under test
grade.run_container(docker_mock, container, args)
logs.check(
('root', 'INFO', 'Debug log:'),
('root', 'ERROR', "Field 'fractionalScore' must be >= 0."),
('root', 'DEBUG', "About to remove container: {'Id': 'myimageId'}")
)
sys.exit.assert_called_with(1)
示例7: test_check_output_missing_grade
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def test_check_output_missing_grade(sys):
with LogCapture() as logs:
docker_mock = MagicMock()
container = {
"Id": "myimageId"
}
args = argparse.Namespace()
args.timeout = 300
args.no_rm = False
docker_mock.wait.return_value = 0
docker_mock.logs.side_effect = [
'',
'{"feedback": "wheeeee"}'
]
# Run the function under test
grade.run_container(docker_mock, container, args)
logs.check(
('root', 'INFO', 'Debug log:'),
('root', 'ERROR', "Required field 'fractionalScore' is missing."),
('root', 'DEBUG', "About to remove container: {'Id': 'myimageId'}")
)
sys.exit.assert_called_with(1)
示例8: test_check_output_malformed_output
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def test_check_output_malformed_output(sys):
with LogCapture() as logs:
docker_mock = MagicMock()
container = {
"Id": "myimageId"
}
args = argparse.Namespace()
args.timeout = 300
args.no_rm = False
docker_mock.wait.return_value = 0
docker_mock.logs.side_effect = [
'',
'{"isCorrect":false, "not-feedback": "garbageeeeeeee'
]
# Run the function under test
grade.run_container(docker_mock, container, args)
logs.check(
('root', 'INFO', 'Debug log:'),
('root', 'ERROR', "The output was not a valid JSON document."),
('root', 'DEBUG', "About to remove container: {'Id': 'myimageId'}")
)
sys.exit.assert_called_with(1)
示例9: test_check_output_bad_return_code
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def test_check_output_bad_return_code(sys):
with LogCapture():
docker_mock = MagicMock()
container = {
"Id": "myimageId"
}
args = argparse.Namespace()
args.timeout = 300
args.no_rm = False
docker_mock.wait.return_value = 1
docker_mock.logs.side_effect = [
'debug output',
'{"isCorrect":true,"feedback":"You win!"}'
]
# Run the function under test
grade.run_container(docker_mock, container, args)
sys.exit.assert_called_with(1)
示例10: test_check_output_good_output_is_correct
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def test_check_output_good_output_is_correct(sys):
with LogCapture() as logs:
docker_mock = MagicMock()
container = {
"Id": "myimageId"
}
args = argparse.Namespace()
args.timeout = 300
args.no_rm = False
docker_mock.wait.return_value = 0
docker_mock.logs.side_effect = [
'',
'{"isCorrect":false, "feedback": "Helpful comment!"}'
]
# Run the function under test
grade.run_container(docker_mock, container, args)
logs.check(
('root', 'INFO', 'Debug log:'),
('root', 'DEBUG', "About to remove container: {'Id': 'myimageId'}")
)
assert not sys.exit.called, "sys.exit should not be called!"
示例11: test_check_output_good_output_fractional_score_one
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def test_check_output_good_output_fractional_score_one(sys):
with LogCapture() as logs:
docker_mock = MagicMock()
container = {
"Id": "myimageId"
}
args = argparse.Namespace()
args.timeout = 300
args.no_rm = False
docker_mock.wait.return_value = 0
docker_mock.logs.side_effect = [
'',
'{"fractionalScore":1, "feedback": "Helpful comment!"}'
]
# Run the function under test
grade.run_container(docker_mock, container, args)
logs.check(
('root', 'INFO', 'Debug log:'),
('root', 'DEBUG', "About to remove container: {'Id': 'myimageId'}")
)
assert not sys.exit.called, "sys.exit should not be called!"
示例12: test_check_output_good_output_fractional_score_one_point_oh
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def test_check_output_good_output_fractional_score_one_point_oh(sys):
with LogCapture() as logs:
docker_mock = MagicMock()
container = {
"Id": "myimageId"
}
args = argparse.Namespace()
args.timeout = 300
args.no_rm = False
docker_mock.wait.return_value = 0
docker_mock.logs.side_effect = [
'',
'{"fractionalScore":1.0, "feedback": "Helpful comment!"}'
]
# Run the function under test
grade.run_container(docker_mock, container, args)
logs.check(
('root', 'INFO', 'Debug log:'),
('root', 'DEBUG', "About to remove container: {'Id': 'myimageId'}")
)
assert not sys.exit.called, "sys.exit should not be called!"
示例13: test_check_output_good_output_fractional_score_zero
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def test_check_output_good_output_fractional_score_zero(sys):
with LogCapture() as logs:
docker_mock = MagicMock()
container = {
"Id": "myimageId"
}
args = argparse.Namespace()
args.timeout = 300
args.no_rm = False
docker_mock.wait.return_value = 0
docker_mock.logs.side_effect = [
'',
'{"fractionalScore":0, "feedback": "Helpful comment!"}'
]
# Run the function under test
grade.run_container(docker_mock, container, args)
logs.check(
('root', 'INFO', 'Debug log:'),
('root', 'DEBUG', "About to remove container: {'Id': 'myimageId'}")
)
assert not sys.exit.called, "sys.exit should not be called!"
示例14: test_check_output_good_output_fractional_score_zero_point_oh
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def test_check_output_good_output_fractional_score_zero_point_oh(sys):
with LogCapture() as logs:
docker_mock = MagicMock()
container = {
"Id": "myimageId"
}
args = argparse.Namespace()
args.timeout = 300
args.no_rm = False
docker_mock.wait.return_value = 0
docker_mock.logs.side_effect = [
'',
'{"fractionalScore":0.0, "feedback": "Helpful comment!"}'
]
# Run the function under test
grade.run_container(docker_mock, container, args)
logs.check(
('root', 'INFO', 'Debug log:'),
('root', 'DEBUG', "About to remove container: {'Id': 'myimageId'}")
)
assert not sys.exit.called, "sys.exit should not be called!"
示例15: test_bad_message_is_logged
# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import LogCapture [as 别名]
def test_bad_message_is_logged(self, config, trivial_message):
responses.add(responses.POST, "https://api.github.com/repos/tdsmith/test_repo/hooks")
repo_listener = snooze.RepositoryListener(
events=snooze.LISTEN_EVENTS,
**config["tdsmith/test_repo"])
sqs = boto3.resource("sqs", region_name="us-west-2")
sqs_queue = list(sqs.queues.all())[0]
sqs_queue.send_message(MessageBody="this isn't a json message at all")
with LogCapture() as l:
repo_listener.poll()
assert 'ERROR' in str(l)
def my_callback(event, message):
raise ValueError("I object!")
sqs_queue.send_message(MessageBody=trivial_message)
repo_listener.register_callback(my_callback)
with LogCapture() as l:
repo_listener.poll()
assert 'I object!' in str(l)