Exemplo n.º 1
0
    def test_expect_not_to_raise_error_can_take_callable_with_args(self):
        class SpecialException(Exception):
            pass

        argument = object()

        def callable_(x):
            if not x is argument:
                raise SpecialException('foo')

        expect(callable_, argument).not_to(raise_error(SpecialException))
Exemplo n.º 2
0
    def test_expect_not_to_raise_error_can_take_callable_with_args(self):
        class SpecialException(Exception):
            pass

        argument = object()

        def callable_(x):
            if not x is argument:
                raise SpecialException('foo')

        expect(callable_, argument).not_to(raise_error(SpecialException))
Exemplo n.º 3
0
    def test_expect_to_raise_error_can_take_callable_with_arg_and_kwargs(self):
        class SpecialException(Exception):
            pass

        argument = object()
        kwargs = dict(x=argument)

        def callable_(arg, x=None):
            if arg is argument and x is argument:
                raise SpecialException('foo')

        expect(callable_, argument, **kwargs).to(raise_error(SpecialException))
Exemplo n.º 4
0
    def test_expect_to_raise_error_can_take_callable_with_arg_and_kwargs(self):
        class SpecialException(Exception):
            pass

        argument = object()
        kwargs = dict(x=argument)

        def callable_(arg, x=None):
            if arg is argument and x is argument:
                raise SpecialException('foo')

        expect(callable_, argument, **kwargs).to(raise_error(SpecialException))
Exemplo n.º 5
0
 def test_greater_than_with_greater_value(self):
     expect(2).to(be_gt(1))
Exemplo n.º 6
0
 def test_less_than_with_greater_value(self):
     expect(1).to(be_lt(2))
Exemplo n.º 7
0
 def test_not_greater_than_with_lesser_value(self):
     expect(0).not_to(be_gt(1))
Exemplo n.º 8
0
 def test_expect_to_be_with_non_identical_object(self):
     obj = object()
     other_obj = object()
     self.assertRaises(ExpectationNotMetError,
                       expect(obj).to, be(other_obj))
Exemplo n.º 9
0
 def test_expect_member_to_be_in_list(self):
     expect(['foo', 'bar', 'baz']).to(include('foo', 'baz'))
Exemplo n.º 10
0
 def test_expect_empty_string_to_be_falsy(self):
     expect('').to(be_falsy())
Exemplo n.º 11
0
 def test_less_than_or_equal_with_greater_value(self):
     expect(1).to(be_lte(2))
Exemplo n.º 12
0
 def test_be_within_3_of_0(self):
     expect(2).to(be_within(3).of(0))
Exemplo n.º 13
0
 def test_not_less_than_with_lesser_value(self):
     expect(1).not_to(be_lt(0))
Exemplo n.º 14
0
 def test_greater_than_or_equal_with_lesser_value(self):
     expect(2).to(be_gte(1))
Exemplo n.º 15
0
 def test_not_less_than_with_greater_value(self):
     self.assertRaises(ExpectationNotMetError, expect(1).not_to, be_lt(2))
Exemplo n.º 16
0
 def test_less_than_with_lesser_value(self):
     self.assertRaises(ExpectationNotMetError, expect(1).to, be_lt(0))
Exemplo n.º 17
0
 def test_less_than_with_greater_value(self):
     expect(1).to(be_lt(2))
Exemplo n.º 18
0
 def test_not_less_than_with_greater_value(self):
     self.assertRaises(ExpectationNotMetError, expect(1).not_to, be_lt(2))
Exemplo n.º 19
0
 def test_be_within_3_of_0(self):
     expect(2).to(be_within(3).of(0))
Exemplo n.º 20
0
 def test_greater_than_or_equal_with_lesser_value(self):
     expect(2).to(be_gte(1))
Exemplo n.º 21
0
 def test_expect_string_to_match_pattern(self):
     expect('foobar').to(match(r'^[a-z]{6}$'))
Exemplo n.º 22
0
 def test_expect_string_to_be_an_instance_of_str(self):
     expect('foobar').to(be_an_instance_of(str))
Exemplo n.º 23
0
 def test_expect_string_to_be_an_instance_of_str(self):
     expect('foobar').to(be_an_instance_of(str))
Exemplo n.º 24
0
 def test_expect_string_to_be_truthy(self):
     expect('foo').to(be_truthy())
Exemplo n.º 25
0
 def test_expect_string_be_of_type_str(self):
     expect('foobar').to(be_of_type(str))
Exemplo n.º 26
0
 def test_expect_pop_from_empty_list_to_raise_IndexError(self):
     expect([].pop).to(raise_error(IndexError))
Exemplo n.º 27
0
 def test_expect_member_to_be_in_list(self):
     expect(['foo', 'bar', 'baz']).to(include('foo', 'baz'))
Exemplo n.º 28
0
 def test_expect_not_to_be_with_identical_object(self):
     obj = object()
     same_obj = obj
     self.assertRaises(ExpectationNotMetError,
                       expect(obj).not_to, be(same_obj))
Exemplo n.º 29
0
 def test_expect_something_not_to_be_in_list(self):
     expect(['foo', 'bar']).not_to(include('baz'))
Exemplo n.º 30
0
 def test_expect_not_to_be_with_non_identical_object(self):
     obj = object()
     other_obj = object()
     expect(obj).not_to(be(other_obj))
Exemplo n.º 31
0
 def test_expect_string_to_be_truthy(self):
     expect('foo').to(be_truthy())
Exemplo n.º 32
0
 def test_not_greater_than_with_lesser_value(self):
     expect(0).not_to(be_gt(1))
Exemplo n.º 33
0
 def test_expect_empty_string_not_to_be_truthy(self):
     expect('').not_to(be_truthy())
Exemplo n.º 34
0
 def test_less_than_with_lesser_value(self):
     self.assertRaises(ExpectationNotMetError, expect(1).to, be_lt(0))
Exemplo n.º 35
0
 def test_expect_empty_string_to_be_falsy(self):
     expect('').to(be_falsy())
Exemplo n.º 36
0
 def test_not_less_than_with_lesser_value(self):
     expect(1).not_to(be_lt(0))
Exemplo n.º 37
0
 def test_expect_string_not_to_be_falsy(self):
     expect('foo').not_to(be_falsy())
Exemplo n.º 38
0
 def test_less_than_or_equal_with_greater_value(self):
     expect(1).to(be_lte(2))
Exemplo n.º 39
0
 def test_expect_pop_from_empty_list_to_raise_IndexError(self):
     expect([].pop).to(raise_error(IndexError))
Exemplo n.º 40
0
 def test_expect_string_to_match_pattern(self):
     expect('foobar').to(match(r'^[a-z]{6}$'))
Exemplo n.º 41
0
 def test_expect_pop_from_list_not_to_raise_IndexError(self):
     expect([0].pop).not_to(raise_error(IndexError))
Exemplo n.º 42
0
 def test_expect_string_be_of_type_str(self):
     expect('foobar').to(be_of_type(str))
Exemplo n.º 43
0
 def test_expect_not_to_be_with_non_identical_object(self):
     obj = object()
     other_obj = object()
     expect(obj).not_to(be(other_obj))
Exemplo n.º 44
0
 def test_expect_something_not_to_be_in_list(self):
     expect(['foo', 'bar']).not_to(include('baz'))
Exemplo n.º 45
0
 def test_expect_to_be_with_non_identical_object(self):
     obj = object()
     other_obj = object()
     self.assertRaises(ExpectationNotMetError,
                       expect(obj).to, be(other_obj))
Exemplo n.º 46
0
 def test_expect_empty_string_not_to_be_truthy(self):
     expect('').not_to(be_truthy())
Exemplo n.º 47
0
from pyspec import description, specification
from pyspec.expectations import expect, eq

with description(True):
    with specification('is false'):
        expect(True).to(eq(False))
Exemplo n.º 48
0
 def test_expect_string_not_to_be_falsy(self):
     expect('foo').not_to(be_falsy())
Exemplo n.º 49
0
from pyspec import description, specification
from pyspec.expectations import expect, eq

with description(True):
    with specification('is not false'):
        expect(True).not_to(eq(False))
Exemplo n.º 50
0
 def test_expect_pop_from_list_not_to_raise_IndexError(self):
     expect([0].pop).not_to(raise_error(IndexError))
Exemplo n.º 51
0
 def test_greater_than_with_greater_value(self):
     expect(2).to(be_gt(1))
Exemplo n.º 52
0
        return n % 3 == 0

    def is_buzz(self, n):
        return n % 5 == 1


with description(BrokenFizzBuzz):

    fizzbuzz = BrokenFizzBuzz()
    some_integer = 7

    with description('.convert'):

        with context(15):
            with specification('returns fizzbuzz'):
                expect(fizzbuzz.convert(15)).to(eq('fizzbuzz'))

        with context(3):
            with specification('returns fizz'):
                expect(fizzbuzz.convert(3)).to(eq('fizz'))

        with context(5):
            with specification('returns buzz'):
                expect(fizzbuzz.convert(5)).to(eq('buzz'))

        with context('some other integer'):
            with specification('returns the integer'):
                expect(fizzbuzz.convert(some_integer)).to(eq(some_integer))

    with description('.floop'):
        with specification('does not exist'):
Exemplo n.º 53
0
 def test_expect_to_be_with_identical_object(self):
     obj = object()
     same_obj = obj
     expect(obj).to(be(same_obj))
Exemplo n.º 54
0
from pyspec import description, specification
from pyspec.expectations import expect, eq

with description(object):
    subject = object()
    with description('.foobar'):
        with specification('is not a thing'):
            expect(subject.foobar).to(eq(None))
Exemplo n.º 55
0
 def test_expect_not_to_be_with_identical_object(self):
     obj = object()
     same_obj = obj
     self.assertRaises(ExpectationNotMetError,
                       expect(obj).not_to, be(same_obj))
Exemplo n.º 56
0
    def is_fizz(self, n):
        return n % 3 == 0

    def is_buzz(self, n):
        return n % 5 == 1

with description(BrokenFizzBuzz):

    fizzbuzz = BrokenFizzBuzz()
    some_integer = 7

    with description('.convert'):

        with context(15):
            with specification('returns fizzbuzz'):
                expect(fizzbuzz.convert(15)).to(eq('fizzbuzz'))

        with context(3):
            with specification('returns fizz'):
                expect(fizzbuzz.convert(3)).to(eq('fizz'))

        with context(5):
            with specification('returns buzz'):
                expect(fizzbuzz.convert(5)).to(eq('buzz'))

        with context('some other integer'):
            with specification('returns the integer'):
                expect(fizzbuzz.convert(some_integer)).to(
                    eq(some_integer))

    with description('.floop'):
Exemplo n.º 57
0
 def test_expect_to_be_with_identical_object(self):
     obj = object()
     same_obj = obj
     expect(obj).to(be(same_obj))