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

Side by Side Diff: tests/super_mox.py

Issue 391075: Revert 32057, 32058, 32059, 32062 because they still have unwanted side-effects. (Closed)
Patch Set: Created 11 years, 1 month 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 | « tests/scm_unittest.py ('k') | tests/trychange_unittest.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 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Simplify unit tests based on pymox.""" 6 """Simplify unit tests based on pymox."""
7 7
8 import __builtin__ 8 import __builtin__
9 import os 9 import os
10 import random 10 import random
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 def compareMembers(self, object, members): 64 def compareMembers(self, object, members):
65 """If you add a member, be sure to add the relevant test!""" 65 """If you add a member, be sure to add the relevant test!"""
66 # Skip over members starting with '_' since they are usually not meant to 66 # Skip over members starting with '_' since they are usually not meant to
67 # be for public use. 67 # be for public use.
68 actual_members = [x for x in sorted(dir(object)) 68 actual_members = [x for x in sorted(dir(object))
69 if not x.startswith('_')] 69 if not x.startswith('_')]
70 expected_members = sorted(members) 70 expected_members = sorted(members)
71 if actual_members != expected_members: 71 if actual_members != expected_members:
72 diff = ([i for i in actual_members if i not in expected_members] + 72 diff = ([i for i in actual_members if i not in expected_members] +
73 [i for i in expected_members if i not in actual_members]) 73 [i for i in expected_members if i not in actual_members])
74 print>>sys.stderr, diff 74 print diff
75 self.assertEqual(actual_members, expected_members) 75 self.assertEqual(actual_members, expected_members)
76 76
77 def UnMock(self, object, name): 77 def UnMock(self, object, name):
78 """Restore an object inside a test.""" 78 """Restore an object inside a test."""
79 for (parent, old_child, child_name) in self.mox.stubs.cache: 79 for (parent, old_child, child_name) in self.mox.stubs.cache:
80 if parent == object and child_name == name: 80 if parent == object and child_name == name:
81 setattr(parent, child_name, old_child) 81 setattr(parent, child_name, old_child)
82 break 82 break
83 83
84 84
(...skipping 14 matching lines...) Expand all
99 self.MockList(subprocess, ('call', 'Popen')) 99 self.MockList(subprocess, ('call', 'Popen'))
100 # Don't mock stderr since it confuses unittests. 100 # Don't mock stderr since it confuses unittests.
101 self.MockList(sys, ('stdin', 'stdout')) 101 self.MockList(sys, ('stdin', 'stdout'))
102 102
103 def MockList(self, parent, items_to_mock): 103 def MockList(self, parent, items_to_mock):
104 for item in items_to_mock: 104 for item in items_to_mock:
105 # Skip over items not present because of OS-specific implementation, 105 # Skip over items not present because of OS-specific implementation,
106 # implemented only in later python version, etc. 106 # implemented only in later python version, etc.
107 if hasattr(parent, item): 107 if hasattr(parent, item):
108 self.mox.StubOutWithMock(parent, item) 108 self.mox.StubOutWithMock(parent, item)
OLDNEW
« no previous file with comments | « tests/scm_unittest.py ('k') | tests/trychange_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698