本文整理汇总了Python中expects.equal函数的典型用法代码示例。如果您正苦于以下问题:Python equal函数的具体用法?Python equal怎么用?Python equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_should_return_ttl_cache_if_flush_interval_is_positive
def test_should_return_ttl_cache_if_flush_interval_is_positive(self):
delta = datetime.timedelta(seconds=1)
should_be_ttl = [
lambda timer: caches.create(
caches.CheckOptions(num_entries=1, flush_interval=delta),
timer=timer
),
lambda timer: caches.create(
caches.ReportOptions(num_entries=1, flush_interval=delta),
timer=timer
),
]
for testf in should_be_ttl:
timer = _DateTimeTimer()
sync_cache = testf(timer)
expect(sync_cache).to(be_a(caches.LockedObject))
with sync_cache as cache:
expect(cache).to(be_a(caches.DequeOutTTLCache))
expect(cache.timer()).to(equal(0))
cache[1] = 1
expect(set(cache)).to(equal({1}))
expect(cache.get(1)).to(equal(1))
timer.tick()
expect(cache.get(1)).to(equal(1))
timer.tick()
expect(cache.get(1)).to(be_none)
# Is still TTL without the custom timer
sync_cache = testf(None)
expect(sync_cache).to(be_a(caches.LockedObject))
with sync_cache as cache:
expect(cache).to(be_a(caches.DequeOutTTLCache))
示例2: test_flush_pipes_data_between_streams
def test_flush_pipes_data_between_streams(self):
a = StringIO(u'food')
b = StringIO()
pump = io.Pump(a, b)
pump.flush(3)
expect(a.read(1)).to(equal('d'))
expect(b.getvalue()).to(equal('foo'))
示例3: test_should_update_temp_response_with_actual
def test_should_update_temp_response_with_actual(self):
req = _make_test_request(self.SERVICE_NAME, self.FAKE_OPERATION_ID)
temp_response = sc_messages.AllocateQuotaResponse(
operationId=self.FAKE_OPERATION_ID)
real_response = sc_messages.AllocateQuotaResponse(
operationId=self.FAKE_OPERATION_ID,
quotaMetrics=[sc_messages.MetricValueSet(
metricName=u'a_float',
metricValues=[
metric_value.create(
labels={
u'key1': u'value1',
u'key2': u'value2'},
doubleValue=1.1,
),
]
)]
)
agg = self.agg
agg.allocate_quota(req)
signature = quota_request.sign(req.allocateQuotaRequest)
with agg._cache as cache:
item = cache[signature]
expect(item.response).to(equal(temp_response))
expect(item.is_in_flight).to(be_true)
agg.add_response(req, real_response)
item = cache[signature]
expect(item.response).to(equal(real_response))
expect(item.is_in_flight).to(be_false)
示例4: test_should_send_requests_with_default_query_param_api_key
def test_should_send_requests_with_default_query_param_api_key(self):
for default_key in (u'key', u'api_key'):
wrappee = _DummyWsgiApp()
control_client = mock.MagicMock(spec=client.Client)
given = {
u'wsgi.url_scheme': u'http',
u'QUERY_STRING': u'%s=my-default-api-key-value' % (default_key,),
u'PATH_INFO': u'/uvw/method_needs_api_key/with_query_param',
u'REMOTE_ADDR': u'192.168.0.3',
u'HTTP_HOST': u'localhost',
u'HTTP_REFERER': u'example.myreferer.com',
u'REQUEST_METHOD': u'GET'}
dummy_response = sc_messages.CheckResponse(
operationId=u'fake_operation_id')
wrapped = wsgi.add_all(wrappee,
self.PROJECT_ID,
control_client,
loader=service.Loaders.ENVIRONMENT)
control_client.check.return_value = dummy_response
wrapped(given, _dummy_start_response)
expect(control_client.check.called).to(be_true)
check_request = control_client.check.call_args_list[0].checkRequest
check_req = control_client.check.call_args[0][0]
expect(check_req.checkRequest.operation.consumerId).to(
equal(u'api_key:my-default-api-key-value'))
expect(control_client.report.called).to(be_true)
report_req = control_client.report.call_args[0][0]
expect(report_req.reportRequest.operations[0].consumerId).to(
equal(u'api_key:my-default-api-key-value'))
expect(control_client.allocate_quota.called).to(be_false)
示例5: _expect_stats_eq_direct_calc_from_samples
def _expect_stats_eq_direct_calc_from_samples(d, samples):
# pylint: disable=fixme
# TODO: update this the sum of rho-squared
want_mean = sum(samples) / len(samples)
expect(d.mean).to(equal(want_mean))
expect(d.maximum).to(equal(max(samples)))
expect(d.minimum).to(equal(min(samples)))
示例6: test_should_not_enter_scheduler_for_cached_checks
def test_should_not_enter_scheduler_for_cached_checks(self, sched, thread_class):
thread_class.return_value.start.side_effect = lambda: old_div(1,0)
self._subject.start()
# confirm scheduler is created and initialized
expect(sched.scheduler.called).to(be_true)
scheduler = sched.scheduler.return_value
expect(scheduler.enter.called).to(be_true)
scheduler.reset_mock()
# call check once, to a cache response
dummy_request = _make_dummy_check_request(self.PROJECT_ID,
self.SERVICE_NAME)
dummy_response = messages.CheckResponse(
operationId=dummy_request.checkRequest.operation.operationId)
t = self._mock_transport
t.services.check.return_value = dummy_response
expect(self._subject.check(dummy_request)).to(equal(dummy_response))
t.reset_mock()
# call check again - response is cached...
expect(self._subject.check(dummy_request)).to(equal(dummy_response))
expect(self._mock_transport.services.check.called).to(be_false)
# ... the scheduler is not run
expect(scheduler.run.called).to(be_false)
示例7: test_should_send_requests_with_configured_header_api_key
def test_should_send_requests_with_configured_header_api_key(self):
wrappee = _DummyWsgiApp()
control_client = mock.MagicMock(spec=client.Client)
given = {
u'wsgi.url_scheme': u'http',
u'PATH_INFO': u'/uvw/method1/with_query_param',
u'REMOTE_ADDR': u'192.168.0.3',
u'HTTP_HOST': u'localhost',
u'HTTP_APIKEYHEADER': u'my-header-value',
u'HTTP_REFERER': u'example.myreferer.com',
u'REQUEST_METHOD': u'GET'}
dummy_response = messages.CheckResponse(operationId=u'fake_operation_id')
wrapped = wsgi.add_all(wrappee,
self.PROJECT_ID,
control_client,
loader=service.Loaders.ENVIRONMENT)
control_client.check.return_value = dummy_response
wrapped(given, _dummy_start_response)
expect(control_client.check.called).to(be_true)
check_request = control_client.check.call_args_list[0].checkRequest
check_req = control_client.check.call_args[0][0]
expect(check_req.checkRequest.operation.consumerId).to(
equal(u'api_key:my-header-value'))
expect(control_client.report.called).to(be_true)
report_req = control_client.report.call_args[0][0]
expect(report_req.reportRequest.operations[0].consumerId).to(
equal(u'api_key:my-header-value'))
示例8: test_signals_resend_on_1st_call_after_flush_interval_with_errors
def test_signals_resend_on_1st_call_after_flush_interval_with_errors(self):
req = _make_test_request(self.SERVICE_NAME)
failure_code = messages.CheckError.CodeValueValuesEnum.NOT_FOUND
fake_response = messages.CheckResponse(
operationId=self.FAKE_OPERATION_ID, checkErrors=[
messages.CheckError(code=failure_code)
])
agg = self.agg
expect(agg.check(req)).to(be_none)
agg.add_response(req, fake_response)
expect(agg.check(req)).to(equal(fake_response))
# Now flush interval is reached, but not the response expiry
self.timer.tick() # now past the flush_interval
expect(agg.check(req)).to(be_none) # first response is null
# until expiry, the response will continue to be returned
expect(agg.check(req)).to(equal(fake_response))
expect(agg.check(req)).to(equal(fake_response))
# expire
self.timer.tick()
self.timer.tick() # now expired
expect(agg.check(req)).to(be_none)
expect(agg.check(req)).to(be_none) # 2nd check is None as well
示例9: test_should_create_with_defaults
def test_should_create_with_defaults(self):
options = caches.CheckOptions()
expect(options.num_entries).to(equal(
caches.CheckOptions.DEFAULT_NUM_ENTRIES))
expect(options.flush_interval).to(equal(
caches.CheckOptions.DEFAULT_FLUSH_INTERVAL))
expect(options.expiration).to(equal(
caches.CheckOptions.DEFAULT_EXPIRATION))
示例10: test_should_ignores_lower_expiration
def test_should_ignores_lower_expiration(self):
wanted_expiration = (
self.AN_INTERVAL + datetime.timedelta(milliseconds=1))
options = caches.CheckOptions(flush_interval=self.AN_INTERVAL,
expiration=self.A_LOWER_INTERVAL)
expect(options.flush_interval).to(equal(self.AN_INTERVAL))
expect(options.expiration).to(equal(wanted_expiration))
expect(options.expiration).not_to(equal(self.A_LOWER_INTERVAL))
示例11: test_should_construct_with_ok_expected_args
def test_should_construct_with_ok_expected_args(self):
rules = self.subject_cls(logs=[u'wanted_log'],
metrics=self.WANTED_METRICS,
labels=self.WANTED_LABELS)
expect(rules).not_to(be_none)
expect(rules.logs).to(equal(set([u'wanted_log'])))
expect(rules.metrics).to(equal(self.WANTED_METRICS))
expect(rules.labels).to(equal(self.WANTED_LABELS))
示例12: test_should_merge_stats_correctly
def test_should_merge_stats_correctly(self):
# TODO(add a check of the variance)
for d1, d2, _ in self.merge_triples:
distribution.merge(d1, d2)
expect(d2.count).to(equal(2))
expect(d2.mean).to(equal((_HIGH_SAMPLE + _LOW_SAMPLE) / 2))
expect(d2.maximum).to(equal(_HIGH_SAMPLE))
expect(d2.minimum).to(equal(_LOW_SAMPLE))
示例13: it_should_insert_a_short_url
def it_should_insert_a_short_url(self):
uow = inject.instance('UnitOfWorkManager')
with uow.start() as tx:
s_url = tx.short_urls.get(self.given_sid)
expect(s_url).to(be_a(ShortUrl))
expect(s_url.url).to(equal(self.url))
expect(s_url.user).to(equal(user))
示例14: it_should_handle_the_collison_and_insert_the_url_twice
def it_should_handle_the_collison_and_insert_the_url_twice(self):
uow = inject.instance('UnitOfWorkManager')
with uow.start() as tx:
s_url1 = tx.short_urls.get('SID-123')
s_url2 = tx.short_urls.get('SID-321')
expect(s_url1.url).to(equal(self.url))
expect(s_url2.url).to(equal(self.url))
示例15: test_set_blocking_changes_fd_flags
def test_set_blocking_changes_fd_flags():
with tempfile.TemporaryFile() as f:
io.set_blocking(f, False)
flags = fcntl.fcntl(f, fcntl.F_GETFL)
expect(flags & os.O_NONBLOCK).to(equal(os.O_NONBLOCK))
io.set_blocking(f, True)
flags = fcntl.fcntl(f, fcntl.F_GETFL)
expect(flags & os.O_NONBLOCK).to(equal(0))