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

Side by Side Diff: PRESUBMIT_test_mocks.py

Issue 933253002: Reland https://codereview.chromium.org/929043002/: Add a presubmit check that warns about declaring… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert chrome/browser/chromeos/login/users/mock_user_manager.cc 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 | « PRESUBMIT_test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 json 5 import json
6 import os 6 import os
7 import re 7 import re
8 import subprocess 8 import subprocess
9 import sys 9 import sys
10 10
(...skipping 11 matching lines...) Expand all
22 self.os_path = os.path 22 self.os_path = os.path
23 self.python_executable = sys.executable 23 self.python_executable = sys.executable
24 self.subprocess = subprocess 24 self.subprocess = subprocess
25 self.files = [] 25 self.files = []
26 self.is_committing = False 26 self.is_committing = False
27 self.change = MockChange([]) 27 self.change = MockChange([])
28 28
29 def AffectedFiles(self, file_filter=None): 29 def AffectedFiles(self, file_filter=None):
30 return self.files 30 return self.files
31 31
32 def AffectedSourceFiles(self, file_filter=None):
33 return self.files
34
32 def PresubmitLocalPath(self): 35 def PresubmitLocalPath(self):
33 return os.path.dirname(__file__) 36 return os.path.dirname(__file__)
34 37
35 def ReadFile(self, filename, mode='rU'): 38 def ReadFile(self, filename, mode='rU'):
39 if hasattr(filename, 'AbsoluteLocalPath'):
40 filename = filename.AbsoluteLocalPath()
36 for file_ in self.files: 41 for file_ in self.files:
37 if file_.LocalPath() == filename: 42 if file_.LocalPath() == filename:
38 return '\n'.join(file_.NewContents()) 43 return '\n'.join(file_.NewContents())
39 # Otherwise, file is not in our mock API. 44 # Otherwise, file is not in our mock API.
40 raise IOError, "No such file or directory: '%s'" % filename 45 raise IOError, "No such file or directory: '%s'" % filename
41 46
42 47
43 class MockOutputApi(object): 48 class MockOutputApi(object):
44 """Mock class for the OutputApi class. 49 """Mock class for the OutputApi class.
45 50
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 def ChangedContents(self): 94 def ChangedContents(self):
90 return self._changed_contents 95 return self._changed_contents
91 96
92 def NewContents(self): 97 def NewContents(self):
93 return self._new_contents 98 return self._new_contents
94 99
95 def LocalPath(self): 100 def LocalPath(self):
96 return self._local_path 101 return self._local_path
97 102
98 103
104 class MockAffectedFile(MockFile):
105 def AbsoluteLocalPath(self):
106 return self._local_path
107
108
99 class MockChange(object): 109 class MockChange(object):
100 """Mock class for Change class. 110 """Mock class for Change class.
101 111
102 This class can be used in presubmit unittests to mock the query of the 112 This class can be used in presubmit unittests to mock the query of the
103 current change. 113 current change.
104 """ 114 """
105 115
106 def __init__(self, changed_files): 116 def __init__(self, changed_files):
107 self._changed_files = changed_files 117 self._changed_files = changed_files
108 118
109 def LocalPaths(self): 119 def LocalPaths(self):
110 return self._changed_files 120 return self._changed_files
OLDNEW
« no previous file with comments | « PRESUBMIT_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698