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

Side by Side Diff: testing_support/auto_stub.py

Issue 2067533002: Check for stray threads from tests and fail if found (Closed) Base URL: https://chromium.googlesource.com/infra/testing/testing_support.git@master
Patch Set: Addressed comments Created 4 years, 6 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 | « README.md ('k') | testing_support/tests/thread_watcher_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
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
8 from testing_support import thread_watcher
8 9
9 10
10 class AutoStubMixIn(object): 11 class AutoStubMixIn(object):
11 """Automatically restores stubbed functions on unit test teardDown. 12 """Automatically restores stubbed functions on unit test teardDown.
12 13
13 It's an extremely lightweight mocking class that doesn't require bookeeping. 14 It's an extremely lightweight mocking class that doesn't require bookeeping.
14 """ 15 """
15 _saved = None 16 _saved = None
16 17
17 def mock(self, obj, member, mock): 18 def mock(self, obj, member, mock):
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 57
57 def _register_call(self, *args, **kwargs): 58 def _register_call(self, *args, **kwargs):
58 """Registers the name of the caller function.""" 59 """Registers the name of the caller function."""
59 caller_name = kwargs.pop('caller_name', None) or inspect.stack()[1][3] 60 caller_name = kwargs.pop('caller_name', None) or inspect.stack()[1][3]
60 str_args = ', '.join(repr(arg) for arg in args) 61 str_args = ', '.join(repr(arg) for arg in args)
61 str_kwargs = ', '.join('%s=%r' % (k, v) for k, v in kwargs.iteritems()) 62 str_kwargs = ', '.join('%s=%r' % (k, v) for k, v in kwargs.iteritems())
62 self.calls.append('%s(%s)' % ( 63 self.calls.append('%s(%s)' % (
63 caller_name, ', '.join(filter(None, [str_args, str_kwargs])))) 64 caller_name, ', '.join(filter(None, [str_args, str_kwargs]))))
64 65
65 66
66 class TestCase(unittest.TestCase, AutoStubMixIn): 67 class TestCase(thread_watcher.TestCase, AutoStubMixIn):
67 """Adds self.mock() and self.has_failed() to a TestCase.""" 68 """Adds self.mock() and self.has_failed() to a TestCase."""
68 def tearDown(self): 69 def tearDown(self):
69 AutoStubMixIn.tearDown(self) 70 AutoStubMixIn.tearDown(self)
70 unittest.TestCase.tearDown(self) 71 super(TestCase, self).tearDown()
OLDNEW
« no previous file with comments | « README.md ('k') | testing_support/tests/thread_watcher_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698