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

Side by Side Diff: tests/patch_test.py

Issue 6055005: Add a function to detect patches that can't be safely applied. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/commit-queue
Patch Set: Rebase against trunk Created 9 years, 12 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 | « pending_manager.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/env python
2 # Copyright (c) 2010 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 patch.py."""
7
8 import os
9 import sys
10 import unittest
11
12 ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
13 sys.path.append(os.path.join(ROOT_DIR, '..'))
14
15 import patch
16
17
18 class PatchTest(unittest.TestCase):
19 def testUnsupportedMerge(self):
20 data = (
21 '\n'
22 'Property changes on: .\n'
23 '\n'
24 '___________________________________________________________________\n'
25 'Modified: svn:mergeinfo\n'
26 ' Merged /trunk:r635-639\n'
27 '\n')
28 self.assertEquals(
29 'Can\'t apply svn property svn:mergeinfo', patch.verify_patch(data))
30
31 def testUnsupportedEmptyfileSvn1(self):
32 data = (
33 'Index: foo.py\n'
34 '===================================================================\n'
35 '\n'
36 'Property changes on: foo.py\n'
37 '___________________________________________________________________\n'
38 'Added: svn:eol-style\n'
39 ' + LF\n'
40 '\n')
41 self.assertEquals(
42 'Can\'t patch empty file (svn)', patch.verify_patch(data))
43
44 def testUnsupportedEmptyfileSvn2(self):
45 data = (
46 'Index: foo.py\n'
47 '===================================================================\n')
48 self.assertEquals(
49 'Can\'t patch empty file (svn)', patch.verify_patch(data))
50
51 def testUnsupportedEmptyfileGit(self):
52 data = (
53 'diff --git a/git_cl/git-cl b/git_cl/git-cl\n')
54 self.assertEquals(
55 'Can\'t patch empty file (git)', patch.verify_patch(data))
56
57 def testUnsupportedGitMode1(self):
58 data = (
59 'diff --git a/git_cl/git-cl b/git_cl/git-cl\n'
60 'old mode 100644\n'
61 'new mode 100755\n')
62 self.assertEquals(
63 'Unsupported git file mode change', patch.verify_patch(data))
64
65 def testUnsupportedGitMode2(self):
66 data = (
67 'diff --git a/git_cl/git-cl b/git_cl/git-cl\n'
68 'old mode 100644\n'
69 'new mode 100755\n'
70 'index 449c6e0..b035565\n'
71 '--- a/git_cl/git-cl\n'
72 '+++ b/git_cl/git-cl\n'
73 '@@ -3,7 +3,7 @@\n'
74 ' # Copyright (C) 2008 Evan Martin <martine@danga.com>\n'
75 '\n'
76 ' import sys\n'
77 '-\n'
78 '+foo\n'
79 ' import git_cl\n'
80 '\n'
81 ' if __name__ == \'__main__\':\n')
82 self.assertEquals(
83 'Unsupported git file mode change', patch.verify_patch(data))
84
85 def testSupported1(self):
86 data = (
87 'Index: foo\n'
88 '===================================================================\n'
89 '--- foo (revision 639)\n'
90 '+++ foo (working copy)\n'
91 '@@ -1,6 +1,6 @@\n'
92 ' Welcome to Rietveld\n'
93 ' -------------------\n'
94 '-\n'
95 '+2\n'
96 ' This project shows how to create a somewhat substantial web '
97 'application\n'
98 ' using Django on Google App Engine. It requires Django version 1.1.\n'
99 '\n'
100 '\n'
101 'Property changes on: foo\n'
102 '___________________________________________________________________\n'
103 'Modified: svn:eol-style\n'
104 ' - native\n'
105 ' + LF\n'
106 '\n')
107 self.assertEquals(None, patch.verify_patch(data))
108
109 def testSupported2(self):
110 data = (
111 'Index: patch.py\n'
112 'diff --git a/patch.py b/patch.py\n'
113 'index af18ee43e212583815d27d138d1fc426883eb663..8433a962e8586c7a84413'
114 '6dc1e43d10e0a542d13 100644\n'
115 '--- a/patch.py\n'
116 '+++ b/patch.py\n'
117 '@@ -1,8 +1,10 @@\n'
118 '+# coding=utf8\n'
119 ' # Copyright (c) 2010 The Chromium Authors. All rights reserved.\n'
120 ' # Use of this source code is governed by a BSD-style license that can'
121 ' be\n'
122 ' # found in the LICENSE file.\n'
123 ' """Utility functions to handle patches."""\n'
124 ' \n'
125 '+import logging\n'
126 ' import re\n'
127 ' import subprocess2\n'
128 ' \n')
129 self.assertEquals(None, patch.verify_patch(data))
130
131 def testSupported3(self):
132 data = (
133 'Index: tests/patch_test.py\n'
134 'diff --git a/tests/patch_test.py b/tests/patch_test.py\n'
135 'new file mode 100755\n'
136 'index 0000000000000000000000000000000000000000..a9dc5827926d57bc5dc8'
137 'f5106a0a63c891cce38c\n'
138 '--- /dev/null\n'
139 '+++ b/tests/patch_test.py\n'
140 '@@ -0,0 +1,1 @@\n'
141 '+#!/usr/bin/env python\n')
142 self.assertEquals(None, patch.verify_patch(data))
143
144
145 if __name__ == '__main__':
146 unittest.main()
OLDNEW
« no previous file with comments | « pending_manager.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698