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


Python assertions.assert_that函数代码示例

本文整理汇总了Python中testtools.assertions.assert_that函数的典型用法代码示例。如果您正苦于以下问题:Python assert_that函数的具体用法?Python assert_that怎么用?Python assert_that使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_cancel_job

    def test_cancel_job(self):
        """
        Tests that scheduler is stopped whenever a port is failing.
        """
        port_out = object()
        port_in = Mock(spec=_port_callback)
        self.flowmap[port_out] = port_in

        run_deferred = self.scheduler.run(self.clock)
        self.scheduler.send('some item', port_out)

        self.assertEquals(len(list(self.scheduler.pending)), 1)

        self.scheduler.stop('bye!')

        self.assertEquals(len(list(self.scheduler.pending)), 1)

        join_deferred = self.scheduler.join()
        self.clock.advance(self.epsilon)
        assert_that(join_deferred, twistedsupport.succeeded(matchers.Always()))
        assert_that(run_deferred, twistedsupport.succeeded(matchers.Equals('bye!')))

        self.assertEquals(len(list(self.scheduler.pending)), 0)

        self.assertEquals(port_in.call_count, 0)
开发者ID:spreadflow,项目名称:spreadflow-core,代码行数:25,代码来源:test_scheduler.py

示例2: test_fail_job

    def test_fail_job(self):
        """
        Tests that scheduler is stopped whenever a port is failing.
        """
        port_out = object()
        port_in = Mock(spec=_port_callback, side_effect=RuntimeError('failed!'))
        self.flowmap[port_out] = port_in

        run_deferred = self.scheduler.run(self.clock)
        self.scheduler.send('some item', port_out)

        expected_message = 'Job failed on {:s} while processing {:s}'.format(
            str(port_in), 'some item')

        from testtools.twistedsupport._runtest import _NoTwistedLogObservers
        with _NoTwistedLogObservers():
            with twistedsupport.CaptureTwistedLogs() as twisted_logs:
                # Trigger queue run.
                self.clock.advance(self.epsilon)
                assert_that(twisted_logs.getDetails(), matchers.MatchesDict({
                    'twisted-log': matchers.AfterPreprocessing(
                        lambda log: log.as_text(), matchers.Contains(expected_message))
                }))

        port_in.assert_called_once_with('some item', self.scheduler.send)

        matcher = matchers.AfterPreprocessing(lambda f: f.value, matchers.IsInstance(RuntimeError))
        assert_that(run_deferred, twistedsupport.failed(matcher))
开发者ID:spreadflow,项目名称:spreadflow-core,代码行数:28,代码来源:test_scheduler.py

示例3: test_default_client

    def test_default_client(self):
        """
        When default_client is passed a client it should return that client.
        """
        client = treq_HTTPClient(Agent(reactor))

        assert_that(default_client(client, reactor), Is(client))
开发者ID:praekeltfoundation,项目名称:marathon-acme,代码行数:7,代码来源:test_clients.py

示例4: test_run_job

    def test_run_job(self):
        """
        Tests send() and ensure that the job-event is fired.
        """
        job_handler = Mock()
        self.dispatcher.add_listener(JobEvent, 0, job_handler)

        port_out = object()
        port_in = Mock(spec=_port_callback)
        self.flowmap[port_out] = port_in

        self.scheduler.run(self.clock)
        self.scheduler.send('some item', port_out)

        expected_job = Job(port_in, 'some item', self.scheduler.send, port_out)
        self.assertEquals(job_handler.call_count, 1)
        assert_that(job_handler.call_args, MatchesInvocation(
            MatchesEvent(JobEvent,
                         scheduler=matchers.Equals(self.scheduler),
                         job=matchers.Equals(expected_job),
                         completed=twistedsupport.has_no_result())
        ))
        self.assertEquals(port_in.call_count, 0)

        self.assertEquals(len(list(self.scheduler.pending)), 1)

        # Trigger queue run.
        self.clock.advance(self.epsilon)

        port_in.assert_called_once_with('some item', self.scheduler.send)

        self.assertEquals(len(list(self.scheduler.pending)), 0)
开发者ID:spreadflow,项目名称:spreadflow-core,代码行数:32,代码来源:test_scheduler.py

示例5: test_separators

 def test_separators(self):
     """
     When the domain label contains only the separators (commas or
     whitespace), the separators should be ignored.
     """
     domains = parse_domain_label(' , ,   ')
     assert_that(domains, Equals([]))
开发者ID:praekeltfoundation,项目名称:marathon-acme,代码行数:7,代码来源:test_service.py

示例6: test_parse_no_ip_address

 def test_parse_no_ip_address(self):
     """
     When a listen address is parsed with no IP address, an endpoint
     description with the listen address's port but no interface is
     returned.
     """
     assert_that(parse_listen_addr(':8080'), Equals('tcp:8080'))
开发者ID:praekeltfoundation,项目名称:marathon-acme,代码行数:7,代码来源:test_cli.py

示例7: test_single_fail

    def test_single_fail(self):
        """
        A single incoming message with a single file path.
        """
        sut = MetadataExtractor('exiftool', ('-some', '-arg'))

        error = RuntimeError('boom!')

        sut.peer = Mock(spec=ExiftoolProtocol)
        sut.peer.execute.return_value = defer.fail(error)

        insert = {
            'inserts': ['a'],
            'deletes': [],
            'data': {
                'a': {
                    'path': '/path/to/file.jpg',
                }
            }
        }
        send = Mock(spec=Scheduler.send)
        result = sut(insert, send)
        self.assertEquals(send.call_count, 0)
        sut.peer.execute.assert_called_once_with(
            b'-some', b'-arg', b'-j', b'-charset', b'exiftool=UTF-8',
            b'-charset', b'filename=UTF-8', b'/path/to/file.jpg')

        failure_matcher = matchers.AfterPreprocessing(
            lambda f: f.value, matchers.IsInstance(MetadataExtractorError))
        assert_that(result, twistedsupport.failed(failure_matcher))
开发者ID:spreadflow,项目名称:spreadflow-exiftool,代码行数:30,代码来源:test_exiftool_proc.py

示例8: test_parse_ipv6

 def test_parse_ipv6(self):
     """
     When a listen address is parsed with an IPv4 address, an appropriate
     interface is present in the returned endpoint description.
     """
     assert_that(parse_listen_addr('[::]:8080'),
                 Equals('tcp6:8080:interface=\:\:'))
开发者ID:praekeltfoundation,项目名称:marathon-acme,代码行数:7,代码来源:test_cli.py

示例9: test_single_job

    def test_single_job(self):
        """
        A single incoming message with a single file path.
        """
        sut = MetadataExtractor('exiftool', ('-some', '-arg'))

        sut.peer = Mock(spec=ExiftoolProtocol)
        sut.peer.execute.return_value = defer.succeed(b'[{"hello": "world"}]')

        insert = {
            'inserts': ['a'],
            'deletes': [],
            'data': {
                'a': {
                    'path': '/path/to/file.jpg',
                }
            }
        }
        expected = copy.deepcopy(insert)
        expected['data']['a']['metadata'] = {'hello': 'world'}
        matches = MatchesSendDeltaItemInvocation(expected, sut)
        send = Mock(spec=Scheduler.send)
        sut(insert, send)
        self.assertEquals(send.call_count, 1)
        assert_that(send.call_args, matches)
        sut.peer.execute.assert_called_once_with(
            b'-some', b'-arg', b'-j', b'-charset', b'exiftool=UTF-8',
            b'-charset', b'filename=UTF-8', b'/path/to/file.jpg')
开发者ID:spreadflow,项目名称:spreadflow-exiftool,代码行数:28,代码来源:test_exiftool_proc.py

示例10: test_multiple_domains_whitespace

 def test_multiple_domains_whitespace(self):
     """
     When the domain label contains multiple whitespace-separated domains,
     the domains should be parsed into a list of domains.
     """
     domains = parse_domain_label('example.com example2.com')
     assert_that(domains, Equals(['example.com', 'example2.com']))
开发者ID:praekeltfoundation,项目名称:marathon-acme,代码行数:7,代码来源:test_service.py

示例11: test_listen_events_attach_initial_sync

    def test_listen_events_attach_initial_sync(self):
        """
        When we listen for events from Marathon, and we receive a subscribe
        event from ourselves subscribing, an initial sync should be performed
        and certificates issued for any new domains.
        """
        self.fake_marathon.add_app({
            'id': '/my-app_1',
            'labels': {
                'HAPROXY_GROUP': 'external',
                'MARATHON_ACME_0_DOMAIN': 'example.com'
            },
            'portDefinitions': [
                {'port': 9000, 'protocol': 'tcp', 'labels': {}}
            ]
        })

        marathon_acme = self.mk_marathon_acme()
        marathon_acme.listen_events()

        # Observe that the certificate was stored and marathon-lb notified
        assert_that(self.cert_store.as_dict(), succeeded(MatchesDict({
            'example.com': Not(Is(None))
        })))
        assert_that(self.fake_marathon_lb.check_signalled_usr1(), Equals(True))
开发者ID:praekeltfoundation,项目名称:marathon-acme,代码行数:25,代码来源:test_service.py

示例12: test_single_domain

 def test_single_domain(self):
     """
     When the domain label contains just a single domain, that domain should
     be parsed into a list containing just the one domain.
     """
     domains = parse_domain_label('example.com')
     assert_that(domains, Equals(['example.com']))
开发者ID:praekeltfoundation,项目名称:marathon-acme,代码行数:7,代码来源:test_service.py

示例13: test_default_reactor

    def test_default_reactor(self):
        """
        When default_reactor is passed a reactor it should return that reactor.
        """
        clock = Clock()

        assert_that(default_reactor(clock), Is(clock))
开发者ID:praekeltfoundation,项目名称:marathon-acme,代码行数:7,代码来源:test_clients.py

示例14: test_provision_second_vif

    def test_provision_second_vif(self, task_catcher, xs_helper, admin_client):
        """
        We can create a new VM using mostly default values.
        """
        createvm_calls = task_catcher.catch_create_vm()
        _, xs = xs_helper.new_host("xs01.local")
        templ = xs_helper.db_template("default")

        assert list(XenVM.objects.all()) == []
        assert list(Addresses.objects.all()) == []

        # Make the request.
        resp = admin_client.post(reverse('provision'), {
            "hostname": "foo.example.com",
            "template": templ.pk,
            "group": xs_helper.db_project("fooproj").pk,
            "extra_network_bridges": "xenbr1",
        }, follow=True)
        assert resp.status_code == 200

        # Make sure we did the right things.
        [addr] = Addresses.objects.all()
        [vm] = XenVM.objects.all()

        assert_that(createvm_calls, MatchesListwise([listmatcher([
            vm, xs, templ, "foo", "example.com", addr.ip,
            "255.255.255.0", DEFAULT_GATEWAY, Always(), ["xenbr1"]])]))
开发者ID:calston,项目名称:xenzen,代码行数:27,代码来源:test_views.py

示例15: test_dispatch_with_return_fails

    def test_dispatch_with_return_fails(self):
        dispatcher = EventDispatcher()

        test_callback_prio_0_cb_0 = Mock(return_value='hello')
        test_callback_prio_0_cb_1 = Mock(side_effect=RuntimeError('boom!'))
        test_callback_prio_1_cb_0 = Mock(return_value='world')

        dispatcher.add_listener(TestEvent, 0, test_callback_prio_0_cb_0)
        dispatcher.add_listener(TestEvent, 0, test_callback_prio_0_cb_1)
        dispatcher.add_listener(TestEvent, 1, test_callback_prio_1_cb_0)

        event = TestEvent()
        d = dispatcher.dispatch(event, fail_mode=FailMode.RETURN)

        matcher = matchers.MatchesListwise([
            matchers.MatchesListwise([
                matchers.Equals(0), matchers.MatchesListwise([
                    matchers.Equals((True, 'hello')),
                    matchers.MatchesListwise([
                        matchers.Equals(False),
                        matchers.AfterPreprocessing(lambda f: f.value, matchers.IsInstance(HandlerError)),
                    ])
                ]),
            ]),
            matchers.MatchesListwise([
                matchers.Equals(1), matchers.MatchesListwise([
                    matchers.Equals((True, 'world')),
                ]),
            ]),
        ])

        assert_that(d, twistedsupport.succeeded(matcher))
开发者ID:spreadflow,项目名称:spreadflow-core,代码行数:32,代码来源:test_eventdispatcher.py


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