def test_expectation_be_greater_than(self): a = 3 e = 2 jazz.expect(a).toBeGreaterThan(e) with self.assertRaises(AssertionError): jazz.expect(a).notToBeGreaterThan(e)
def test_expectation_be(self): a = {} e = a jazz.expect(a).toBe(e) with self.assertRaises(AssertionError): jazz.expect(a).notToBe(e)
def test_expectation_be_less_than(self): a = 2 e = 3 jazz.expect(a).toBeLessThan(e) with self.assertRaises(AssertionError): jazz.expect(a).notToBeLessThan(e)
def test_expectation_be_instance_of(self): a = 3 e = int jazz.expect(a).toBeInstanceOf(e) with self.assertRaises(AssertionError): jazz.expect(a).notToBeInstanceOf(e)
def test_expectation_contain(self): a = ['key'] e = 'key' jazz.expect(a).toContain(e) with self.assertRaises(AssertionError): jazz.expect(a).notToContain(e)
def test_expectation_equal(self): a = 4 e = 4 jazz.expect(a).toEqual(e) with self.assertRaises(AssertionError): jazz.expect(a).notToEqual(e)
def test_expectation_match(self): a = 'some string here matches' e = r'.*matches' jazz.expect(a).toMatch(e) with self.assertRaises(AssertionError): jazz.expect(a).notToMatch(e)
def test_add_matcher(self): def BeFoo(a): return True def be_bar(a): return True jazz.add_matcher(BeFoo) jazz.add_matcher(be_bar) jazz.expect(jazz).toBeFoo() jazz.expect(jazz).toBeBar()
def test_custom_matcher(self): def BeOneMoreThan(a, e): return e + 1 == a jazz.add_matcher(BeOneMoreThan) a = 4 e = 3 jazz.expect(a).toBeOneMoreThan(e) with self.assertRaises(AssertionError): jazz.expect(a).notToBeOneMoreThan(e)
def test_extra_args(self): def BeXMoreThan(a, e, x): return e + x == a jazz.add_matcher(BeXMoreThan) a = 5 e = 3 x = 5 - 3 jazz.expect(a).toBeXMoreThan(e, x) with self.assertRaises(AssertionError): jazz.expect(a).notToBeXMoreThan(e, x)
def test_expectation_pep8(self): jazz.expect(True).toBeTruthy() jazz.expect(True).to_be_truthy() with self.assertRaises(AssertionError): jazz.expect(True).notToBeTruthy() with self.assertRaises(AssertionError): jazz.expect(True).not_to_be_truthy()
def test_stringification(self): string = str(jazz.expect(the_spanish_inquisition())) self.assertIn('expect(42)', string) self.assertRegexpMatches(string, r'jazz_test.py:\d+') self.assertIn( 'test_stringification:string = ' + 'str(jazz.expect(the_spanish_inquisition()))', string)
def test_matchers_can_be_chained(self): (jazz.expect(3) .toBe(3) .notToBeLessThan(3) .andNotToBeGreaterThan(3) .toBe(3) .andNotToBe(4) .notToBe(2) .andNotToBe(5))
def test_expectation_raise(self): def a(): raise ValueError() e = ValueError jazz.expect(a).toRaise(e) with self.assertRaises(AssertionError): jazz.expect(a).notToRaise(e) def a(): raise jazz.expect(a).toRaise() with self.assertRaises(AssertionError): jazz.expect(a).notToRaise()
def test_expectation_be_close_to(self): import math a = math.pi e = 3.1415 jazz.expect(a).toBeCloseTo(e) with self.assertRaises(AssertionError): jazz.expect(a).notToBeCloseTo(e) with self.assertRaises(AssertionError): jazz.expect(a).toBeCloseTo(e, 8)
def test_add_matchers(self): def BeFoo(a): return True def be_bar(a): return True matchers = {'be baz': lambda x: True} jazz.add_matchers(matchers) jazz.add_matchers([BeFoo, be_bar]) jazz.expect(jazz).toBeFoo() jazz.expect(jazz).toBeBar() jazz.expect(jazz).toBeBaz()
def it_should_create_different_names(self): expect(self.FIRST_NAME).notToEqual(self.LAST_NAME)
def test_expectation_be_none(self): a = None jazz.expect(a).toBeNone() with self.assertRaises(AssertionError): jazz.expect(a).notToBeNone()
def test_expectation_be_truthy(self): a = 'truthy string is truthy' jazz.expect(a).toBeTruthy() with self.assertRaises(AssertionError): jazz.expect(a).notToBeTruthy()
def it_should_create_a_float(self): expect(self.FLOAT).toBeInstanceOf(float)
def it_should_create_repeated_values(self): expect(len(self.TWO_WORDS.split())).toEqual(2)
def test_spy_records(self): spy = jazz.create_spy('foo') spy(123) jazz.expect(spy).to_have_been_called_with(123)
def it_should_create_a_username(self): expect(self.USERNAME).toBeInstanceOf(str) expect(self.USERNAME).notToContain(' ') expect(len(self.USERNAME)).toBeGreaterThan(5) expect(len(self.USERNAME)).toBeLessThan(9)
def it_should_create_an_address(self): addr = self.ADDRESS.split(' ') expect(int(addr[0])).toBeGreaterThan(0) expect(len(addr[1])).toBeGreaterThan(0)
def test_spy_obj_records(self): spy = jazz.create_spy_obj('foo', ['baz', 'cat']) spy.baz(456) jazz.expect(spy.baz).to_have_been_called_with(456)
def test_expectation_been_called_with(self): m = mock.Mock() m(123, bar=45) jazz.expect(m).toHaveBeenCalledWith(123, bar=45)
def test_expectation_be_falsy(self): a = [] jazz.expect(a).toBeFalsy() with self.assertRaises(AssertionError): jazz.expect(a).notToBeFalsy()
def test_expectation_been_called(self): m = mock.Mock() jazz.expect(m).notToHaveBeenCalled() m() jazz.expect(m).toHaveBeenCalled()
def it_should_hate_this(self): jazz.expect(the_spanish_inquisition())
def test_expectation_have_length(self): jazz.expect([1]).toHaveLength(1) with self.assertRaises(AssertionError): jazz.expect([1, 2]).toHaveLength(3)
def it_should_create_an_int(self): expect(self.INT).toBeInstanceOf(int)