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))
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))
def test_greater_than_with_greater_value(self): expect(2).to(be_gt(1))
def test_less_than_with_greater_value(self): expect(1).to(be_lt(2))
def test_not_greater_than_with_lesser_value(self): expect(0).not_to(be_gt(1))
def test_expect_to_be_with_non_identical_object(self): obj = object() other_obj = object() self.assertRaises(ExpectationNotMetError, expect(obj).to, be(other_obj))
def test_expect_member_to_be_in_list(self): expect(['foo', 'bar', 'baz']).to(include('foo', 'baz'))
def test_expect_empty_string_to_be_falsy(self): expect('').to(be_falsy())
def test_less_than_or_equal_with_greater_value(self): expect(1).to(be_lte(2))
def test_be_within_3_of_0(self): expect(2).to(be_within(3).of(0))
def test_not_less_than_with_lesser_value(self): expect(1).not_to(be_lt(0))
def test_greater_than_or_equal_with_lesser_value(self): expect(2).to(be_gte(1))
def test_not_less_than_with_greater_value(self): self.assertRaises(ExpectationNotMetError, expect(1).not_to, be_lt(2))
def test_less_than_with_lesser_value(self): self.assertRaises(ExpectationNotMetError, expect(1).to, be_lt(0))
def test_expect_string_to_match_pattern(self): expect('foobar').to(match(r'^[a-z]{6}$'))
def test_expect_string_to_be_an_instance_of_str(self): expect('foobar').to(be_an_instance_of(str))
def test_expect_string_to_be_truthy(self): expect('foo').to(be_truthy())
def test_expect_string_be_of_type_str(self): expect('foobar').to(be_of_type(str))
def test_expect_pop_from_empty_list_to_raise_IndexError(self): expect([].pop).to(raise_error(IndexError))
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))
def test_expect_something_not_to_be_in_list(self): expect(['foo', 'bar']).not_to(include('baz'))
def test_expect_not_to_be_with_non_identical_object(self): obj = object() other_obj = object() expect(obj).not_to(be(other_obj))
def test_expect_empty_string_not_to_be_truthy(self): expect('').not_to(be_truthy())
def test_expect_string_not_to_be_falsy(self): expect('foo').not_to(be_falsy())
def test_expect_pop_from_list_not_to_raise_IndexError(self): expect([0].pop).not_to(raise_error(IndexError))
from pyspec import description, specification from pyspec.expectations import expect, eq with description(True): with specification('is false'): expect(True).to(eq(False))
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))
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'):
def test_expect_to_be_with_identical_object(self): obj = object() same_obj = obj expect(obj).to(be(same_obj))
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))
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'):