2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
8 from mock_function
import MockFunction
11 class MockFunctionUnittest(unittest
.TestCase
):
12 def testMockFunction(self
):
14 def calc(a
, b
, mult
=1):
17 self
.assertTrue(*calc
.CheckAndReset(0))
19 (False, 'calc: expected 1 call(s), got 0'), calc
.CheckAndReset(1))
21 self
.assertEqual(20, calc(2, 3, mult
=4))
22 self
.assertTrue(*calc
.CheckAndReset(1))
23 self
.assertTrue(*calc
.CheckAndReset(0))
25 self
.assertEqual(20, calc(2, 3, mult
=4))
27 (False, 'calc: expected 0 call(s), got 1'), calc
.CheckAndReset(0))
29 self
.assertEqual(3, calc(1, 2))
30 self
.assertEqual(0, calc(3, 4, mult
=0))
31 self
.assertTrue(*calc
.CheckAndReset(2))
32 self
.assertTrue(*calc
.CheckAndReset(0))
34 self
.assertEqual(3, calc(1, 2))
35 self
.assertEqual(0, calc(3, 4, mult
=0))
37 (False, 'calc: expected 3 call(s), got 2'), calc
.CheckAndReset(3))
40 if __name__
== '__main__':