1 # Copyright 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
6 from telemetry
.testing
import simple_mock
8 _
= simple_mock
.DONT_CARE
10 # pylint: disable=no-member
11 class SimpleMockUnitTest(unittest
.TestCase
):
13 mock
= simple_mock
.MockObject()
14 mock
.ExpectCall('foo')
19 mock
= simple_mock
.MockObject()
20 mock
.ExpectCall('foo').WillReturn(7)
23 self
.assertEquals(ret
, 7)
26 mock
= simple_mock
.MockObject()
27 mock
.ExpectCall('foo').WithArgs(3, 4)
32 mock
= simple_mock
.MockObject()
33 mock
.ExpectCall('foo', 3, 4)
37 def testArgsMismatch(self
):
38 mock
= simple_mock
.MockObject()
39 mock
.ExpectCall('foo').WithArgs(3, 4)
41 self
.assertRaises(Exception,
42 lambda: mock
.foo(4, 4))
45 def testArgsDontCare(self
):
46 mock
= simple_mock
.MockObject()
47 mock
.ExpectCall('foo').WithArgs(_
, 4)
52 mock
= simple_mock
.MockObject()
57 handler_called
.append(True)
58 mock
.ExpectCall('baz', 7).WhenCalled(Handler
)
61 self
.assertTrue(len(handler_called
) > 0)
64 def testSubObject(self
):
65 mock
= simple_mock
.MockObject()
66 mock
.bar
= simple_mock
.MockObject(mock
)
68 mock
.ExpectCall('foo').WithArgs(_
, 4)
69 mock
.bar
.ExpectCall('baz')
74 def testSubObjectMismatch(self
):
75 mock
= simple_mock
.MockObject()
76 mock
.bar
= simple_mock
.MockObject(mock
)
78 mock
.ExpectCall('foo').WithArgs(_
, 4)
79 mock
.bar
.ExpectCall('baz')
83 lambda: mock
.bar
.baz()) # pylint: disable=unnecessary-lambda