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

Side by Side Diff: tests/gcl_unittest.py

Issue 100095: Convert gcl.GetSVNFileInfo() to xml format. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 11 years, 7 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 | « revert.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')
Property Changes:
Added: svn:executable
+ *
Added: svn:eol-style
+ LF
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 gcl.py."""
7
8 import os
9 import unittest
10
11 # Local imports
12 import gcl
13
14
15 class GclTestsBase(unittest.TestCase):
16 """Setups and tear downs the mocks but doesn't test anything as-is."""
17 def setUp(self):
18 def RunShellMock(filename):
19 return filename
20 self._RunShell = gcl.RunShell
21 gcl.RunShell = RunShellMock
22
23 def tearDown(self):
24 gcl.RunShell = self._RunShell
25
26 def compareMembers(self, object, members):
27 """If you add a member, be sure to add the relevant test!"""
28 # Skip over members starting with '_' since they are usually not meant to
29 # be for public use.
30 actual_members = [x for x in sorted(dir(object))
31 if not x.startswith('_')]
32 expected_members = sorted(members)
33 if actual_members != expected_members:
34 diff = ([i for i in actual_members if i not in expected_members] +
35 [i for i in expected_members if i not in actual_members])
36 print diff
37 self.assertEqual(actual_members, expected_members)
38
39
40 class GclUnittest(GclTestsBase):
41 """General gcl.py tests."""
42 def testMembersChanged(self):
43 members = [
44 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', 'CPP_EXTENSIONS',
45 'Change', 'ChangeInfo', 'Changes', 'Commit', 'DoPresubmitChecks',
46 'ErrorExit', 'GenerateChangeName', 'GenerateDiff', 'GetCLs',
47 'GetChangelistInfoFile', 'GetCodeReviewSetting', 'GetEditor',
48 'GetFilesNotInCL', 'GetInfoDir', 'GetIssueDescription',
49 'GetModifiedFiles', 'GetNamedNodeText', 'GetNodeNamedAttributeText',
50 'GetRepositoryRoot', 'GetSVNFileInfo', 'GetSVNStatus',
51 'GetSVNFileProperty', 'Help', 'IGNORE_PATHS', 'IsSVNMoved', 'IsTreeOpen',
52 'Lint', 'LoadChangelistInfo', 'LoadChangelistInfoForMultiple',
53 'MISSING_TEST_MSG', 'Opened', 'ParseXML', 'PresubmitCL', 'ReadFile',
54 'RunShell',
55 'RunShellWithReturnCode', 'SEPARATOR', 'SendToRietveld', 'TryChange',
56 'UnknownFiles', 'UploadCL', 'Warn', 'WriteFile', 'gcl_info_dir',
57 'getpass', 'main', 'os', 'random', 're', 'read_gcl_info',
58 'repository_root', 'string', 'subprocess', 'sys', 'tempfile', 'upload',
59 'urllib2', 'use_shell', 'xml',
60
61 ]
62 # If this test fails, you should add the relevant test.
63 self.compareMembers(gcl, members)
64
65 def testGetSVNFileInfo(self):
66 def RunShellMock(command):
67 return r"""<?xml version="1.0"?>
68 <info>
69 <entry kind="file" path="%s" revision="14628">
70 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url>
71 <repository><root>http://src.chromium.org/svn</root></repository>
72 <wc-info>
73 <schedule>add</schedule>
74 <depth>infinity</depth>
75 <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from- url>
76 <copy-from-rev>14628</copy-from-rev>
77 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum>
78 </wc-info>
79 </entry>
80 </info>
81 """ % command[3]
82 gcl.RunShell = RunShellMock
83 filename = os.path.join('app', 'd')
84 info = gcl.GetSVNFileInfo(filename)
85 expected = {
86 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d',
87 'Repository Root': 'http://src.chromium.org/svn',
88 'Schedule': 'add',
89 'Copied From URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS' ,
90 'Copied From Rev': '14628',
91 'Path': filename,
92 'Node Kind': 'file',
93 }
94 self.assertEquals(sorted(info.items()), sorted(expected.items()))
95
96 def testGetSVNStatus(self):
97 def RunShellMock(command):
98 return r"""<?xml version="1.0"?>
99 <status>
100 <target path=".">
101 <entry path="unversionned_file.txt">
102 <wc-status props="none" item="unversioned"></wc-status>
103 </entry>
104 <entry path="build\internal\essential.vsprops">
105 <wc-status props="normal" item="modified" revision="14628">
106 <commit revision="13818">
107 <author>ajwong@chromium.org</author>
108 <date>2009-04-16T00:42:06.872358Z</date>
109 </commit>
110 </wc-status>
111 </entry>
112 <entry path="chrome\app\d">
113 <wc-status props="none" copied="true" tree-conflicted="true" item="added">
114 </wc-status>
115 </entry>
116 <entry path="chrome\app\DEPS">
117 <wc-status props="modified" item="modified" revision="14628">
118 <commit revision="1279">
119 <author>brettw@google.com</author>
120 <date>2008-08-23T17:16:42.090152Z</date>
121 </commit>
122 </wc-status>
123 </entry>
124 <entry path="scripts\master\factory\gclient_factory.py">
125 <wc-status props="normal" item="conflicted" revision="14725">
126 <commit revision="14633">
127 <author>nsylvain@chromium.org</author>
128 <date>2009-04-27T19:37:17.977400Z</date>
129 </commit>
130 </wc-status>
131 </entry>
132 </target>
133 </status>
134 """
135 gcl.RunShell = RunShellMock
136 info = gcl.GetSVNStatus('.')
137 expected = [
138 ('? ', 'unversionned_file.txt'),
139 ('M ', 'build\\internal\\essential.vsprops'),
140 ('A + ', 'chrome\\app\\d'),
141 ('MM ', 'chrome\\app\\DEPS'),
142 ('C ', 'scripts\\master\\factory\\gclient_factory.py'),
143 ]
144 self.assertEquals(sorted(info), sorted(expected))
145
146 def testGetSVNStatusEmpty(self):
147 def RunShellMock(command):
148 return r"""<?xml version="1.0"?>
149 <status>
150 <target
151 path="perf">
152 </target>
153 </status>
154 """
155 gcl.RunShell = RunShellMock
156 info = gcl.GetSVNStatus(None)
157 self.assertEquals(info, [])
158
159
160 if __name__ == '__main__':
161 unittest.main()
OLDNEW
« no previous file with comments | « revert.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698