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

Unified Diff: testing_support/auto_stub.py

Issue 238233002: Reduce auto_stub.py by removing python 2.6 support code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Remove unneeded pylint disabling Created 6 years, 8 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing_support/auto_stub.py
diff --git a/testing_support/auto_stub.py b/testing_support/auto_stub.py
index 8ad4bbe74433a768011ea8fe595f2a5cc4f370c0..c5a3495c6fc7e6335fb24cd139f9359c56a7e78c 100644
--- a/testing_support/auto_stub.py
+++ b/testing_support/auto_stub.py
@@ -2,36 +2,13 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+__version__ = '1.0'
+
+import collections
import inspect
import unittest
-class OrderedDict(object):
- """Incomplete and inefficient implementation of collections.OrderedDict."""
- def __init__(self):
- self._keys = []
-
- def setdefault(self, key, value):
- try:
- self._getindex(key)
- except KeyError:
- self._keys.append((key, value))
- return self[key]
-
- def _getindex(self, key):
- for i, v in enumerate(self._keys):
- if v[0] == key:
- return i
- raise KeyError(key)
-
- def __getitem__(self, key):
- return self._keys[self._getindex(key)][1]
-
- def iteritems(self):
- for i in self._keys:
- yield i
-
-
class AutoStubMixIn(object):
"""Automatically restores stubbed functions on unit test teardDown.
@@ -40,9 +17,9 @@ class AutoStubMixIn(object):
_saved = None
def mock(self, obj, member, mock):
- self._saved = self._saved or OrderedDict()
+ self._saved = self._saved or collections.OrderedDict()
old_value = self._saved.setdefault(
- obj, OrderedDict()).setdefault(member, getattr(obj, member))
+ obj, collections.OrderedDict()).setdefault(member, getattr(obj, member))
setattr(obj, member, mock)
return old_value
@@ -86,43 +63,11 @@ class SimpleMock(object):
class TestCase(unittest.TestCase, AutoStubMixIn):
- """Adds python 2.7 functionality."""
-
+ """Adds self.mock() and self.has_failed() to a TestCase."""
def tearDown(self):
AutoStubMixIn.tearDown(self)
unittest.TestCase.tearDown(self)
def has_failed(self):
"""Returns True if the test has failed."""
- if hasattr(self, '_exc_info'):
- # Only present in python <= 2.6
- # pylint: disable=E1101
- return bool(self._exc_info()[0])
-
- # Only present in python >= 2.7
- # pylint: disable=E1101
return not self._resultForDoCleanups.wasSuccessful()
-
- def assertIs(self, expr1, expr2, msg=None):
- if hasattr(super(TestCase, self), 'assertIs'):
- return super(TestCase, self).assertIs(expr1, expr2, msg)
- if expr1 is not expr2:
- self.fail(msg or '%r is not %r' % (expr1, expr2))
-
- def assertIsNot(self, expr1, expr2, msg=None):
- if hasattr(super(TestCase, self), 'assertIsNot'):
- return super(TestCase, self).assertIsNot(expr1, expr2, msg)
- if expr1 is expr2:
- self.fail(msg or 'unexpectedly identical: %r' % expr1)
-
- def assertIn(self, expr1, expr2, msg=None):
- if hasattr(super(TestCase, self), 'assertIn'):
- return super(TestCase, self).assertIn(expr1, expr2, msg)
- if expr1 not in expr2:
- self.fail(msg or '%r not in %r' % (expr1, expr2))
-
- def assertLess(self, a, b, msg=None):
- if hasattr(super(TestCase, self), 'assertLess'):
- return super(TestCase, self).assertLess(a, b, msg)
- if not a < b:
- self.fail(msg or '%r not less than %r' % (a, b))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698