本文整理汇总了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)
示例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))
示例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))
示例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)
示例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([]))
示例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'))
示例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))
示例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=\:\:'))
示例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')
示例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']))
示例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))
示例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']))
示例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))
示例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"]])]))
示例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))