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))
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'):
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(object): subject = object() with description('.foobar'): with specification('is not a thing'): expect(subject.foobar).to(eq(None))
def test_expect_equal_with_inequal_value(self): self.assertRaises(ExpectationNotMetError, expect(1).to, eq(2))
def test_expect_not_equal_with_inequal_value(self): expect(1).not_to(eq(2))
def test_expect_equal_with_equal_value(self): expect(1).to(eq(1))
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_not_equal_with_inequal_value(self): expect(1).not_to(eq(2))
def test_expect_equal_with_inequal_value(self): self.assertRaises(ExpectationNotMetError, expect(1).to, eq(2))
def test_expect_equal_with_equal_value(self): expect(1).to(eq(1))