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

Side by Side Diff: tests/gclient_test.py

Issue 215039: Fix gclient unittests. (Closed)
Patch Set: Created 11 years, 3 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
« no previous file with comments | « no previous file | 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
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright 2008-2009 Google Inc. All Rights Reserved. 3 # Copyright 2008-2009 Google Inc. All Rights Reserved.
4 # 4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License. 6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at 7 # You may obtain a copy of the License at
8 # 8 #
9 # http://www.apache.org/licenses/LICENSE-2.0 9 # http://www.apache.org/licenses/LICENSE-2.0
10 # 10 #
(...skipping 17 matching lines...) Expand all
28 import gclient_scm 28 import gclient_scm
29 import gclient_utils 29 import gclient_utils
30 import super_mox 30 import super_mox
31 from super_mox import mox 31 from super_mox import mox
32 32
33 33
34 class BaseTestCase(super_mox.SuperMoxTestBase): 34 class BaseTestCase(super_mox.SuperMoxTestBase):
35 def setUp(self): 35 def setUp(self):
36 super_mox.SuperMoxTestBase.setUp(self) 36 super_mox.SuperMoxTestBase.setUp(self)
37 self.mox.StubOutWithMock(gclient.os.path, 'exists') 37 self.mox.StubOutWithMock(gclient.os.path, 'exists')
38 self.mox.StubOutWithMock(gclient.os.path, 'isfile')
38 self.mox.StubOutWithMock(gclient.os.path, 'isdir') 39 self.mox.StubOutWithMock(gclient.os.path, 'isdir')
39 self.mox.StubOutWithMock(gclient.os, 'remove') 40 self.mox.StubOutWithMock(gclient.os, 'remove')
40 self.mox.StubOutWithMock(gclient.sys, 'stdout') 41 self.mox.StubOutWithMock(gclient.sys, 'stdout')
41 self.mox.StubOutWithMock(gclient_utils, 'subprocess') 42 self.mox.StubOutWithMock(gclient_utils, 'subprocess')
42 # These are not tested. 43 # These are not tested.
43 self.mox.StubOutWithMock(gclient, 'FileRead') 44 self.mox.StubOutWithMock(gclient, 'FileRead')
44 self.mox.StubOutWithMock(gclient, 'FileWrite') 45 self.mox.StubOutWithMock(gclient, 'FileWrite')
45 self.mox.StubOutWithMock(gclient_utils, 'SubprocessCall') 46 self.mox.StubOutWithMock(gclient_utils, 'SubprocessCall')
46 self.mox.StubOutWithMock(gclient_utils, 'RemoveDirectory') 47 self.mox.StubOutWithMock(gclient_utils, 'RemoveDirectory')
47 48
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 self.mox.ReplayAll() 1085 self.mox.ReplayAll()
1085 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1086 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1086 relpath=self.relpath) 1087 relpath=self.relpath)
1087 scm.revert(options, self.args, files_list) 1088 scm.revert(options, self.args, files_list)
1088 1089
1089 def testRevertNone(self): 1090 def testRevertNone(self):
1090 options = self.Options(verbose=True) 1091 options = self.Options(verbose=True)
1091 base_path = os.path.join(self.root_dir, self.relpath) 1092 base_path = os.path.join(self.root_dir, self.relpath)
1092 gclient.os.path.isdir(base_path).AndReturn(True) 1093 gclient.os.path.isdir(base_path).AndReturn(True)
1093 gclient_scm.CaptureSVNStatus(base_path).AndReturn([]) 1094 gclient_scm.CaptureSVNStatus(base_path).AndReturn([])
1095 gclient_scm.RunSVNAndGetFileList(['update', '--revision', 'BASE'], base_path ,
Nicolas Sylvain 2009/09/21 22:30:43 80 chars
1096 mox.IgnoreArg())
1094 1097
1095 self.mox.ReplayAll() 1098 self.mox.ReplayAll()
1096 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1099 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1097 relpath=self.relpath) 1100 relpath=self.relpath)
1098 file_list = [] 1101 file_list = []
1099 scm.revert(options, self.args, file_list) 1102 scm.revert(options, self.args, file_list)
1100 1103
1101 def testRevert2Files(self): 1104 def testRevert2Files(self):
1102 options = self.Options(verbose=True) 1105 options = self.Options(verbose=True)
1103 base_path = os.path.join(self.root_dir, self.relpath) 1106 base_path = os.path.join(self.root_dir, self.relpath)
1104 gclient.os.path.isdir(base_path).AndReturn(True) 1107 gclient.os.path.isdir(base_path).AndReturn(True)
1105 items = [ 1108 items = [
1106 ('M ', 'a'), 1109 ('M ', 'a'),
1107 ('A ', 'b'), 1110 ('A ', 'b'),
1108 ] 1111 ]
1112 file_path1 = os.path.join(base_path, 'a')
1113 file_path2 = os.path.join(base_path, 'b')
1109 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items) 1114 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items)
1110 1115 gclient_scm.os.path.exists(file_path1).AndReturn(True)
1116 gclient_scm.os.path.isfile(file_path1).AndReturn(True)
1117 gclient_scm.os.remove(file_path1)
1118 gclient_scm.os.path.exists(file_path2).AndReturn(True)
1119 gclient_scm.os.path.isfile(file_path2).AndReturn(True)
1120 gclient_scm.os.remove(file_path2)
1121 gclient_scm.RunSVNAndGetFileList(['update', '--revision', 'BASE'], base_path ,
Nicolas Sylvain 2009/09/21 22:30:43 80 chars
1122 mox.IgnoreArg())
1111 print(os.path.join(base_path, 'a')) 1123 print(os.path.join(base_path, 'a'))
1112 print(os.path.join(base_path, 'b')) 1124 print(os.path.join(base_path, 'b'))
1113 gclient_scm.RunSVN(['revert', 'a', 'b'], base_path)
1114 1125
1115 self.mox.ReplayAll() 1126 self.mox.ReplayAll()
1116 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1127 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1117 relpath=self.relpath) 1128 relpath=self.relpath)
1118 file_list = [] 1129 file_list = []
1119 scm.revert(options, self.args, file_list) 1130 scm.revert(options, self.args, file_list)
1120 self.assertEquals(sorted(file_list), sorted([os.path.join(base_path, 'a'),
1121 os.path.join(base_path, 'b')]))
1122 1131
1123 def testRevertUnversionedUnexpectedFile(self): 1132 def testRevertDirectory(self):
1124 options = self.Options(verbose=True) 1133 options = self.Options(verbose=True)
1125 base_path = os.path.join(self.root_dir, self.relpath) 1134 base_path = os.path.join(self.root_dir, self.relpath)
1126 gclient.os.path.isdir(base_path).AndReturn(True) 1135 gclient.os.path.isdir(base_path).AndReturn(True)
1127 items = [ 1136 items = [
1128 ('~ ', 'a'), 1137 ('~ ', 'a'),
1129 ] 1138 ]
1130 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items) 1139 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items)
1131 file_path = os.path.join(base_path, 'a') 1140 file_path = os.path.join(base_path, 'a')
1132 print(file_path) 1141 print(file_path)
1133 gclient_scm.os.remove(file_path).AndRaise(EnvironmentError()) 1142 gclient_scm.os.path.exists(file_path).AndReturn(True)
1143 gclient_scm.os.path.isfile(file_path).AndReturn(False)
1144 gclient_scm.os.path.isdir(file_path).AndReturn(True)
1145 #gclient_scm.os.remove(file_path)
Nicolas Sylvain 2009/09/21 22:30:43 why?
1134 gclient_utils.RemoveDirectory(file_path) 1146 gclient_utils.RemoveDirectory(file_path)
1135 gclient_scm.RunSVN(['revert', 'a'], base_path) 1147 file_list1 = []
1148 gclient_scm.RunSVNAndGetFileList(['update', '--revision', 'BASE'], base_path ,
Nicolas Sylvain 2009/09/21 22:30:43 80 chars
1149 mox.IgnoreArg())
1136 1150
1137 self.mox.ReplayAll() 1151 self.mox.ReplayAll()
1138 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1152 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1139 relpath=self.relpath) 1153 relpath=self.relpath)
1140 file_list = [] 1154 file_list2 = []
1141 scm.revert(options, self.args, file_list) 1155 scm.revert(options, self.args, file_list2)
1142 # TODO(msb): fix bug (file_list contains dupes) and enable assertion
1143 #self.assertEquals(file_list, [os.path.join(base_path, 'a')])
1144 1156
1145 def testStatus(self): 1157 def testStatus(self):
1146 options = self.Options(verbose=True) 1158 options = self.Options(verbose=True)
1147 base_path = os.path.join(self.root_dir, self.relpath) 1159 base_path = os.path.join(self.root_dir, self.relpath)
1148 gclient.os.path.isdir(base_path).AndReturn(True) 1160 gclient.os.path.isdir(base_path).AndReturn(True)
1149 gclient_scm.RunSVNAndGetFileList(['status'] + self.args, base_path, 1161 gclient_scm.RunSVNAndGetFileList(['status'] + self.args, base_path,
1150 []).AndReturn(None) 1162 []).AndReturn(None)
1151 1163
1152 self.mox.ReplayAll() 1164 self.mox.ReplayAll()
1153 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1165 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 """ 1419 """
1408 gclient_scm.CaptureSVN = CaptureSVNMock 1420 gclient_scm.CaptureSVN = CaptureSVNMock
1409 info = gclient_scm.CaptureSVNStatus(None) 1421 info = gclient_scm.CaptureSVNStatus(None)
1410 self.assertEquals(info, []) 1422 self.assertEquals(info, [])
1411 1423
1412 1424
1413 if __name__ == '__main__': 1425 if __name__ == '__main__':
1414 unittest.main() 1426 unittest.main()
1415 1427
1416 # vim: ts=2:sw=2:tw=80:et: 1428 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698