Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: testing_support/tests/auto_stub_test.py

Issue 939523004: Copied files from depot_tools. (Closed) Base URL: https://chromium.googlesource.com/infra/testing/testing_support.git@master
Patch Set: Added some tests Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « testing_support/tests/__init__.py ('k') | testing_support/tests/trial_dir_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2015 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.
4
5 import sys
6 import unittest
7
8 from testing_support import auto_stub
9
10
11 class MockedObject(auto_stub.SimpleMock):
12 def method1(self, *args, **kwargs):
13 self._register_call(*args, **kwargs)
14
15
16 class TestSimpleMock(unittest.TestCase):
17 def test_auto_mock(self):
18 obj = MockedObject(self)
19 obj.method1(1, param=2)
20 obj.check_calls(['method1(1, param=2)'])
21
22 def return_one():
23 return 1
24
25 def return_two():
26 return 2
27
28 class TestAutoStubTestCase(auto_stub.TestCase):
29 def test_mock_method(self):
30 # mock one function
31 self.assertEqual(return_one(), 1)
32 self.mock(sys.modules[__name__], 'return_one', lambda: 'mocked')
33 self.assertEqual(return_one(), 'mocked')
34 auto_stub.TestCase.tearDown(self)
35 self.assertEqual(return_one(), 1)
36
37 # mock two functions
38 self.assertEqual(return_one(), 1)
39 self.assertEqual(return_two(), 2)
40 self.mock(sys.modules[__name__], 'return_one', lambda: 'mocked1')
41 self.mock(sys.modules[__name__], 'return_two', lambda: 'mocked2')
42 self.assertEqual(return_one(), 'mocked1')
43 self.assertEqual(return_two(), 'mocked2')
44 auto_stub.TestCase.tearDown(self)
45 self.assertEqual(return_one(), 1)
46 self.assertEqual(return_two(), 2)
OLDNEW
« no previous file with comments | « testing_support/tests/__init__.py ('k') | testing_support/tests/trial_dir_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698