예제 #1
0
  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)
예제 #2
0
  def test_expectation_be(self):
    a = {}
    e = a

    jazz.expect(a).toBe(e)
    with self.assertRaises(AssertionError):
      jazz.expect(a).notToBe(e)
예제 #3
0
  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)
예제 #4
0
  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)
예제 #5
0
  def test_expectation_contain(self):
    a = ['key']
    e = 'key'

    jazz.expect(a).toContain(e)
    with self.assertRaises(AssertionError):
      jazz.expect(a).notToContain(e)
예제 #6
0
  def test_expectation_equal(self):
    a = 4
    e = 4

    jazz.expect(a).toEqual(e)
    with self.assertRaises(AssertionError):
      jazz.expect(a).notToEqual(e)
예제 #7
0
  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)
예제 #8
0
  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()
예제 #9
0
  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)
예제 #10
0
  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)
예제 #11
0
 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()
예제 #12
0
  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)
예제 #13
0
 def test_matchers_can_be_chained(self):
   (jazz.expect(3)
     .toBe(3)
     .notToBeLessThan(3)
     .andNotToBeGreaterThan(3)
     .toBe(3)
     .andNotToBe(4)
     .notToBe(2)
     .andNotToBe(5))
예제 #14
0
  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()
예제 #15
0
  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)
예제 #16
0
  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()
예제 #17
0
 def it_should_create_different_names(self):
     expect(self.FIRST_NAME).notToEqual(self.LAST_NAME)
예제 #18
0
  def test_expectation_be_none(self):
    a = None

    jazz.expect(a).toBeNone()
    with self.assertRaises(AssertionError):
      jazz.expect(a).notToBeNone()
예제 #19
0
  def test_expectation_be_truthy(self):
    a = 'truthy string is truthy'

    jazz.expect(a).toBeTruthy()
    with self.assertRaises(AssertionError):
      jazz.expect(a).notToBeTruthy()
예제 #20
0
 def it_should_create_a_float(self):
   expect(self.FLOAT).toBeInstanceOf(float)
예제 #21
0
 def it_should_create_repeated_values(self):
     expect(len(self.TWO_WORDS.split())).toEqual(2)
예제 #22
0
 def test_spy_records(self):
   spy = jazz.create_spy('foo')
   spy(123)
   jazz.expect(spy).to_have_been_called_with(123)
예제 #23
0
 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)
예제 #24
0
 def it_should_create_an_address(self):
     addr = self.ADDRESS.split(' ')
     expect(int(addr[0])).toBeGreaterThan(0)
     expect(len(addr[1])).toBeGreaterThan(0)
예제 #25
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)
예제 #26
0
 def it_should_create_an_address(self):
   addr = self.ADDRESS.split(' ')
   expect(int(addr[0])).toBeGreaterThan(0)
   expect(len(addr[1])).toBeGreaterThan(0)
예제 #27
0
 def it_should_create_different_names(self):
   expect(self.FIRST_NAME).notToEqual(self.LAST_NAME)
예제 #28
0
 def it_should_create_a_float(self):
     expect(self.FLOAT).toBeInstanceOf(float)
예제 #29
0
 def test_expectation_been_called_with(self):
   m = mock.Mock()
   m(123, bar=45)
   jazz.expect(m).toHaveBeenCalledWith(123, bar=45)
예제 #30
0
 def it_should_create_repeated_values(self):
   expect(len(self.TWO_WORDS.split())).toEqual(2)
예제 #31
0
 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)
예제 #32
0
  def test_expectation_be_falsy(self):
    a = []

    jazz.expect(a).toBeFalsy()
    with self.assertRaises(AssertionError):
      jazz.expect(a).notToBeFalsy()
예제 #33
0
 def test_expectation_been_called(self):
   m = mock.Mock()
   jazz.expect(m).notToHaveBeenCalled()
   m()
   jazz.expect(m).toHaveBeenCalled()
예제 #34
0
 def it_should_hate_this(self):
   jazz.expect(the_spanish_inquisition())
예제 #35
0
 def test_expectation_have_length(self):
   jazz.expect([1]).toHaveLength(1)
   with self.assertRaises(AssertionError):
     jazz.expect([1, 2]).toHaveLength(3)
예제 #36
0
 def it_should_create_an_int(self):
     expect(self.INT).toBeInstanceOf(int)