本文整理汇总了Python中eliot.testing.LoggedAction类的典型用法代码示例。如果您正苦于以下问题:Python LoggedAction类的具体用法?Python LoggedAction怎么用?Python LoggedAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LoggedAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: actuallyAssert
def actuallyAssert(self, logger):
request = LoggedAction.ofType(logger.messages, REQUEST)[0]
assertContainsFields(self, request.startMessage, {
u"request_path": path.decode("ascii"),
u"method": method,
})
return request
示例2: test_iterates
def test_iterates(self, logger):
"""
If the predicate returns something falsey followed by something truthy,
then ``loop_until`` returns it immediately.
"""
result = object()
results = [None, result]
def predicate():
return results.pop(0)
clock = Clock()
d = loop_until(clock, predicate)
self.assertNoResult(d)
clock.advance(0.1)
self.assertEqual(
self.successResultOf(d),
result)
action = LoggedAction.of_type(logger.messages, LOOP_UNTIL_ACTION)[0]
assertContainsFields(self, action.start_message, {
'predicate': predicate,
})
assertContainsFields(self, action.end_message, {
'result': result,
})
self.assertTrue(action.succeeded)
message = LoggedMessage.of_type(
logger.messages, LOOP_UNTIL_ITERATION_MESSAGE)[0]
self.assertEqual(action.children, [message])
assertContainsFields(self, message.message, {
'result': None,
})
示例3: _assertTracebackLogged
def _assertTracebackLogged(self, logger):
"""
Assert that a traceback for an L{ArbitraryException} was logged as a
child of a L{REQUEST} action.
"""
# Get rid of it so it doesn't fail the test later.
tracebacks = logger.flushTracebacks(exceptionType)
if len(tracebacks) > 1:
self.fail("Multiple tracebacks: %s" % tracebacks)
traceback = tracebacks[0]
# Verify it contains what it's supposed to contain.
assertContainsFields(self, traceback, {
u"exception": exceptionType,
u"message_type": u"eliot:traceback",
# Just assume the traceback it contains is correct. The code
# that generates that string isn't part of this unit, anyway.
})
# Verify that it is a child of one of the request actions.
for request in LoggedAction.ofType(logger.messages, REQUEST):
if LoggedMessage(traceback) in request.descendants():
break
else:
self.fail(
"Traceback was logged outside of the context of a request "
"action.")
示例4: test_multiple_iterations
def test_multiple_iterations(self, logger):
"""
If the predicate returns something falsey followed by something truthy,
then ``loop_until`` returns it immediately.
"""
result = object()
results = [None, False, result]
expected_results = results[:-1]
def predicate():
return results.pop(0)
clock = Clock()
d = loop_until(clock, predicate)
clock.advance(0.1)
self.assertNoResult(d)
clock.advance(0.1)
self.assertEqual(self.successResultOf(d), result)
action = LoggedAction.of_type(logger.messages, LOOP_UNTIL_ACTION)[0]
assertContainsFields(self, action.start_message, {"predicate": predicate})
assertContainsFields(self, action.end_message, {"result": result})
self.assertTrue(action.succeeded)
messages = LoggedMessage.of_type(logger.messages, LOOP_UNTIL_ITERATION_MESSAGE)
self.assertEqual(action.children, messages)
self.assertEqual([messages[0].message["result"], messages[1].message["result"]], expected_results)
示例5: assert_nested_logging
def assert_nested_logging(self, combo, action_type, logger):
"""
All the underlying ``IStateChange`` will be run in Eliot context in
which the sequential ``IStateChange`` is run, even if they are not
run immediately.
:param combo: ``sequentially`` or ``in_parallel``.
:param action_type: ``eliot.ActionType`` we expect to be parent of
sub-changes' log entries.
:param logger: A ``MemoryLogger`` where messages go.
"""
actions = [ControllableAction(result=Deferred()),
ControllableAction(result=succeed(None))]
for action in actions:
self.patch(action, "_logger", logger)
run_state_change(combo(actions), None)
# For sequentially this will ensure second action doesn't
# automatically run in context of LOG_ACTION:
actions[0].result.callback(None)
parent = assertHasAction(self, logger, action_type, succeeded=True)
self.assertEqual(
dict(messages=parent.children, length=len(parent.children)),
dict(
messages=LoggedAction.ofType(
logger.messages, CONTROLLABLE_ACTION_TYPE),
length=2))
示例6: test_error_sending
def test_error_sending(self, logger):
"""
An error sending to one agent does not prevent others from being
notified.
"""
control_amp_service = build_control_amp_service(self)
self.patch(control_amp_service, 'logger', logger)
connected_protocol = ControlAMP(control_amp_service)
# Patching is bad.
# https://clusterhq.atlassian.net/browse/FLOC-1603
connected_protocol.callRemote = lambda *args, **kwargs: succeed({})
error = ConnectionLost()
disconnected_protocol = ControlAMP(control_amp_service)
results = [succeed({}), fail(error)]
# Patching is bad.
# https://clusterhq.atlassian.net/browse/FLOC-1603
disconnected_protocol.callRemote = (
lambda *args, **kwargs: results.pop(0))
control_amp_service.connected(disconnected_protocol)
control_amp_service.connected(connected_protocol)
control_amp_service.node_changed(NodeState(hostname=u"1.2.3.4"))
actions = LoggedAction.ofType(logger.messages, LOG_SEND_TO_AGENT)
self.assertEqual(
[action.end_message["exception"] for action in actions
if not action.succeeded],
[u"twisted.internet.error.ConnectionLost"])
示例7: validate
def validate(case, logger):
assertHasAction(case, logger, parent_action_type, succeeded=True)
# Remember what the docstring said? Ideally this would inspect the
# children of the action returned by assertHasAction but the interfaces
# don't seem to line up.
iptables = LoggedAction.ofType(logger.messages, IPTABLES)
case.assertNotEqual(iptables, [])
示例8: test_boto_ec2response_error
def test_boto_ec2response_error(self, logger):
"""
1. Invalid parameters to Boto's EBS API calls
raise the right exception after logging to Eliot.
2. Verify Eliot log output for expected message fields
from logging decorator for boto.exception.EC2Exception
originating from boto.ec2.connection.EC2Connection.
"""
# Test 1: Create volume with size 0.
# Raises: ClientError
self.assertRaises(ClientError, self.api.create_volume,
dataset_id=uuid4(), size=0,)
# Test 2: Set EC2 connection zone to an invalid string.
# Raises: ClientError
self.api.zone = u'invalid_zone'
self.assertRaises(
ClientError,
self.api.create_volume,
dataset_id=uuid4(),
size=self.minimum_allocatable_size,
)
# Validate decorated method for exception logging
# actually logged to ``Eliot`` logger.
expected_message_keys = {AWS_CODE.key, AWS_MESSAGE.key,
AWS_REQUEST_ID.key}
for logged in LoggedAction.of_type(logger.messages, AWS_ACTION,):
key_subset = set(key for key in expected_message_keys
if key in logged.end_message.keys())
self.assertEqual(expected_message_keys, key_subset)
示例9: assertSearchLogging2
def assertSearchLogging2(self, logger):
"""
The two put actions are logged, followed by the two get actions.
"""
[put1, put2] = LoggedAction.of_type(logger.messages, LOG_SEARCH_PUT)
assertContainsFields(
self, put1.start_message,
{'searchClass': SearchClasses.EXACT,
'environment': u'e',
'indexType': u'i',
'searchType': u'type1',
'result': u'result1'})
assertContainsFields(
self, put1.end_message,
{'searchValue': u'value'})
self.assertTrue(put1.succeeded)
assertContainsFields(
self, put2.start_message,
{'searchClass': SearchClasses.PREFIX,
'environment': u'e',
'indexType': u'i',
'searchType': u'type2',
'result': u'result2'})
assertContainsFields(
self, put2.end_message,
{'searchValue': u'value'})
self.assertTrue(put2.succeeded)
[get1, get2] = LoggedAction.of_type(logger.messages, LOG_SEARCH_GET)
assertContainsFields(
self, get1.start_message,
{'searchClass': SearchClasses.EXACT,
'environment': u'e',
'indexType': u'i',
'searchValue': u'value',
'searchType': None})
assertContainsFields(self, get1.end_message, {'results': [u'result1']})
self.assertTrue(get1.succeeded)
assertContainsFields(
self, get2.start_message,
{'searchClass': SearchClasses.PREFIX,
'environment': u'e',
'indexType': u'i',
'searchValue': u'va',
'searchType': None})
assertContainsFields(self, get2.end_message, {'results': [u'result2']})
self.assertTrue(get2.succeeded)
示例10: assertSearchLogging
def assertSearchLogging(self, logger):
"""
The put action is logged, followed by the get action, followed by the
delete, followed by the second get.
"""
[put] = LoggedAction.of_type(logger.messages, LOG_SEARCH_PUT)
assertContainsFields(
self, put.start_message,
{'searchClass': SearchClasses.EXACT,
'environment': u'someenv',
'indexType': u'someindex',
'result': u'result',
'searchType': u'type'})
assertContainsFields(
self, put.end_message,
{'searchValue': u'somevalue'})
self.assertTrue(put.succeeded)
[delete] = LoggedAction.of_type(logger.messages, LOG_SEARCH_DELETE)
assertContainsFields(
self, delete.start_message,
{'searchClass': SearchClasses.EXACT,
'environment': u'someenv',
'indexType': u'someindex',
'result': u'result',
'searchType': u'type'})
self.assertTrue(delete.succeeded)
[get1, get2] = LoggedAction.of_type(logger.messages, LOG_SEARCH_GET)
assertContainsFields(
self, get1.start_message,
{'searchClass': SearchClasses.EXACT,
'environment': u'someenv',
'indexType': u'someindex',
'searchValue': u'somevalue',
'searchType': None})
assertContainsFields(self, get1.end_message, {'results': [u'result']})
self.assertTrue(get1.succeeded)
assertContainsFields(
self, get2.start_message,
{'searchClass': SearchClasses.EXACT,
'environment': u'someenv',
'indexType': u'someindex',
'searchValue': u'somevalue',
'searchType': None})
assertContainsFields(self, get2.end_message, {'results': []})
self.assertTrue(get2.succeeded)
示例11: assertOutputLogging
def assertOutputLogging(self, logger):
"""
The L{IOutputExecutor} is invoked in the FSM's transition action
context.
"""
loggedTransition = LoggedAction.ofType(
logger.messages, LOG_FSM_TRANSITION)[0]
loggedAnimal = LoggedMessage.ofType(logger.messages, LOG_ANIMAL)[0]
self.assertIn(loggedAnimal, loggedTransition.children)
示例12: assert_context_preserved
def assert_context_preserved(self, logger):
"""
Logging in the method running in the thread pool is child of caller's
Eliot context.
"""
parent = assertHasAction(self, logger, LOG_IN_CALLER, True, {})
# in-between we expect a eliot:remote_task...
self.assertIn(parent.children[0].children[0],
LoggedAction.of_type(logger.messages, LOG_IN_SPY))
示例13: test_run_successful_test
def test_run_successful_test(self, logger):
"""
Running a test with the Eliot reporter logs an action.
"""
reporter = make_reporter()
test = make_successful_test()
test.run(reporter)
[action] = LoggedAction.of_type(logger.serialize(), TEST)
assertContainsFields(self, action.start_message, {"test": test.id()})
示例14: test_successful_test
def test_successful_test(self, logger):
"""
Starting and stopping a test logs a whole action.
"""
reporter = make_reporter()
test = make_successful_test()
reporter.startTest(test)
reporter.stopTest(test)
[action] = LoggedAction.of_type(logger.serialize(), TEST)
assertContainsFields(self, action.start_message, {"test": test.id()})
示例15: test_read_headers_fails
def test_read_headers_fails(capture_logging):
unparseable = io.BytesIO(b'21:'
b'missing trailing null'
b',')
with pytest.raises(RuntimeError), capture_logging() as logger:
receiver.read_headers(unparseable)
fail_actions = LoggedAction.ofType(logger.messages, types.SCGI_PARSE)
assert fail_actions and not fail_actions[0].succeeded