Exemplo n.º 1
0
 def test_with_statement_style2(self):
     exps = [PlaceboExpectation() for i in range(10)]
     with Dispenser() as m:
         m.Mocked.expectations = exps
         for exp in exps: 
             surely(exp.count, equals, 0)
     for exp in exps: 
         surely(exp.count, equals, 1)
Exemplo n.º 2
0
 def test_with_statement(self):
     exps = [PlaceboExpectation() for i in range(10)]
     dispenser.Mocked.expectations = exps
     with dispenser:
         for exp in exps: 
             surely(exp.count, equals, 0)
     for exp in exps: 
         surely(exp.count, equals, 1)
Exemplo n.º 3
0
 def test_chaining_returns(self):
     surely(self.exp, equals, self.exp.returns(1))
Exemplo n.º 4
0
 def test_chaining_twice(self):
     surely(self.exp, equals, self.exp.twice())
Exemplo n.º 5
0
 def test_unary(self):
     def is_the_truth(x): assert x is True, "%s is not True" % x
     surely(True, is_the_truth)
     surely(lambda: surely(False, is_the_truth), raises, AssertionError, "False is not True")
Exemplo n.º 6
0
 def test_parent_mock_sugar(self):
     surely(self.exp.mock, same_as, dispenser.Parent)
Exemplo n.º 7
0
 def test_verify(self):
     exps = [PlaceboExpectation() for i in range(10)]
     dispenser.Placebo.expectations = exps
     dispenser.Placebo.verify()
     for exp in exps: 
         surely(exp.count, equals, 1)
Exemplo n.º 8
0
 def test_name(self):
     surely(self.placebo.name, equals, 'Placebo')
Exemplo n.º 9
0
 def test_expecting_args_length_fails(self):
     self.exp.with_args(1, 2 , 3, four=4, five=5)
     surely(self.exp, raises, AssertionError)
Exemplo n.º 10
0
 def test_returns(self):
     self.exp.returns(1)
     surely(self.exp(), equals, 1)
Exemplo n.º 11
0
 def test_same_as_message(self):
     surely(lambda: surely(1, same_as, 2), raises,  AssertionError, 'Failed: 1 is 2')
Exemplo n.º 12
0
 def test_surely_operator_is(self):
     is_the_same_as = is_same_as = same_as
     surely(1, same_as, 1)
     surely(1, is_same_as, 1)
     surely(1, is_the_same_as, 1)
Exemplo n.º 13
0
 def test_isa_fails(self):
     surely(lambda: surely("a", isa, type(1)), 
         raises, AssertionError, "Expected %s to be of type %s" % (repr("a"), type(1)))
Exemplo n.º 14
0
 def test_isa(self):
     surely(1, isa, type(1))
Exemplo n.º 15
0
 def test_and_does_with_returns(self):
     should_be_exp = None
     def done(placebo):
         return 23
     self.exp.does(done).and_returns(44)
     surely(self.exp(), equals, 44)
Exemplo n.º 16
0
 def test_verify_all(self):
     dispenser.FailPlacebo.receives('doit').once()
     surely(lambda: dispenser.verify(), raises, AssertionError,
         "<Expectation 'FailPlacebo.doit'> expected to be called 1 times, but was called 0 times")
Exemplo n.º 17
0
 def test_expecting_args_values_fails(self):
     self.exp.with_args(dispenser.One, dispenser.Two)
     surely(lambda: self.exp(dispenser.One, 2), raises, AssertionError,
             "<Expectation 'Parent.test'> at position 1: expected: <Mock 'Two'> received: 2")
Exemplo n.º 18
0
 def test_expecting_kwargs_values_fails(self):
     self.exp.with_args(one=1, two=2)
     surely(lambda: self.exp(one=1, two=3), raises, AssertionError,
             "<Expectation 'Parent.test'> keyword two: expected: 2 received: 3")
Exemplo n.º 19
0
 def test_chaining_with_with_args(self):
     surely(self.exp, equals, self.exp.with_args([]))
Exemplo n.º 20
0
 def test_identity(self):
     surely(dispenser.Placebo, same_as, self.placebo)
Exemplo n.º 21
0
 def test_chaining_called(self):
     surely(self.exp, equals, self.exp.called(1))
Exemplo n.º 22
0
 def test_attr(self):
     self.placebo.attr('something').returns(1)
     surely(self.placebo.something, equals, 1)
Exemplo n.º 23
0
 def test_chaining_once(self):
     surely(self.exp, equals, self.exp.once())
Exemplo n.º 24
0
 def test_called_fails(self):
     self.exp.twice()
     surely(lambda: self.exp.verify(), raises, AssertionError,
         "<Expectation 'Parent.test'> expected to be called 2 times, but was called 0 times")
Exemplo n.º 25
0
 def test_custom_error(self):
     def barfs(x): assert False, 'Barf!'
     surely(lambda: surely(1, barfs), raises, AssertionError, 'Barf!')