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)
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)
def test_chaining_returns(self): surely(self.exp, equals, self.exp.returns(1))
def test_chaining_twice(self): surely(self.exp, equals, self.exp.twice())
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")
def test_parent_mock_sugar(self): surely(self.exp.mock, same_as, dispenser.Parent)
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)
def test_name(self): surely(self.placebo.name, equals, 'Placebo')
def test_expecting_args_length_fails(self): self.exp.with_args(1, 2 , 3, four=4, five=5) surely(self.exp, raises, AssertionError)
def test_returns(self): self.exp.returns(1) surely(self.exp(), equals, 1)
def test_same_as_message(self): surely(lambda: surely(1, same_as, 2), raises, AssertionError, 'Failed: 1 is 2')
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)
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)))
def test_isa(self): surely(1, isa, type(1))
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)
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")
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")
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")
def test_chaining_with_with_args(self): surely(self.exp, equals, self.exp.with_args([]))
def test_identity(self): surely(dispenser.Placebo, same_as, self.placebo)
def test_chaining_called(self): surely(self.exp, equals, self.exp.called(1))
def test_attr(self): self.placebo.attr('something').returns(1) surely(self.placebo.something, equals, 1)
def test_chaining_once(self): surely(self.exp, equals, self.exp.once())
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")
def test_custom_error(self): def barfs(x): assert False, 'Barf!' surely(lambda: surely(1, barfs), raises, AssertionError, 'Barf!')