Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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')
Exemplo n.º 4
0
        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})
Exemplo n.º 5
0
    def test(self):
#         expect_diff = '''\
# expected                                got
# {'spam_code': 'spam',                   {'spam_code': 'spam',
#  'spam_count': 4295,
#  'spam_id': '32102903',                  'spam_id': '32102903',
#  'spam_method': 'thorough',              'spam_method': 'thorough',
#  'spam_transaction': 'ABS32402983SAJFD   'spam_transaction': 'ABS32402983SAJFD
# AJFS',                                  AJFS',
#  'spam_type': 'full',                    'spam_type': 'full',
#  'spamspamspamspam': '2016-08-26T15:20   'spamspamspamspam': '2016-08-26T15:21
# :12Z'}                                  :12Z'}

# '''
        expect_value = {
            "spam_id": "32102903",
            "spam_code": "spam",
            "spam_count": 4295,
            "spam_method": "thorough",
            "spam_type": "full",
            "spamspamspamspam": "2016-08-26T15:20:12Z",
            "spam_transaction": "ABS32402983SAJFDAJFS"
        }
        got_value = {
            "spam_id": "32102903",
            "spam_code": "spam",
            "spam_method": "thorough",
            "spam_type": "full",
            "spamspamspamspam": "2016-08-26T15:21:12Z",
            "spam_transaction": "ABS32402983SAJFDAJFS"
        }
        expect_snippet = ("'spamspamspamspam': '2016-08-26T15:2\x1b[0;33m1\x1b[m \n\x1b[0;33m\x1b[m:12Z'}")
        with failure(contain(expect_snippet)):
            expect(got_value).to(icdiff_expects.equal(expect_value))
Exemplo n.º 6
0
        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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
 def it_should_fail_if_actual_does_not_have_property_in_args_but_in_kwargs():
     with failure(_.obj, "to have property 'foo'"):
         expect(_.obj).to.have.properties('foo', bar=0)
Exemplo n.º 9
0
# -*- coding: utf-8 -*

from expects import *
from expects.testing import failure


with describe('be_below'):
    with it('should pass if number is below expected'):
        expect(1).to(be_below(4))

    with it('should fail if number is not below expected'):
        with failure('expected: 4 to be below 1'):
            expect(4).to(be_below(1))

    with context('#negated'):
        with it('should pass if number is not below expected'):
            expect(4).not_to(be_below(1))

        with it('should fail if number is below expected'):
            with failure('expected: 1 not to be below 4'):
                expect(1).not_to(be_below(4))
Exemplo n.º 10
0
 def it_should_fail_if_actual_is_false():
     with failure(False, "to be True"):
         expect(False).to.be.true
Exemplo n.º 11
0
        self.str = 'My foo string'

    with it('passes if dict has keys in args'):
        expect(self.dct).to(have_keys('bar', 'baz'))

    with it('passes if dict has keys in kwargs'):
        expect(self.dct).to(have_keys(bar=0, baz=1))

    with it('passes if dict has keys in args and kwargs'):
        expect(self.dct).to(have_keys('bar', baz=1))

    with it('passes if dict has keys in dict'):
        expect(self.dct).to(have_keys({'bar': 0, 'baz': 1}))

    with it('fails if dict does not have key in args'):
        with failure("but: key 'foo' not found"):
            expect(self.dct).to(have_keys('bar', 'foo'))

    with it('fails if dict does not have key in kwargs'):
        with failure("but: key 'foo' equal 1 not found"):
            expect(self.dct).to(have_keys(bar=0, foo=1))

    with it('fails if dict has key without value in kwargs'):
        with failure("but: key 'bar' equal 1 not found"):
            expect(self.dct).to(have_keys(bar=1, baz=1))

    with it('fails if dict does not have key in args but in kwargs'):
        with failure("but: key 'foo' not found"):
            expect(self.dct).to(have_keys('foo', 'fuu', bar=0))

    with it('fails if dict has key in args and kwargs without value'):
Exemplo n.º 12
0
 def callback():
     with failure(self.message):
         pass
Exemplo n.º 13
0
# -*- 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))
Exemplo n.º 14
0
 def it_should_fail_if_actual_is_not_above_expected():
     with failure(1, 'to be above 4'):
         expect(1).to.be.above(4)
Exemplo n.º 15
0
from expects.testing import failure


with describe('match'):
    with before.all:
        self.str = 'My foo string'

    with it('passes if string matches expected regexp'):
        expect(self.str).to(match(r'My \w+ string'))

    with it('passes if part of the string matches expected regexp'):
        expect(self.str).to(match(r'\w+ string'))

    with it('passes if string matches expected regexp with re flags'):
        expect(self.str).to(match(r'my [A-Z]+ strinG', re.I))

    with it('fails if string does not match expected regexp'):
        with failure("to match 'My \\\\W+ string'"):
            expect(self.str).to(match(r'My \W+ string'))

    with context('when negated'):
        with it('passes if string does not match expected regexp'):
            expect(self.str).not_to(match(r'My \W+ string'))

        with it('passes if string does not match expected regexp with re flags'):
            expect(self.str).not_to(match(r'My \W+ string', re.I))

        with it('fails if string matches expected regexp'):
            with failure("not to match 'My \\\\w+ string'"):
                expect(self.str).not_to(match(r'My \w+ string'))
Exemplo n.º 16
0
# -*- coding: utf-8 -*

from expects import *
from expects.testing import failure

with describe('be_below'):
    with it('should pass if number is below expected'):
        expect(1).to(be_below(4))

    with it('should fail if number is not below expected'):
        with failure('expected: 4 to be below 1'):
            expect(4).to(be_below(1))

    with context('#negated'):
        with it('should pass if number is not below expected'):
            expect(4).not_to(be_below(1))

        with it('should fail if number is below expected'):
            with failure('expected: 1 not to be below 4'):
                expect(1).not_to(be_below(4))
Exemplo n.º 17
0
# -*- coding: utf-8 -*

from expects import *
from expects.testing import failure

with describe('be_none'):
    with it('should pass if object is none'):
        expect(None).to(be_none)

    with it('should fail if object is not none'):
        with failure('expected: True to be none'):
            expect(True).to(be_none)

    with context('#negated'):
        with it('should pass if object is not none'):
            expect('foo').not_to(be_none)

        with it('should fail if object is none'):
            with failure('expected: None not to be none'):
                expect(None).not_to(be_none)
Exemplo n.º 18
0
from expects.aliases import *
from expects.testing import failure

with describe('have_key'):
    with before.all:
        self.dct = {'bar': 0, 'baz': 1}
        self.str = 'My foo string'

    with it('should pass if actual has expected key'):
        expect(self.dct).to(have_key('bar'))

    with it('should pass if actual has key and value'):
        expect(self.dct).to(have_key('bar', 0))

    with it('should fail if actual does not have expected key'):
        with failure("but: key 'foo' not found"):
            expect(self.dct).to(have_key('foo'))

    with it('should fail if actual does not have key with value'):
        with failure("but: key 'foo' equal 0 not found"):
            expect(self.dct).to(have_key('foo', 0))

    with it('should fail if actual has key without expected value'):
        with failure("but: key 'bar' equal 1 not found"):
            expect(self.dct).to(have_key('bar', 1))

    with it('should fail if actual has key without none value'):
        with failure("but: key 'bar' equal None not found"):
            expect(self.dct).to(have_key('bar', None))

    with it('should fail if actual is not a dict'):
Exemplo n.º 19
0
        expect(self.lst).to(contain_only(*reversed(self.lst)))

    with it('passes if iterable only has items'):
        expect(self.itr).to(contain_only('bar', 'baz'))

    with it('passes if string only contains string'):
        expect(self.str).to(contain_only(self.str))

    with it('passes if string only contains strings'):
        expect(self.str).to(contain_only('My foo', ' string'))

    with it('passes if list only has expected matching items'):
        expect(self.lst).to(contain_only(equal('bar'), equal('baz')))

    with it('fails if list does not have item'):
        with failure("but: item equal 'foo' not found"):
            expect(self.lst).to(contain_only('foo'))

    with it('fails if list has two expected items but has a different length'):
        self.lst.append('foo')

        with failure("but: have a different length"):
            expect(self.lst).to(contain_only('bar', 'baz'))

    with it('fails if string contains string and more'):
        with failure("but: have a different length"):
            expect(self.str).to(contain_only('foo'))

    with it('fails if string does not contain item'):
        with failure("but: item 'bar' not found"):
            expect(self.str).to(contain_only('bar'))
Exemplo n.º 20
0
# -*- coding: utf-8 -*

from expects import *
from expects.testing import failure

with describe('be_true'):
    with it('should pass if object is true'):
        expect(True).to(be_true)

    with it('should fail if object is false'):
        with failure('expected: False to be true'):
            expect(False).to(be_true)

    with context('#negated'):
        with it('should pass if object is not true'):
            expect(False).not_to(be_true)

        with it('should fail if object is true'):
            with failure('expected: True not to be true'):
                expect(True).not_to(be_true)
Exemplo n.º 21
0
        expect(self.lst).to(contain_only(*reversed(self.lst)))

    with it('passes if iterable only has items'):
        expect(self.itr).to(contain_only('bar', 'baz'))

    with it('passes if string only contains string'):
        expect(self.str).to(contain_only(self.str))

    with it('passes if string only contains strings'):
        expect(self.str).to(contain_only('My foo', ' string'))

    with it('passes if list only has expected matching items'):
        expect(self.lst).to(contain_only(equal('bar'), equal('baz')))

    with it('fails if list does not have item'):
        with failure("but: item equal 'foo' not found"):
            expect(self.lst).to(contain_only('foo'))

    with it('fails if list has two expected items but has a different length'):
        self.lst.append('foo')

        with failure("but: have a different length"):
            expect(self.lst).to(contain_only('bar', 'baz'))

    with it('fails if string contains string and more'):
        with failure("but: have a different length"):
            expect(self.str).to(contain_only('foo'))

    with it('fails if string does not contain item'):
        with failure("but: item 'bar' not found"):
            expect(self.str).to(contain_only('bar'))
Exemplo n.º 22
0
 def it_should_fail_if_actual_has_property_without_value_in_dict():
     with failure(_.obj, "to have property 'bar' with value 1 but was 0"):
         expect(_.obj).to.have.properties({'bar': 1, 'baz': 1})
Exemplo n.º 23
0
 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)
Exemplo n.º 24
0
# -*- coding: utf-8 -*

from expects import *
from expects.testing import failure

with describe('be_empty'):
    with it('should pass if string empty'):
        expect('').to(be_empty)

    with it('should pass if iterable is empty'):
        expect(iter('')).to(be_empty)

    with it('should fail if string is not empty'):
        with failure("expected: 'foo' to be empty"):
            expect('foo').to(be_empty)

    with it('should fail if actual is a non empty iterable'):
        with failure('to be empty'):
            expect(iter('foo')).to(be_empty)

    with context('#negated'):
        with it('should pass if actual is not empty'):
            expect('foo').not_to(be_empty)

        with it('should fail if actual is empty'):
            with failure("expected: '' not to be empty"):
                expect('').not_to(be_empty)
Exemplo n.º 25
0
    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)
Exemplo n.º 26
0
        expect(self.lst).to(contain_exactly(*self.lst))

    with it('passes if list contains exactly matching items'):
        expect(self.lst).to(contain_exactly(equal('bar'), equal('baz')))

    with it('passes if iterable contains item'):
        expect(self.itr).to(contain_exactly('bar', 'baz'))

    with it('passes if string exactly contains string'):
        expect(self.str).to(contain_exactly(self.str))

    with it('passes if string exactly contains strings'):
        expect(self.str).to(contain_exactly('My foo', ' string'))

    with it('fails if list contains fewer elements that the expected one'):
        with failure("but: item equal 'bar' not found at index 1"):
            expect(['foo']).to(contain_exactly('foo', 'bar'))

    with it('fails if list does not contain expected item'):
        with failure("but: item equal 'foo' not found at index 0"):
            expect(self.lst).to(contain_exactly('foo'))

    with it('fails if list does not contain expected items'):
        with failure("but: item equal 'foo' not found at index 0"):
            expect(self.lst).to(contain_exactly('foo', 'fuu'))

    with it('fails if list does not contain expected items in order'):
        with failure("but: item equal 'baz' not found at index 0"):
            expect(self.lst).to(contain_exactly('baz', 'bar'))

    with it('fails if list has the given item and more'):
Exemplo n.º 27
0
# -*- coding: utf-8 -*

from expects import *
from expects.testing import failure

with describe('matcher & matcher'):
    with it('passes if both matchers match'):
        expect(True).to(be_true & be_true)

    with it('fails if one matcher does not match'):
        with failure('be above 0 and equal 2'):
            expect(1).to(be_above(0) & equal(2))

with describe('matcher & matcher & matcher'):
    with it('passes if all matchers match'):
        expect(True).to(be_true & be_true & be_true)

    with it('fails if one matcher does not match'):
        with failure('be above 0, equal 2 and be an int'):
            expect(1).to(be_above(0) & equal(2) & be_an(int))
Exemplo n.º 28
0
# -*- 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)
Exemplo n.º 29
0
 def callback():
     with failure(self.message):
         raise KeyError()
Exemplo n.º 30
0
        expect(self.lst).to(contain_exactly(*self.lst))

    with it('passes if list contains exactly matching items'):
        expect(self.lst).to(contain_exactly(equal('bar'), equal('baz')))

    with it('passes if iterable contains item'):
        expect(self.itr).to(contain_exactly('bar', 'baz'))

    with it('passes if string exactly contains string'):
        expect(self.str).to(contain_exactly(self.str))

    with it('passes if string exactly contains strings'):
        expect(self.str).to(contain_exactly('My foo', ' string'))

    with it('fails if list contains fewer elements that the expected one'):
        with failure("but: item equal 'bar' not found at index 1"):
            expect(['foo']).to(contain_exactly('foo', 'bar'))

    with it('fails if list does not contain expected item'):
        with failure("but: item equal 'foo' not found at index 0"):
            expect(self.lst).to(contain_exactly('foo'))

    with it('fails if list does not contain expected items'):
        with failure("but: item equal 'foo' not found at index 0"):
            expect(self.lst).to(contain_exactly('foo', 'fuu'))

    with it('fails if list does not contain expected items in order'):
        with failure("but: item equal 'baz' not found at index 0"):
            expect(self.lst).to(contain_exactly('baz', 'bar'))

    with it('fails if list has the given item and more'):
Exemplo n.º 31
0
# -*- 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)
Exemplo n.º 32
0
# -*- 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))
Exemplo n.º 33
0
 def it_should_fail_if_actual_is_true():
     with failure(True, "not to be True"):
         expect(True).not_to.be.true
Exemplo n.º 34
0
# -*- coding: utf-8 -*

from expects import *
from expects.testing import failure

with describe('equal'):
    with it('should pass if number equals expected'):
        expect(1).to(equal(1))

    with it('should fail if number does not equal expected'):
        with failure('expected: 1 to equal 2'):
            expect(1).to(equal(2))

    with context('#negated'):
        with it('should pass if number does not equal expected'):
            expect(1).not_to(equal(2))

        with it('should fail if number equals expected'):
            with failure('expected: 1 not to equal 1'):
                expect(1).not_to(equal(1))
Exemplo n.º 35
0
# -*- coding: utf-8 -*

from expects import *
from expects.testing import failure


with describe("be"):
    with it("should pass if object is expected"):
        value = 1
        expect(value).to(be(value))

    with it("should fail if object is not expected"):
        with failure("Expected 1 to be 2"):
            expect(1).to(be(2))

    with context("#negated"):
        with it("should pass if object is not expected"):
            expect(1).not_to(be(2))

        with it("should fail if object is expected"):
            value = 1

            with failure("Expected 1 not to be 1"):
                expect(value).not_to(be(value))
Exemplo n.º 36
0
# -*- coding: utf-8 -*

from expects import *
from expects.testing import failure

with describe('be_within'):
    with it('should pass if integer is within expected range'):
        expect(5).to(be_within(4, 7))

    with it('should pass if float is within expected range'):
        expect(5.5).to(be_within(4, 7))

    with it('should fail if integer is not within expected range'):
        with failure('expected: 1 to be within 4 and 7'):
            expect(1).to(be_within(4, 7))

    with context('#negated'):
        with it('should pass if integer is not within expected range'):
            expect(1).not_to(be_within(4, 7))

        with it('should fail if integer is within expected range'):
            with failure('expected: 5 not to be within 4 and 7'):
                expect(5).not_to(be_within(4, 7))
Exemplo n.º 37
0
 def it_should_fail_if_actual_has_property_in_args_and_kwargs_without_value():
     with failure(_.obj, "to have property 'bar' with value 1 but was 0"):
         expect(_.obj).to.have.properties('baz', bar=1)
Exemplo n.º 38
0
        # https://github.com/jaimegildesagredo/expects/issues/42

        expect({'bar': 0, 'baz': 1}.keys()).to(contain('bar'))

    with it('passes if dict.keys() contains item'):
        # https://github.com/jaimegildesagredo/expects/issues/42

        expect({'bar': 0, 'baz': 1}.keys()).to(contain('bar'))

    with it('passes if set contains item'):
        # https://github.com/jaimegildesagredo/expects/issues/38

        expect(set(self.lst)).to(contain('bar'))

    with it('fails if list does not contain item'):
        with failure("but: item equal 'foo' not found"):
            expect(self.lst).to(contain('bar', 'foo'))

    with it('fails if list is empty'):
        with failure("but: is empty"):
            expect([]).to(contain('foo'))

    with it('fails if iterable does not contain item'):
        with failure("but: item equal 'foo' not found"):
            expect(self.itr).to(contain('bar', 'foo'))

    with it('fails if is not an iterable object'):
        with failure("but: is not a valid sequence type"):
            expect(object()).to(contain('bar'))

    with it('fails if list does not contain items matching'):
Exemplo n.º 39
0
 def it_should_fail_if_actual_has_property_in_args():
     with failure(_.obj, "not to have property 'bar'"):
         expect(_.obj).not_to.have.properties('foo', 'bar')
Exemplo n.º 40
0
# -*- coding: utf-8 -*

from expects import *
from expects.testing import failure

with describe('be_above'):
    with it('should pass if number is above expected'):
        expect(5).to(be_above(4))

    with it('should fail if number is not above expected'):
        with failure('expected: 1 to be above 4'):
            expect(1).to(be_above(4))

    with context('#negated'):
        with it('should pass if number is not above expected'):
            expect(1).not_to(be_above(4))

        with it('should fail if number is above expected'):
            with failure('expected: 5 not to be above 4'):
                expect(5).not_to(be_above(4))
Exemplo n.º 41
0
 def it_should_fail_if_actual_has_property_in_dict_with_value():
     with failure(_.obj, "not to have property 'bar' with value 0 but was 0"):
         expect(_.obj).not_to.have.properties({'bar': 0, 'foo': 1})
Exemplo n.º 42
0
        expect(callback).to(raise_error(AttributeError, self.message))

    with it('passes if callable raises with non string value'):

        def callback():
            raise AttributeError(1)

        expect(callback).to(raise_error(AttributeError, 1))

    with it('fails if callable does not raise any exception'):

        def callback():
            pass

        with failure('but: no exception raised'):
            expect(callback).to(raise_error)

    with it('fails if callable does not raise expected exception'):

        def callback():
            raise KeyError()

        with failure(contain('but: KeyError raised')):
            expect(callback).to(raise_error(AttributeError))

    with it('fails if callable does not raise exception'):
        with failure('but: no exception raised'):
            expect(lambda: None).to(raise_error(AttributeError))

    with it('fails if callable raises with different message'):
Exemplo n.º 43
0
 def it_should_fail_if_actual_is_above_expected():
     with failure(5, 'not to be above 4'):
         expect(5).not_to.be.above(4)
Exemplo n.º 44
0
# -*- coding: utf-8 -*

from expects import *
from expects.testing import failure

with describe('be'):
    with it('should pass if object is expected'):
        value = 1
        expect(value).to(be(value))

    with it('should fail if object is not expected'):
        with failure('expected: 1 to be 2'):
            expect(1).to(be(2))

    with context('#negated'):
        with it('should pass if object is not expected'):
            expect(1).not_to(be(2))

        with it('should fail if object is expected'):
            value = 1

            with failure('expected: 1 not to be 1'):
                expect(value).not_to(be(value))
Exemplo n.º 45
0
        def it_should_fail_if_actual_has_the_expected_length():
            actual = 'foo'

            with failure(actual, 'not to have length 3 but was 3'):
                expect(actual).not_to.have.length(3)
Exemplo n.º 46
0
        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 = r"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
Exemplo n.º 47
0
        self.str = 'My foo string'

    with it('should_pass_if_dict_has_keys_in_args'):
        expect(self.dct).to(have_keys('bar', 'baz'))

    with it('should_pass_if_dict_has_keys_in_kwargs'):
        expect(self.dct).to(have_keys(bar=0, baz=1))

    with it('should_pass_if_dict_has_keys_in_args_and_kwargs'):
        expect(self.dct).to(have_keys('bar', baz=1))

    with it('should_pass_if_dict_has_keys_in_dict'):
        expect(self.dct).to(have_keys({'bar': 0, 'baz': 1}))

    with it('should_fail_if_dict_does_not_have_key_in_args'):
        with failure("to have keys 'bar' and 'foo'"):
            expect(self.dct).to(have_keys('bar', 'foo'))

    with it('should_fail_if_dict_does_not_have_key_in_kwargs'):
        with failure("to have keys 'bar' equal 0 and 'foo' equal 1"):
            expect(self.dct).to(have_keys(bar=0, foo=1))

    with it('should_fail_if_dict_has_key_without_value_in_kwargs'):
        with failure("to have keys 'bar' equal 1 and 'baz' equal 1"):
            expect(self.dct).to(have_keys(bar=1, baz=1))

    with it('should_fail_if_dict_does_not_have_key_in_args_but_in_kwargs'):
        with failure("to have keys 'foo', 'fuu' and 'bar' equal 0"):
            expect(self.dct).to(have_keys('foo', 'fuu', bar=0))

    with it('should_fail_if_dict_has_key_in_args_and_kwargs_without_value'):
Exemplo n.º 48
0
 def callback():
     with failure(self.message):
         raise AssertionError('foo')
Exemplo n.º 49
0
            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
Exemplo n.º 50
0
 def callback():
     with failure(have_length(0)):
         raise AssertionError('foo')
Exemplo n.º 51
0
 def callback():
     with failure(self.message):
         raise AssertionError('foo')
Exemplo n.º 52
0
# -*- coding: utf-8 -*

from expects import *
from expects.testing import failure


with describe('be_below_or_equal'):
    with it('should pass if number is below expected'):
        expect(1).to(be_below_or_equal(4))

    with it('should pass if number is equals expected'):
        expect(5).to(be_below_or_equal(5))

    with it('should fail if number is not below or equal expected'):
        with failure('expected: 4 to be below or equal 1'):
            expect(4).to(be_below_or_equal(1))

    with context('#negated'):
        with it('should pass if number is not below or equal expected'):
            expect(4).not_to(be_below_or_equal(1))

        with it('should fail if number is below expected'):
            with failure('expected: 1 not to be below or equal 4'):
                expect(1).not_to(be_below_or_equal(4))

        with it('should fail if number equals expected'):
            with failure('expected: 5 not to be below or equal 5'):
                expect(5).not_to(be_below_or_equal(5))
Exemplo n.º 53
0
 def callback():
     with failure(have_length(0)):
         raise AssertionError('foo')
Exemplo n.º 54
0
        expect(self.method).to(
            have_been_called_with(be_a(type(self.arg1)),
                                  be_a(type(self.arg2))))

    with it('passes if called with keyword args matching matchers'):
        self.method(**self.kwargs)

        expect(self.method).to(
            have_been_called_with(
                **{k: be_a(type(v))
                   for k, v in self.kwargs.items()}))

    with it('fails if not called with positional arg'):
        self.method()

        with failure("calls were:\n          Spy.method()"):
            expect(self.method).to(have_been_called_with(self.arg1))

    with it('fails if not called with keyword args'):
        self.method()

        with failure:
            expect(self.method).to(have_been_called_with(**self.kwargs))

    with context('when negated'):
        with it('passes if called with different positional arg'):
            self.method(self.arg1)

            expect(self.method).not_to(
                have_been_called_with(self.arg1, self.arg2))
Exemplo n.º 55
0
 def callback():
     with failure(self.message):
         pass
Exemplo n.º 56
0
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'):
Exemplo n.º 57
0
 def callback():
     with failure(self.message):
         raise KeyError()
Exemplo n.º 58
0
from expects.aliases import *

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'):
Exemplo n.º 59
0
# -*- coding: utf-8 -*

from expects import *
from expects.testing import failure


with describe('matcher | matcher'):
    with it('passes if both matchers match'):
        expect(True).to(be_true | be_true)

    with it('passes if one matcher does not match'):
        expect(True).to(be_false | be_true)

    with it('fails if both matchers do not match'):
        with failure(contain(' or ')):
            expect(1).to(be_below(0) | equal(2))

with describe('matcher | matcher | matcher'):
    with it('passes if all matchers match'):
        expect(True).to(be_true | be_true | be_true)

    with it('passes if one matcher matchs'):
        expect(True).to(be_false | be_false | be_true)

    with it('fails if all matchers do not match'):
        with failure(contain(', ') & contain(' or ')):
            expect(1).to(be_below(0) |
                         equal(2) |
                         be_a(str))
Exemplo n.º 60
0
    with before.each:
        self.method = doublex.Spy().method

    with it('passes if method called'):
        self.method()

        expect(self.method).to(have_been_called)

    with it('passes if method called twice'):
        self.method()
        self.method()

        expect(self.method).to(have_been_called)

    with it('fails if method not called'):
        with failure("calls were:\n          No one"):
            expect(self.method).to(have_been_called)

    with context('when negated'):
        with it('passes if not called'):
            expect(self.method).not_to(have_been_called)

        with it('fails if called'):
            self.method()

            with failure:
                expect(self.method).not_to(have_been_called)

    with describe('once'):
        with it('passes if called once'):
            self.method()