Exemple #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))
Exemple #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))
Exemple #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))
Exemple #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))
Exemple #5
0
 def test_greater_than_with_greater_value(self):
     expect(2).to(be_gt(1))
Exemple #6
0
 def test_less_than_with_greater_value(self):
     expect(1).to(be_lt(2))
Exemple #7
0
 def test_not_greater_than_with_lesser_value(self):
     expect(0).not_to(be_gt(1))
Exemple #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))
Exemple #9
0
 def test_expect_member_to_be_in_list(self):
     expect(['foo', 'bar', 'baz']).to(include('foo', 'baz'))
Exemple #10
0
 def test_expect_empty_string_to_be_falsy(self):
     expect('').to(be_falsy())
Exemple #11
0
 def test_less_than_or_equal_with_greater_value(self):
     expect(1).to(be_lte(2))
Exemple #12
0
 def test_be_within_3_of_0(self):
     expect(2).to(be_within(3).of(0))
Exemple #13
0
 def test_not_less_than_with_lesser_value(self):
     expect(1).not_to(be_lt(0))
Exemple #14
0
 def test_greater_than_or_equal_with_lesser_value(self):
     expect(2).to(be_gte(1))
Exemple #15
0
 def test_not_less_than_with_greater_value(self):
     self.assertRaises(ExpectationNotMetError, expect(1).not_to, be_lt(2))
Exemple #16
0
 def test_less_than_with_lesser_value(self):
     self.assertRaises(ExpectationNotMetError, expect(1).to, be_lt(0))
Exemple #17
0
 def test_less_than_with_greater_value(self):
     expect(1).to(be_lt(2))
Exemple #18
0
 def test_not_less_than_with_greater_value(self):
     self.assertRaises(ExpectationNotMetError, expect(1).not_to, be_lt(2))
Exemple #19
0
 def test_be_within_3_of_0(self):
     expect(2).to(be_within(3).of(0))
Exemple #20
0
 def test_greater_than_or_equal_with_lesser_value(self):
     expect(2).to(be_gte(1))
Exemple #21
0
 def test_expect_string_to_match_pattern(self):
     expect('foobar').to(match(r'^[a-z]{6}$'))
Exemple #22
0
 def test_expect_string_to_be_an_instance_of_str(self):
     expect('foobar').to(be_an_instance_of(str))
Exemple #23
0
 def test_expect_string_to_be_an_instance_of_str(self):
     expect('foobar').to(be_an_instance_of(str))
Exemple #24
0
 def test_expect_string_to_be_truthy(self):
     expect('foo').to(be_truthy())
Exemple #25
0
 def test_expect_string_be_of_type_str(self):
     expect('foobar').to(be_of_type(str))
Exemple #26
0
 def test_expect_pop_from_empty_list_to_raise_IndexError(self):
     expect([].pop).to(raise_error(IndexError))
Exemple #27
0
 def test_expect_member_to_be_in_list(self):
     expect(['foo', 'bar', 'baz']).to(include('foo', 'baz'))
Exemple #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))
Exemple #29
0
 def test_expect_something_not_to_be_in_list(self):
     expect(['foo', 'bar']).not_to(include('baz'))
Exemple #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))
Exemple #31
0
 def test_expect_string_to_be_truthy(self):
     expect('foo').to(be_truthy())
Exemple #32
0
 def test_not_greater_than_with_lesser_value(self):
     expect(0).not_to(be_gt(1))
Exemple #33
0
 def test_expect_empty_string_not_to_be_truthy(self):
     expect('').not_to(be_truthy())
Exemple #34
0
 def test_less_than_with_lesser_value(self):
     self.assertRaises(ExpectationNotMetError, expect(1).to, be_lt(0))
Exemple #35
0
 def test_expect_empty_string_to_be_falsy(self):
     expect('').to(be_falsy())
Exemple #36
0
 def test_not_less_than_with_lesser_value(self):
     expect(1).not_to(be_lt(0))
Exemple #37
0
 def test_expect_string_not_to_be_falsy(self):
     expect('foo').not_to(be_falsy())
Exemple #38
0
 def test_less_than_or_equal_with_greater_value(self):
     expect(1).to(be_lte(2))
Exemple #39
0
 def test_expect_pop_from_empty_list_to_raise_IndexError(self):
     expect([].pop).to(raise_error(IndexError))
Exemple #40
0
 def test_expect_string_to_match_pattern(self):
     expect('foobar').to(match(r'^[a-z]{6}$'))
Exemple #41
0
 def test_expect_pop_from_list_not_to_raise_IndexError(self):
     expect([0].pop).not_to(raise_error(IndexError))
Exemple #42
0
 def test_expect_string_be_of_type_str(self):
     expect('foobar').to(be_of_type(str))
Exemple #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))
Exemple #44
0
 def test_expect_something_not_to_be_in_list(self):
     expect(['foo', 'bar']).not_to(include('baz'))
Exemple #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))
Exemple #46
0
 def test_expect_empty_string_not_to_be_truthy(self):
     expect('').not_to(be_truthy())
Exemple #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))
Exemple #48
0
 def test_expect_string_not_to_be_falsy(self):
     expect('foo').not_to(be_falsy())
Exemple #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))
Exemple #50
0
 def test_expect_pop_from_list_not_to_raise_IndexError(self):
     expect([0].pop).not_to(raise_error(IndexError))
Exemple #51
0
 def test_greater_than_with_greater_value(self):
     expect(2).to(be_gt(1))
Exemple #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'):
Exemple #53
0
 def test_expect_to_be_with_identical_object(self):
     obj = object()
     same_obj = obj
     expect(obj).to(be(same_obj))
Exemple #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))
Exemple #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))
Exemple #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'):
Exemple #57
0
 def test_expect_to_be_with_identical_object(self):
     obj = object()
     same_obj = obj
     expect(obj).to(be(same_obj))