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

Unified Diff: tests/presubmit_unittest.py

Issue 558007: Add presubmit_canned_checks.CheckLicense() (Closed)
Patch Set: Created 10 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/presubmit_unittest.py
diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py
index c11283e3785c30b6cce5f8aa94df502864ada81c..3ed655fadf663994a5bf49fdffd6becb84d4a245 100755
--- a/tests/presubmit_unittest.py
+++ b/tests/presubmit_unittest.py
@@ -1069,6 +1069,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
'CheckChangeHasTestField',
'CheckChangeLintsClean',
'CheckChangeSvnEolStyle',
+ 'CheckLicense',
'CheckSvnModifiedDirectories',
'CheckSvnForCommonMimeTypes', 'CheckSvnProperty',
'CheckDoNotSubmit',
@@ -1282,6 +1283,66 @@ class CannedChecksUnittest(PresubmitTestsBase):
'svn:eol-style', 'LF', '', False,
presubmit.OutputApi.PresubmitNotifyResult, True)
+ def _LicenseCheck(self, text, license, committing, expected_result):
+ change = self.mox.CreateMock(presubmit.SvnChange)
+ change.scm = 'svn'
+ input_api = self.MockInputApi(change, committing)
+ affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
+ input_api.AffectedSourceFiles(42).AndReturn([affected_file])
+ input_api.ReadFile(affected_file, 'rb').AndReturn(text)
+ if expected_result:
+ affected_file.LocalPath().AndReturn('bleh')
+
+ self.mox.ReplayAll()
+ result = presubmit_canned_checks.CheckLicense(
+ input_api, presubmit.OutputApi, license, 42)
+ if expected_result:
+ self.assertEqual(len(result), 1)
+ self.assertEqual(result[0].__class__, expected_result)
+ else:
+ self.assertEqual(result, [])
+
+ def testCheckLicenseSuccess(self):
+ text = (
+ "#!/bin/python\n"
+ "# Copyright (c) 2037 Nobody.\n"
+ "# All Rights Reserved.\n"
+ "print 'foo'\n"
+ )
+ license = (
+ r".*? Copyright \(c\) 2037 Nobody." "\n"
+ r".*? All Rights Reserved\." "\n"
+ )
+ self._LicenseCheck(text, license, True, None)
+
+ def testCheckLicenseFailCommit(self):
+ text = (
+ "#!/bin/python\n"
+ "# Copyright (c) 2037 Nobody.\n"
+ "# All Rights Reserved.\n"
+ "print 'foo'\n"
+ )
+ license = (
+ r".*? Copyright \(c\) 0007 Nobody." "\n"
+ r".*? All Rights Reserved\." "\n"
+ )
+ self._LicenseCheck(text, license, True,
+ presubmit.OutputApi.PresubmitPromptWarning)
+
+ def testCheckLicenseFailUpload(self):
+ text = (
+ "#!/bin/python\n"
+ "# Copyright (c) 2037 Nobody.\n"
+ "# All Rights Reserved.\n"
+ "print 'foo'\n"
+ )
+ license = (
+ r".*? Copyright \(c\) 0007 Nobody." "\n"
+ r".*? All Rights Reserved\." "\n"
+ )
+ self._LicenseCheck(text, license, False,
+ presubmit.OutputApi.PresubmitNotifyResult)
+
def testCannedCheckSvnAccidentalSubmission(self):
modified_dir_file = 'foo/'
accidental_submssion_file = 'foo/bar.cc'
« no previous file with comments | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698