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

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: 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
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):
tandrii(chromium) 2016/06/13 17:03:27 i'd not touch this one. Provide your testcase, yes
Sergiy Byelozyorov 2016/06/14 06:12:14 Developers are used to inherit from auto_stub.Test
tandrii(chromium) 2016/06/14 10:21:43 it's a trade off for how easy it'd be to roll this
Sergiy Byelozyorov 2016/06/14 19:47:01 Acknowledged.
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()
tandrii(chromium) 2016/06/13 17:03:27 this is bad. It should be explicit as it used to b
Sergiy Byelozyorov 2016/06/14 06:12:14 We do it differently everywhere else. Why should i
tandrii(chromium) 2016/06/14 10:21:43 Oh, yes, I suppose it's Ok. I prefer explicit beca
Sergiy Byelozyorov 2016/06/14 19:47:01 Acknowledged.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698