Пример #1
0
    def test_expects_bound_method_returns(self):
        obj = SampleBase()
        expect(obj.bound_method).args(1, 2).returns(12)
        assert_equals(12, obj.bound_method(1, 2))

        expect(obj.bound_method).args(1, 4).returns(1100)
        assert_equals(1100, obj.bound_method(1, 4))
Пример #2
0
 def test_expects_bound_method_at_least_as_last_expectation(self):
   obj = SampleBase()
   expect(obj.bound_method).args(1, 2).returns(12).at_least(3)
   assert_equals(12, obj.bound_method(1, 2))
   assert_equals(12, obj.bound_method(1, 2))
   assert_equals(12, obj.bound_method(1, 2))
   assert_equals(12, obj.bound_method(1, 2))
Пример #3
0
  def test_expect_bound_method_with_allof_comparator(self):
    obj = SampleBase()
    expect(obj.bound_method).args( all_of(length(5),'hello') )
    obj.bound_method( 'hello' )

    expect(obj.bound_method).args( all_of(length(3),'hello') ).at_least(0)
    assert_raises(UnexpectedCall, obj.bound_method, 'hello' )
Пример #4
0
  def test_expects_bound_method_returns(self):
    obj = SampleBase()
    expect(obj.bound_method).args(1, 2).returns(12)
    assert_equals(12, obj.bound_method(1, 2))

    expect(obj.bound_method).args(1, 4).returns(1100)
    assert_equals(1100, obj.bound_method(1, 4))
Пример #5
0
    def test_expect_bound_method_with_allof_comparator(self):
        obj = SampleBase()
        expect(obj.bound_method).args(all_of(length(5), 'hello'))
        obj.bound_method('hello')

        expect(obj.bound_method).args(all_of(length(3), 'hello')).at_least(0)
        assert_raises(UnexpectedCall, obj.bound_method, 'hello')
Пример #6
0
 def test_expects_bound_method_at_most(self):
   obj = SampleBase()
   expect(obj.bound_method).args(1, 2).returns(12).at_most(3)
   assert_equals(12, obj.bound_method(1, 2))
   assert_equals(12, obj.bound_method(1, 2))
   obj.bound_method(1, 2)
   assert_raises(UnexpectedCall, obj.bound_method, 1, 2)
Пример #7
0
 def test_expects_bound_method_at_least_as_last_expectation(self):
     obj = SampleBase()
     expect(obj.bound_method).args(1, 2).returns(12).at_least(3)
     assert_equals(12, obj.bound_method(1, 2))
     assert_equals(12, obj.bound_method(1, 2))
     assert_equals(12, obj.bound_method(1, 2))
     assert_equals(12, obj.bound_method(1, 2))
Пример #8
0
 def test_expects_bound_method_at_most(self):
     obj = SampleBase()
     expect(obj.bound_method).args(1, 2).returns(12).at_most(3)
     assert_equals(12, obj.bound_method(1, 2))
     assert_equals(12, obj.bound_method(1, 2))
     obj.bound_method(1, 2)
     assert_raises(UnexpectedCall, obj.bound_method, 1, 2)
Пример #9
0
 def test_expects_any_order_without_count_modifiers(self):
   obj = SampleBase()
   expect(obj.bound_method).args(3).returns(4)
   expect(obj.bound_method).args(1).returns(2).any_order()
   expect(obj.bound_method).args(3).returns(4)
   assert_equals(4, obj.bound_method(3) )
   assert_equals(4, obj.bound_method(3) )
   assert_equals(2, obj.bound_method(1) )
Пример #10
0
 def test_expects_any_order_without_count_modifiers(self):
     obj = SampleBase()
     expect(obj.bound_method).args(3).returns(4)
     expect(obj.bound_method).args(1).returns(2).any_order()
     expect(obj.bound_method).args(3).returns(4)
     assert_equals(4, obj.bound_method(3))
     assert_equals(4, obj.bound_method(3))
     assert_equals(2, obj.bound_method(1))
Пример #11
0
    def test_expects_bound_method_can_be_used_for_iterative_testing(self):
        obj = SampleBase()
        expect(obj.bound_method).args(1, 2).returns(12)
        assert_equals(12, obj.bound_method(1, 2))
        assert_raises(UnexpectedCall, obj.bound_method)

        expect(obj.bound_method).args(1, 4).returns(1100)
        assert_equals(1100, obj.bound_method(1, 4))
Пример #12
0
  def test_expects_bound_method_can_be_used_for_iterative_testing(self):
    obj = SampleBase()
    expect(obj.bound_method).args(1, 2).returns(12)
    assert_equals(12, obj.bound_method(1, 2))
    assert_raises(UnexpectedCall, obj.bound_method)

    expect(obj.bound_method).args(1, 4).returns(1100)
    assert_equals(1100, obj.bound_method(1, 4))
Пример #13
0
    def test_expect_unbound_method_acts_as_any_instance(self):
        expect(SampleBase, 'bound_method').args('hello').returns('world')
        expect(SampleBase, 'bound_method').args('hello').returns('mars')

        obj1 = SampleBase()
        obj2 = SampleBase()
        assert_equals('world', obj2.bound_method('hello'))
        assert_equals('mars', obj1.bound_method('hello'))
        assert_raises(UnexpectedCall, obj2.bound_method)
Пример #14
0
  def test_expect_unbound_method_acts_as_any_instance(self):
    expect( SampleBase.bound_method ).args('hello').returns('world')
    expect( SampleBase.bound_method ).args('hello').returns('mars')

    obj1 = SampleBase()
    obj2 = SampleBase()
    assert_equals( 'world', obj2.bound_method('hello') )
    assert_equals( 'mars', obj1.bound_method('hello') )
    assert_raises(UnexpectedCall, obj2.bound_method)
Пример #15
0
  def test_expects_bound_method_at_least_with_other_expectation_and_anyorder(self):
    obj = SampleBase()
    expect(obj.bound_method).args(1, 2).returns(12).at_least(2).any_order()
    assert_equals(12, obj.bound_method(1, 2))
    assert_equals(12, obj.bound_method(1, 2))

    expect(obj.bound_method).args(1, 3).returns(100)
    assert_equals(100, obj.bound_method(1, 3))
    
    assert_equals(12, obj.bound_method(1, 2))
Пример #16
0
 def tests_expects_bound_method_any_order_with_mins(self):
   obj = SampleBase()
   expect(obj.bound_method).args(1).returns(2).any_order().at_least_once()
   expect(obj.bound_method).args(3).returns(4).any_order().at_least_once()
   assert_equals(4, obj.bound_method(3) )
   assert_equals(2, obj.bound_method(1) )
   assert_equals(4, obj.bound_method(3) )
   assert_equals(2, obj.bound_method(1) )
   assert_equals(2, obj.bound_method(1) )
   assert_equals(4, obj.bound_method(3) )
   assert_equals(2, obj.bound_method(1) )
Пример #17
0
    def test_expects_bound_method_at_least_with_other_expectation_and_anyorder(
            self):
        obj = SampleBase()
        expect(obj.bound_method).args(1, 2).returns(12).at_least(2).any_order()
        assert_equals(12, obj.bound_method(1, 2))
        assert_equals(12, obj.bound_method(1, 2))

        expect(obj.bound_method).args(1, 3).returns(100)
        assert_equals(100, obj.bound_method(1, 3))

        assert_equals(12, obj.bound_method(1, 2))
Пример #18
0
 def tests_expects_bound_method_any_order_with_mins(self):
     obj = SampleBase()
     expect(obj.bound_method).args(1).returns(2).any_order().at_least_once()
     expect(obj.bound_method).args(3).returns(4).any_order().at_least_once()
     assert_equals(4, obj.bound_method(3))
     assert_equals(2, obj.bound_method(1))
     assert_equals(4, obj.bound_method(3))
     assert_equals(2, obj.bound_method(1))
     assert_equals(2, obj.bound_method(1))
     assert_equals(4, obj.bound_method(3))
     assert_equals(2, obj.bound_method(1))
Пример #19
0
 def tests_expects_bound_method_any_order_with_fixed_maxes(self):
   obj = SampleBase()
   expect(obj.bound_method).args(1).returns(2).any_order()
   expect(obj.bound_method).args(3).returns(4).any_order()
   assert_equals(4, obj.bound_method(3) )
   assert_equals(2, obj.bound_method(1) )
   assert_raises(UnexpectedCall, obj.bound_method, 1)
Пример #20
0
 def tests_expects_bound_method_any_order_with_fixed_maxes(self):
     obj = SampleBase()
     expect(obj.bound_method).args(1).returns(2).any_order()
     expect(obj.bound_method).args(3).returns(4).any_order()
     assert_equals(4, obj.bound_method(3))
     assert_equals(2, obj.bound_method(1))
     assert_raises(UnexpectedCall, obj.bound_method, 1)
Пример #21
0
 def test_expect_bound_method_with_anyof_comparator(self):
     obj = SampleBase()
     expect(obj.bound_method).times(4).args(
         any_of(int, 3.14, 'hello', is_a(list)))
     obj.bound_method(42)
     obj.bound_method(3.14)
     obj.bound_method('hello')
     obj.bound_method([1, 2, 3])
     assert_raises(UnexpectedCall, obj.bound_method, '42')
Пример #22
0
 def test_expect_bound_method_with_anyof_comparator(self):
   obj = SampleBase()
   expect(obj.bound_method).times(4).args(
     any_of(int, 3.14, 'hello', is_a(list)))
   obj.bound_method(42)
   obj.bound_method(3.14)
   obj.bound_method('hello')
   obj.bound_method([1, 2, 3])
   assert_raises(UnexpectedCall, obj.bound_method, '42')
Пример #23
0
 def test_regex_comparator(self):
   obj = SampleBase()
   expect(obj.bound_method).args(matches("name$")).returns(100)
   assert_equals(obj.bound_method('first_name'), 100)
Пример #24
0
 def test_is_comparator(self):
     obj = SampleBase()
     expect(obj.bound_method).args(is_arg(obj)).returns(100)
     assert_equals(obj.bound_method(obj), 100)
Пример #25
0
 def test_almost_equals_comparator(self):
     obj = SampleBase()
     expect(obj.bound_method).args(almost_equals(10.1234, 2)).returns(100)
     assert_equals(obj.bound_method(10.12), 100)
Пример #26
0
 def test_in_comparator(self):
     obj = SampleBase()
     expect(obj.bound_method).args(contains('name')).returns(100).at_most(3)
     assert_equals(obj.bound_method(['name', 'age']), 100)
     assert_equals(obj.bound_method({'name': 'vitaly'}), 100)
     assert_equals(obj.bound_method('lasfs-name-asfsad'), 100)
Пример #27
0
 def test_function_comparator(self):
     obj = SampleBase()
     expect(obj.bound_method).args(func(lambda arg: arg > 10)).returns(100)
     assert_equals(obj.bound_method(100), 100)
Пример #28
0
 def test_almost_equals_comparator(self):
   obj = SampleBase()
   expect(obj.bound_method).args(almost_equals(10.1234, 2)).returns(100)
   assert_equals(obj.bound_method(10.12), 100)
Пример #29
0
 def test_expect_bound_method_with_equals_comparator(self):
   obj = SampleBase()
   expect(obj.bound_method).args( equals(42) )
   obj.bound_method( 42 )
   assert_raises(UnexpectedCall, obj.bound_method, 32 )
Пример #30
0
 def test_ignore_arg(self):
   obj = SampleBase()
   expect(obj.bound_method).args(ignore_arg()).returns(100)
   assert_equals(obj.bound_method('first_name'), 100)
Пример #31
0
 def test_expect_bound_method_with_notof_comparator_using_types(self):
     obj = SampleBase()
     expect(obj.bound_method).args(not_of(float, int))
     obj.bound_method('hello')
Пример #32
0
 def test_function_comparator(self):
   obj = SampleBase()
   expect(obj.bound_method).args(func(lambda arg: arg > 10)).returns(100)
   assert_equals(obj.bound_method(100), 100)
Пример #33
0
 def test_expect_bound_method_with_is_a_comparator(self):
     obj = SampleBase()
     expect(obj.bound_method).args(is_a(int))
     obj.bound_method(42)
     assert_raises(UnexpectedCall, obj.bound_method, '42')
Пример #34
0
 def test_expect_bound_method_with_equals_comparator(self):
     obj = SampleBase()
     expect(obj.bound_method).args(equals(42))
     obj.bound_method(42)
     assert_raises(UnexpectedCall, obj.bound_method, 32)
Пример #35
0
 def test_in_comparator(self):
   obj = SampleBase()
   expect(obj.bound_method).args(contains('name')).returns(100).at_most(3)
   assert_equals(obj.bound_method(['name', 'age']), 100)
   assert_equals(obj.bound_method({'name' : 'vitaly'}), 100)
   assert_equals(obj.bound_method('lasfs-name-asfsad'), 100)
Пример #36
0
 def test_expect_bound_method_with_notof_comparator_using_types(self):
   obj = SampleBase()
   expect(obj.bound_method).args( not_of(float,int) )
   obj.bound_method( 'hello' )
Пример #37
0
 def test_expect_bound_method_with_is_a_comparator(self):
   obj = SampleBase()
   expect(obj.bound_method).args( is_a(int) )
   obj.bound_method( 42 )
   assert_raises(UnexpectedCall, obj.bound_method, '42' )
Пример #38
0
 def test_regex_comparator(self):
     obj = SampleBase()
     expect(obj.bound_method).args(matches("name$")).returns(100)
     assert_equals(obj.bound_method('first_name'), 100)
Пример #39
0
 def test_ignore_arg(self):
     obj = SampleBase()
     expect(obj.bound_method).args(ignore_arg()).returns(100)
     assert_equals(obj.bound_method('first_name'), 100)
Пример #40
0
 def test_is_comparator(self):
   obj = SampleBase()
   expect(obj.bound_method).args(is_arg(obj)).returns(100)
   assert_equals(obj.bound_method(obj), 100)