本文整理汇总了Python中expects.testing.failure函数的典型用法代码示例。如果您正苦于以下问题:Python failure函数的具体用法?Python failure怎么用?Python failure使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了failure函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_should_fail_if_actual_has_expected_header_without_value
def test_should_fail_if_actual_has_expected_header_without_value(self):
with failure(
self.response,
"to have header {!r} with value {!r} but was".format(IRRELEVANT_HEADER_KEY1, IRRELEVANT_HEADER_VALUE3),
):
expect(response=self.response).to.have.header(IRRELEVANT_HEADER_KEY1, IRRELEVANT_HEADER_VALUE3)
示例2: it_should_fail_if_actual_has_key_in_kwargs_but_not_in_args
def it_should_fail_if_actual_has_key_in_kwargs_but_not_in_args():
with failure(_.dct, "not to have key 'bar' with value 0 but was 0"):
expect(_.dct).not_to.have.keys('foo', bar=0)
def it_should_fail_if_actual_has_key_in_dict_with_value():
with failure(_.dct, "not to have key 'bar' with value 0 but was 0"):
expect(_.dct).not_to.have.keys({'bar': 0, 'foo': 1})
示例3: test_should_fail_if_actual_has_expected_header_and_value
def test_should_fail_if_actual_has_expected_header_and_value(self):
with failure(
self.response,
"not to have header {!r} with value {!r}".format(IRRELEVANT_HEADER_KEY1, IRRELEVANT_HEADER_VALUE1),
):
expect(response=self.response).not_to.have.header(IRRELEVANT_HEADER_KEY1, IRRELEVANT_HEADER_VALUE1)
示例4: test_should_fail_if_actual_has_header_without_value_in_kwargs
def test_should_fail_if_actual_has_header_without_value_in_kwargs(self):
with failure(self.response,
"to have header 'content-length' with value '25'"):
expect(response=self.response).to.have.headers(
content_type=IRRELEVANT_HEADER_VALUE1,
content_length='25')
示例5: it_should_fail_if_actual_raises_expected_exception_with_message
def it_should_fail_if_actual_raises_expected_exception_with_message():
message = 'Foo error'
failure_message = 'not to raise AttributeError with message {} but message was {}'.format(
repr(message), repr(message))
def callback():
raise AttributeError(message)
with failure(callback, failure_message):
expect(callback).not_to.raise_error(AttributeError, message)
示例6: it_should_fail_if_actual_raises_but_message_does_not_match_pattern
def it_should_fail_if_actual_raises_but_message_does_not_match_pattern():
pattern = r'\W+ error'
def callback():
raise AttributeError(_.message)
with failure(callback, "to raise AttributeError with "
"message {} but message was {}"
.format(repr(pattern), repr(_.message))):
expect(callback).to.raise_error(AttributeError, pattern)
示例7: callback
def callback():
with failure(have_length(0)):
raise AssertionError('foo')
示例8: expect
expect(callback).to(raise_error(AssertionError))
with it('fails if another exception raised'):
def callback():
with failure:
raise KeyError()
expect(callback).to(raise_error(AssertionError))
with context('with message'):
with before.each:
self.message = "to be 'bar'"
self.pattern = "to be '\w+'"
with it('passes if assertion raised and message ends with'):
with failure(self.message):
raise AssertionError("Expected 'foo' {0}".format(self.message))
with it('passes if assertion error raised and message matches'):
with failure(match(self.pattern)):
raise AssertionError("Expected 'foo' {0}".format(self.message))
with it('passes if assertion error raised and message has length 0'):
with failure(have_length(0)):
raise AssertionError('')
with it('fails if assertion error not raised'):
def callback():
with failure(self.message):
pass
示例9: describe
# -*- coding: utf-8 -*
from expects import *
from expects.testing import failure
with describe('be_above_or_equal'):
with it('should pass if number is above expected'):
expect(5).to(be_above_or_equal(4))
with it('should pass if number equals expected'):
expect(5).to(be_above_or_equal(5))
with it('should fail if number is not above or equal expected'):
with failure('expected: 1 to be above or equal 4'):
expect(1).to(be_above_or_equal(4))
with context('when negated'):
with it('should pass if number is not above or equal expected'):
expect(1).not_to(be_above_or_equal(4))
with it('should fail if number is above expected'):
with failure('expected: 5 not to be above or equal 4'):
expect(5).not_to(be_above_or_equal(4))
with it('should fail if number equals expected'):
with failure('expected: 5 not to be above or equal 5'):
expect(5).not_to(be_above_or_equal(5))
示例10: it_should_fail_if_actual_iterable_does_not_have_the_expected_length
def it_should_fail_if_actual_iterable_does_not_have_the_expected_length():
actual = iter('foo')
with failure(actual, 'to have length 2 but was 3'):
expect(actual).to.have.length(2)
示例11: it_should_fail_if_actual_is_not_above_expected
def it_should_fail_if_actual_is_not_above_expected():
with failure(1, 'to be above 4'):
expect(1).to.be.above(4)
示例12: it_should_fail_if_actual_is_false
def it_should_fail_if_actual_is_false():
with failure(False, "to be True"):
expect(False).to.be.true
示例13: describe
# -*- coding: utf-8 -*
from expects import *
from expects.testing import failure
with describe("be_false"):
with it("should pass if object is false"):
expect(False).to(be_false)
with it("should fail if object is true"):
with failure("Expected True to be false"):
expect(True).to(be_false)
with context("#negated"):
with it("should pass if object is not false"):
expect(True).not_to(be_false)
with it("should fail if object is false"):
with failure("Expected False not to be false"):
expect(False).not_to(be_false)
示例14: describe
from expects.testing import failure
with describe('have_len'):
with it('passes if string has the expected length'):
expect('foo').to(have_len(3))
with it('passes if string has length matching'):
expect('foo').to(have_len(above_or_equal(3)))
with it('passes if iterable has the expected length'):
expect(iter('foo')).to(have_len(3))
with it('fails if string does not have the expected length'):
with failure("but: was 3"):
expect('foo').to(have_len(2))
with it('fails if string does not have length matching'):
with failure("but: was 3"):
expect('foo').to(have_len(below(3)))
with it('fails if iterable does not have the expected length'):
with failure("but: was 3"):
expect(iter('foo')).to(have_len(2))
with context('when negated'):
with it('passes if string does not have the expected length'):
expect('foo').not_to(have_len(2))
with it('fails if string has the expected length'):
示例15: it_should_fail_if_actual_has_property_in_kwargs_but_not_in_args
def it_should_fail_if_actual_has_property_in_kwargs_but_not_in_args():
with failure(_.obj, "not to have property 'bar' with value 0 but was 0"):
expect(_.obj).not_to.have.properties('foo', bar=0)