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

Side by Side Diff: PRESUBMIT_test_mocks.py

Issue 719463003: Presubmit checks for user actions intorduced in HTML files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits and clean up Created 6 years 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
(Empty)
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
3 # found in the LICENSE file.
4
5 import json
6 import os
7 import re
8 import subprocess
9 import sys
10
11
12 class MockInputApi(object):
13 def __init__(self):
14 self.json = json
15 self.re = re
16 self.os_path = os.path
17 self.python_executable = sys.executable
18 self.subprocess = subprocess
19 self.files = []
20 self.is_committing = False
21
22 def AffectedFiles(self, file_filter=None):
23 return self.files
24
25 def PresubmitLocalPath(self):
26 return os.path.dirname(__file__)
27
28 def ReadFile(self, filename, mode='rU'):
29 for file_ in self.files:
30 if file_.LocalPath() == filename:
31 return '\n'.join(file_.NewContents())
32 # Otherwise, file is not in our mock API.
33 raise IOError, "No such file or directory: '%s'" % filename
34
35
36 class MockOutputApi(object):
37 class PresubmitResult(object):
38 def __init__(self, message, items=None, long_text=''):
39 self.message = message
40 self.items = items
41 self.long_text = long_text
42
43 class PresubmitError(PresubmitResult):
44 def __init__(self, message, items, long_text=''):
45 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text)
46 self.type = 'error'
47
48 class PresubmitPromptWarning(PresubmitResult):
49 def __init__(self, message, items, long_text=''):
50 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text)
51 self.type = 'warning'
52
53 class PresubmitNotifyResult(PresubmitResult):
54 def __init__(self, message, items, long_text=''):
55 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text)
56 self.type = 'notify'
57
58 class PresubmitPromptOrNotify(PresubmitResult):
59 def __init__(self, message, items, long_text=''):
60 MockOutputApi.PresubmitResult.__init__(self, message, items, long_text)
61 self.type = 'promptOrNotify'
62
63
64 class MockFile(object):
65 def __init__(self, local_path, new_contents):
66 self._local_path = local_path
67 self._new_contents = new_contents
68 self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)]
69
70 def ChangedContents(self):
71 return self._changed_contents
72
73 def NewContents(self):
74 return self._new_contents
75
76 def LocalPath(self):
77 return self._local_path
78
79
80 class MockChange(object):
81 def __init__(self, changed_files):
82 self._changed_files = changed_files
83
84 def LocalPaths(self):
85 return self._changed_files
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698