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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing_support/tests/auto_stub_test.py
diff --git a/testing_support/tests/auto_stub_test.py b/testing_support/tests/auto_stub_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..a3d6aef1992b4cef01ae07db6add3e908b8d066b
--- /dev/null
+++ b/testing_support/tests/auto_stub_test.py
@@ -0,0 +1,46 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import sys
+import unittest
+
+from testing_support import auto_stub
+
+
+class MockedObject(auto_stub.SimpleMock):
+ def method1(self, *args, **kwargs):
+ self._register_call(*args, **kwargs)
+
+
+class TestSimpleMock(unittest.TestCase):
+ def test_auto_mock(self):
+ obj = MockedObject(self)
+ obj.method1(1, param=2)
+ obj.check_calls(['method1(1, param=2)'])
+
+def return_one():
+ return 1
+
+def return_two():
+ return 2
+
+class TestAutoStubTestCase(auto_stub.TestCase):
+ def test_mock_method(self):
+ # mock one function
+ self.assertEqual(return_one(), 1)
+ self.mock(sys.modules[__name__], 'return_one', lambda: 'mocked')
+ self.assertEqual(return_one(), 'mocked')
+ auto_stub.TestCase.tearDown(self)
+ self.assertEqual(return_one(), 1)
+
+ # mock two functions
+ self.assertEqual(return_one(), 1)
+ self.assertEqual(return_two(), 2)
+ self.mock(sys.modules[__name__], 'return_one', lambda: 'mocked1')
+ self.mock(sys.modules[__name__], 'return_two', lambda: 'mocked2')
+ self.assertEqual(return_one(), 'mocked1')
+ self.assertEqual(return_two(), 'mocked2')
+ auto_stub.TestCase.tearDown(self)
+ self.assertEqual(return_one(), 1)
+ self.assertEqual(return_two(), 2)
« 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