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

Side by Side Diff: PRESUBMIT_unittest.py

Issue 20474: Very basic starter presubmit script for Chromium, as requested by maruel.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « PRESUBMIT.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
(Empty)
1 #!/usr/bin/python
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
4 # found in the LICENSE file.
5
6 """Unit tests for top-level Chromium presubmit script.
7 """
8
9
10 import PRESUBMIT
11 import unittest
12
13
14 class MockInputApi(object):
15 def __init__(self):
16 self.affected_files = []
17
18 def AffectedTextFiles(self, include_deletes=True):
19 return self.affected_files
20
21
22 class MockAffectedFile(object):
23 def __init__(self, path):
24 self.path = path
25
26 def LocalPath(self):
27 return self.path
28
29
30 class MockOutputApi(object):
31 class PresubmitError(object):
32 def __init__(self, msg, items):
33 self.msg = msg
34 self.items = items
35
36
37 class PresubmitUnittest(unittest.TestCase):
38 def setUp(self):
39 self.file_contents = ''
40 def MockReadFile(path):
41 self.failIf(path.endswith('notsource'))
42 return self.file_contents
43 PRESUBMIT._ReadFile = MockReadFile
44
45 def tearDown(self):
46 PRESUBMIT._ReadFile = PRESUBMIT.ReadFile
47
48 def testCheckNoCrLfOrTabs(self):
49 api = MockInputApi()
50 api.affected_files = [
51 MockAffectedFile('foo/blat/yoo.notsource'),
52 MockAffectedFile('foo/blat/source.h'),
53 MockAffectedFile('foo/blat/source.mm'),
54 MockAffectedFile('foo/blat/source.py'),
55 ]
56 self.file_contents = 'file with\nerror\nhere\r\nyes there'
57 self.failUnless(len(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi)) == 1)
58 self.failUnless(
59 len(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi)[0].items) == 3)
60
61 self.file_contents = 'file\twith\ttabs'
62 self.failUnless(len(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi)) == 1)
63
64 self.file_contents = 'file\rusing\rCRs'
65 self.failUnless(len(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi)) == 1)
66
67 self.file_contents = 'both\ttabs and\r\nCRLF'
68 self.failUnless(len(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi)) == 2)
69
70 self.file_contents = 'file with\nzero \\t errors \\r\\n'
71 self.failIf(PRESUBMIT.CheckNoCrOrTabs(api, MockOutputApi))
72
73
74 if __name__ == '__main__':
75 unittest.main()
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698