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

Side by Side Diff: testing_support/auto_stub.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/__init__.py ('k') | testing_support/fake_repos.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import collections 5 import collections
6 import inspect 6 import inspect
7 import unittest 7 import unittest
8 8
9 9
10 class AutoStubMixIn(object): 10 class AutoStubMixIn(object):
(...skipping 16 matching lines...) Expand all
27 for obj, items in self._saved.iteritems(): 27 for obj, items in self._saved.iteritems():
28 for member, previous_value in items.iteritems(): 28 for member, previous_value in items.iteritems():
29 setattr(obj, member, previous_value) 29 setattr(obj, member, previous_value)
30 30
31 31
32 class SimpleMock(object): 32 class SimpleMock(object):
33 """Really simple manual class mock.""" 33 """Really simple manual class mock."""
34 def __init__(self, unit_test): 34 def __init__(self, unit_test):
35 """Do not call __init__ if you want to use the global call list to detect 35 """Do not call __init__ if you want to use the global call list to detect
36 ordering across different instances. 36 ordering across different instances.
37
38 Args:
39 unit_test (unittest.TestCase): instance of a test class.
37 """ 40 """
38 self.calls = [] 41 self.calls = []
39 self.unit_test = unit_test 42 self.unit_test = unit_test
40 self.assertEqual = unit_test.assertEqual 43 self.assertEqual = unit_test.assertEqual
41 44
42 def pop_calls(self): 45 def pop_calls(self):
43 """Returns the list of calls up to date. 46 """Returns the list of calls up to date.
44 47
45 Good to do self.assertEqual(expected, mock.pop_calls()). 48 Good to do self.assertEqual(expected, mock.pop_calls()).
46 """ 49 """
(...skipping 15 matching lines...) Expand all
62 65
63 class TestCase(unittest.TestCase, AutoStubMixIn): 66 class TestCase(unittest.TestCase, AutoStubMixIn):
64 """Adds self.mock() and self.has_failed() to a TestCase.""" 67 """Adds self.mock() and self.has_failed() to a TestCase."""
65 def tearDown(self): 68 def tearDown(self):
66 AutoStubMixIn.tearDown(self) 69 AutoStubMixIn.tearDown(self)
67 unittest.TestCase.tearDown(self) 70 unittest.TestCase.tearDown(self)
68 71
69 def has_failed(self): 72 def has_failed(self):
70 """Returns True if the test has failed.""" 73 """Returns True if the test has failed."""
71 return not self._resultForDoCleanups.wasSuccessful() 74 return not self._resultForDoCleanups.wasSuccessful()
OLDNEW
« no previous file with comments | « testing_support/__init__.py ('k') | testing_support/fake_repos.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698