当前位置: 首页>>代码示例>>Python>>正文


Python LoggedMessage.of_type方法代码示例

本文整理汇总了Python中eliot.testing.LoggedMessage.of_type方法的典型用法代码示例。如果您正苦于以下问题:Python LoggedMessage.of_type方法的具体用法?Python LoggedMessage.of_type怎么用?Python LoggedMessage.of_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eliot.testing.LoggedMessage的用法示例。


在下文中一共展示了LoggedMessage.of_type方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_iterates

# 需要导入模块: from eliot.testing import LoggedMessage [as 别名]
# 或者: from eliot.testing.LoggedMessage import of_type [as 别名]
    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,
        })
开发者ID:LeastAuthority,项目名称:leastauthority.com,代码行数:37,代码来源:test_retry.py

示例2: test_boto_ec2response_error

# 需要导入模块: from eliot.testing import LoggedMessage [as 别名]
# 或者: from eliot.testing.LoggedMessage import of_type [as 别名]
    def test_boto_ec2response_error(self, logger):
        """
        1. Test that 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: EC2ResponseError
        self.assertRaises(EC2ResponseError, self.api.create_volume,
                          dataset_id=uuid4(), size=0,)

        # Test 2: Set EC2 connection zone to an invalid string.
        # Raises: EC2ResponseError
        self.api.zone = u'invalid_zone'
        self.assertRaises(
            EC2ResponseError,
            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 LoggedMessage.of_type(logger.messages,
                                            BOTO_EC2RESPONSE_ERROR,):
            key_subset = set(key for key in expected_message_keys
                             if key in logged.message.keys())
            self.assertEqual(expected_message_keys, key_subset)
开发者ID:achanda,项目名称:flocker,代码行数:34,代码来源:test_ebs.py

示例3: test_multiple_iterations

# 需要导入模块: from eliot.testing import LoggedMessage [as 别名]
# 或者: from eliot.testing.LoggedMessage import of_type [as 别名]
    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)
开发者ID:ClusterHQ,项目名称:flocker,代码行数:31,代码来源:test_retry.py

示例4: test_novaclient_exception

# 需要导入模块: from eliot.testing import LoggedMessage [as 别名]
# 或者: from eliot.testing.LoggedMessage import of_type [as 别名]
    def test_novaclient_exception(self, logger):
        """
        The details of ``novaclient.exceptions.ClientException`` are logged
        when it is raised by the decorated method and the exception is still
        raised.
        """
        result = NovaClientException(
            code=INTERNAL_SERVER_ERROR,
            message="Some things went wrong with some other things.",
            details={"key": "value"},
            request_id="abcdefghijklmnopqrstuvwxyz",
            url="/foo/bar",
            method="POST",
        )
        logging_dummy = LoggingDummy(Dummy(result))
        self.assertRaises(NovaClientException, logging_dummy.raise_method)

        logged = LoggedMessage.of_type(
            logger.messages, NOVA_CLIENT_EXCEPTION,
        )[0]
        assertContainsFields(
            self, logged.message, {
                u"code": result.code,
                u"message": result.message,
                u"details": result.details,
                u"request_id": result.request_id,
                u"url": result.url,
                u"method": result.method,
            },
        )
开发者ID:achanda,项目名称:flocker,代码行数:32,代码来源:test_openstack.py

示例5: test_keystone_client_exception

# 需要导入模块: from eliot.testing import LoggedMessage [as 别名]
# 或者: from eliot.testing.LoggedMessage import of_type [as 别名]
    def test_keystone_client_exception(self, logger):
        """
        ``keystoneclient.openstack.common.apiclient.exceptions.BadRequest`` is
        treated similarly to ``novaclient.exceptions.ClientException``.

        See ``test_novaclient_exception``.
        """
        response = Response()
        response._content = "hello world"
        result = KeystoneHttpError(
            message="Some things went wrong with some other things.",
            details={"key": "value"},
            response=response,
            request_id="abcdefghijklmnopqrstuvwxyz",
            url="/foo/bar",
            method="POST",
            http_status=INTERNAL_SERVER_ERROR,
        )
        logging_dummy = LoggingDummy(Dummy(result))
        self.assertRaises(KeystoneHttpError, logging_dummy.raise_method)

        logged = LoggedMessage.of_type(
            logger.messages, KEYSTONE_HTTP_ERROR,
        )[0]
        assertContainsFields(
            self, logged.message, {
                u"code": result.http_status,
                u"message": result.message,
                u"details": result.details,
                u"request_id": result.request_id,
                u"url": result.url,
                u"method": result.method,
                u"response": "hello world",
            },
        )
开发者ID:achanda,项目名称:flocker,代码行数:37,代码来源:test_openstack.py

示例6: assert_logged_multiple_iterations

# 需要导入模块: from eliot.testing import LoggedMessage [as 别名]
# 或者: from eliot.testing.LoggedMessage import of_type [as 别名]
 def assert_logged_multiple_iterations(self, logger):
     """
     Function passed to ``retry_failure`` is run in the context of a
     ``LOOP_UNTIL_ACTION``.
     """
     iterations = LoggedMessage.of_type(logger.messages, ITERATION_MESSAGE)
     loop = assertHasAction(self, logger, LOOP_UNTIL_ACTION, True)
     self.assertEqual(sorted(iterations, key=lambda m: m.message["iteration"]), loop.children)
开发者ID:ClusterHQ,项目名称:flocker,代码行数:10,代码来源:test_retry.py

示例7: test_volume_busy_error_on_busy_state

# 需要导入模块: from eliot.testing import LoggedMessage [as 别名]
# 或者: from eliot.testing.LoggedMessage import of_type [as 别名]
    def test_volume_busy_error_on_busy_state(self, logger):
        """
        A ``VolumeBusy`` is raised if a volume's attachment state is "busy"
        when attempting to detach the volume. This can occur if an attempt
        is made to detach a volume that has not been unmounted.
        """
        try:
            config = get_blockdevice_config()
        except InvalidConfig as e:
            self.skipTest(str(e))

        # Create a volume
        dataset_id = uuid4()
        flocker_volume = self.api.create_volume(
            dataset_id=dataset_id,
            size=self.minimum_allocatable_size,
        )
        ec2_client = get_ec2_client_for_test(config)

        # Attach the volume.
        instance_id = self.api.compute_instance_id()
        self.api.attach_volume(flocker_volume.blockdevice_id, instance_id)

        volume = ec2_client.connection.Volume(flocker_volume.blockdevice_id)

        def clean_volume(volume):
            volume.detach_from_instance()
            _wait_for_volume_state_change(VolumeOperations.DETACH, volume)
            volume.delete()

        self.addCleanup(clean_volume, volume)

        # Artificially set the volume's attachment state to "busy", by
        # monkey-patching the EBS driver's ``_get_ebs_volume`` method.
        def busy_ebs_volume(volume_id):
            busy_volume = ec2_client.connection.Volume(volume_id)
            busy_volume.load()
            if busy_volume.attachments:
                busy_volume.attachments[0]['State'] = "busy"
            return busy_volume

        self.patch(self.api, "_get_ebs_volume", busy_ebs_volume)

        # Try to detach and get the VolumeBusy exception.
        self.assertRaises(
            VolumeBusy, self.api.detach_volume, flocker_volume.blockdevice_id)

        expected_keys = set(["volume_id", "attachments"])
        messages = [
            message.message for message
            in LoggedMessage.of_type(logger.messages, VOLUME_BUSY_MESSAGE)
        ]
        self.assertThat(messages, AllMatch(ContainsAll(expected_keys)))
开发者ID:332054781,项目名称:flocker,代码行数:55,代码来源:test_ebs.py


注:本文中的eliot.testing.LoggedMessage.of_type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。