| 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 gclient.py. | 6 """Unit tests for gclient.py. |
| 7 | 7 |
| 8 See gclient_smoketest.py for integration tests. | 8 See gclient_smoketest.py for integration tests. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 from __future__ import with_statement | 11 from __future__ import with_statement |
| 12 import Queue | 12 import Queue |
| 13 import logging | 13 import logging |
| 14 import os | 14 import os |
| 15 import sys | 15 import sys |
| 16 import unittest | 16 import unittest |
| 17 | 17 |
| 18 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | 18 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 19 sys.path.insert(0, os.path.dirname(BASE_DIR)) | 19 sys.path.insert(0, os.path.dirname(BASE_DIR)) |
| 20 | 20 |
| 21 import gclient | 21 import gclient |
| 22 import gclient_utils |
| 22 from tests import trial_dir | 23 from tests import trial_dir |
| 23 | 24 |
| 24 | 25 |
| 25 def write(filename, content): | 26 def write(filename, content): |
| 26 """Writes the content of a file and create the directories as needed.""" | 27 """Writes the content of a file and create the directories as needed.""" |
| 27 filename = os.path.abspath(filename) | 28 filename = os.path.abspath(filename) |
| 28 dirname = os.path.dirname(filename) | 29 dirname = os.path.dirname(filename) |
| 29 if not os.path.isdir(dirname): | 30 if not os.path.isdir(dirname): |
| 30 os.makedirs(dirname) | 31 os.makedirs(dirname) |
| 31 with open(filename, 'w') as f: | 32 with open(filename, 'w') as f: |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 actual.remove('svn://example.com/bar_empty') | 156 actual.remove('svn://example.com/bar_empty') |
| 156 self.assertEquals( | 157 self.assertEquals( |
| 157 [ | 158 [ |
| 158 'svn://example.com/foo/dir1', | 159 'svn://example.com/foo/dir1', |
| 159 'svn://example.com/foo/dir1/dir2/dir3', | 160 'svn://example.com/foo/dir1/dir2/dir3', |
| 160 'svn://example.com/foo/dir1/dir2/dir3/dir4', | 161 'svn://example.com/foo/dir1/dir2/dir3/dir4', |
| 161 # TODO(maruel): This is probably wrong. | 162 # TODO(maruel): This is probably wrong. |
| 162 'svn://example.com/foo/dir1/dir2/dir3/dir4/dir1/another', | 163 'svn://example.com/foo/dir1/dir2/dir3/dir4/dir1/another', |
| 163 ], | 164 ], |
| 164 actual) | 165 actual) |
| 166 |
| 165 self._check_requirements( | 167 self._check_requirements( |
| 166 obj.dependencies[0], | 168 obj.dependencies[0], |
| 167 { | 169 { |
| 168 'foo/dir1': ['foo'], | 170 'foo/dir1': ['foo'], |
| 169 'foo/dir1/dir2/dir3': ['foo', 'foo/dir1', 'foo/dir1/dir2'], | 171 'foo/dir1/dir2/dir3': ['foo', 'foo/dir1', 'foo/dir1/dir2'], |
| 170 'foo/dir1/dir2/dir3/dir4': | 172 'foo/dir1/dir2/dir3/dir4': |
| 171 ['foo', 'foo/dir1', 'foo/dir1/dir2', 'foo/dir1/dir2/dir3'], | 173 ['foo', 'foo/dir1', 'foo/dir1/dir2', 'foo/dir1/dir2/dir3'], |
| 172 'foo/dir1/dir2/dir5/dir6': | 174 'foo/dir1/dir2/dir5/dir6': |
| 173 ['foo', 'foo/dir1', 'foo/dir1/dir2', 'foo/dir1/dir2/dir3/dir4'], | 175 ['foo', 'foo/dir1', 'foo/dir1/dir2', 'foo/dir1/dir2/dir3/dir4'], |
| 174 }) | 176 }) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 185 'bar/empty': ['bar'], | 187 'bar/empty': ['bar'], |
| 186 }) | 188 }) |
| 187 | 189 |
| 188 def _check_requirements(self, solution, expected): | 190 def _check_requirements(self, solution, expected): |
| 189 for dependency in solution.dependencies: | 191 for dependency in solution.dependencies: |
| 190 self.assertEquals( | 192 self.assertEquals( |
| 191 expected.pop(dependency.name), sorted(dependency.requirements)) | 193 expected.pop(dependency.name), sorted(dependency.requirements)) |
| 192 self.assertEquals({}, expected) | 194 self.assertEquals({}, expected) |
| 193 | 195 |
| 194 def _get_processed(self): | 196 def _get_processed(self): |
| 197 """Retrieves the item in the order they were processed.""" |
| 195 items = [] | 198 items = [] |
| 196 try: | 199 try: |
| 197 while True: | 200 while True: |
| 198 items.append(self.processed.get_nowait()) | 201 items.append(self.processed.get_nowait()) |
| 199 except Queue.Empty: | 202 except Queue.Empty: |
| 200 pass | 203 pass |
| 201 return items | 204 return items |
| 202 | 205 |
| 203 def testAutofix(self): | 206 def testAutofix(self): |
| 204 # Invalid urls causes pain when specifying requirements. Make sure it's | 207 # Invalid urls causes pain when specifying requirements. Make sure it's |
| (...skipping 27 matching lines...) Expand all Loading... |
| 232 obj.dependencies[0]._dependencies.append( | 235 obj.dependencies[0]._dependencies.append( |
| 233 gclient.Dependency( | 236 gclient.Dependency( |
| 234 obj.dependencies[0], 'foo/dir3', | 237 obj.dependencies[0], 'foo/dir3', |
| 235 gclient.GClientKeywords.FileImpl('url'), None, None, None, None, | 238 gclient.GClientKeywords.FileImpl('url'), None, None, None, None, |
| 236 'DEPS', True)) | 239 'DEPS', True)) |
| 237 obj.dependencies[0]._file_list.append('foo') | 240 obj.dependencies[0]._file_list.append('foo') |
| 238 self.assertEquals(434, len(str(obj)), '%d\n%s' % (len(str(obj)), str(obj))) | 241 self.assertEquals(434, len(str(obj)), '%d\n%s' % (len(str(obj)), str(obj))) |
| 239 | 242 |
| 240 | 243 |
| 241 if __name__ == '__main__': | 244 if __name__ == '__main__': |
| 245 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) |
| 246 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) |
| 247 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) |
| 248 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) |
| 242 logging.basicConfig( | 249 logging.basicConfig( |
| 243 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 250 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
| 244 min(sys.argv.count('-v'), 3)], | 251 min(sys.argv.count('-v'), 3)], |
| 245 format='%(asctime).19s %(levelname)s %(filename)s:' | 252 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' |
| 246 '%(lineno)s %(message)s') | 253 '%(lineno)d) %(message)s') |
| 247 unittest.main() | 254 unittest.main() |
| OLD | NEW |