Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" | 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" |
| 7 | 7 |
| 8 # pylint is too confused. | 8 # pylint is too confused. |
| 9 # pylint: disable=E1101,E1103,R0201,W0212,W0403 | 9 # pylint: disable=E1101,E1103,R0201,W0212,W0403 |
| 10 | 10 |
| (...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1212 presubmit.os.path.isdir(path).AndReturn(False) | 1212 presubmit.os.path.isdir(path).AndReturn(False) |
| 1213 presubmit.gclient_utils.FileRead(path, 'rU').AndReturn('whatever\ncookie') | 1213 presubmit.gclient_utils.FileRead(path, 'rU').AndReturn('whatever\ncookie') |
| 1214 presubmit.scm.SVN.CaptureInfo(path).AndReturn( | 1214 presubmit.scm.SVN.CaptureInfo(path).AndReturn( |
| 1215 {'URL': 'svn:/foo/foo/blat.cc'}) | 1215 {'URL': 'svn:/foo/foo/blat.cc'}) |
| 1216 self.mox.ReplayAll() | 1216 self.mox.ReplayAll() |
| 1217 af = presubmit.SvnAffectedFile('foo/blat.cc', 'M') | 1217 af = presubmit.SvnAffectedFile('foo/blat.cc', 'M') |
| 1218 self.failUnless(af.ServerPath() == 'svn:/foo/foo/blat.cc') | 1218 self.failUnless(af.ServerPath() == 'svn:/foo/foo/blat.cc') |
| 1219 self.failUnless(af.LocalPath() == presubmit.normpath('foo/blat.cc')) | 1219 self.failUnless(af.LocalPath() == presubmit.normpath('foo/blat.cc')) |
| 1220 self.failUnless(af.Action() == 'M') | 1220 self.failUnless(af.Action() == 'M') |
| 1221 self.assertEquals(af.NewContents(), ['whatever', 'cookie']) | 1221 self.assertEquals(af.NewContents(), ['whatever', 'cookie']) |
| 1222 | |
| 1223 def testAffectedFileNotExists(self): | |
| 1224 presubmit.os.path.exists('notfound.cc').AndReturn(False) | |
| 1225 presubmit.gclient_utils.FileRead('notfound.cc', 'rU').AndRaise(IOError) | |
| 1226 self.mox.ReplayAll() | |
| 1222 af = presubmit.AffectedFile('notfound.cc', 'A') | 1227 af = presubmit.AffectedFile('notfound.cc', 'A') |
| 1223 self.failUnless(af.ServerPath() == '') | 1228 self.failUnless(af.ServerPath() == '') |
| 1229 self.failUnless(af.NewContents() == []) | |
|
M-A Ruel
2011/04/27 14:07:43
nit: I prefer:
self.assertEquals('', af.ServerPath
ncarter (slow)
2011/04/27 20:55:13
Done.
| |
| 1224 | 1230 |
| 1225 def testProperty(self): | 1231 def testProperty(self): |
| 1226 presubmit.scm.SVN.GetFileProperty('foo.cc', 'svn:secret-property' | 1232 presubmit.scm.SVN.GetFileProperty('foo.cc', 'svn:secret-property' |
| 1227 ).AndReturn('secret-property-value') | 1233 ).AndReturn('secret-property-value') |
| 1228 self.mox.ReplayAll() | 1234 self.mox.ReplayAll() |
| 1229 affected_file = presubmit.SvnAffectedFile('foo.cc', 'A') | 1235 affected_file = presubmit.SvnAffectedFile('foo.cc', 'A') |
| 1230 # Verify cache coherency. | 1236 # Verify cache coherency. |
| 1231 self.failUnless(affected_file.Property('svn:secret-property') == | 1237 self.failUnless(affected_file.Property('svn:secret-property') == |
| 1232 'secret-property-value') | 1238 'secret-property-value') |
| 1233 self.failUnless(affected_file.Property('svn:secret-property') == | 1239 self.failUnless(affected_file.Property('svn:secret-property') == |
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2138 whitelist=['^a$', '^b$'], | 2144 whitelist=['^a$', '^b$'], |
| 2139 blacklist=['a']) | 2145 blacklist=['a']) |
| 2140 self.assertEqual(results, []) | 2146 self.assertEqual(results, []) |
| 2141 self.checkstdout( | 2147 self.checkstdout( |
| 2142 'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) | 2148 'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) |
| 2143 | 2149 |
| 2144 | 2150 |
| 2145 if __name__ == '__main__': | 2151 if __name__ == '__main__': |
| 2146 import unittest | 2152 import unittest |
| 2147 unittest.main() | 2153 unittest.main() |
| OLD | NEW |