Chromium Code Reviews| 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 | |
| 167 # Now check requirements. | |
|
Dirk Pranke
2011/10/04 22:14:13
I doubt this comment adds anything.
| |
| 165 self._check_requirements( | 168 self._check_requirements( |
| 166 obj.dependencies[0], | 169 obj.dependencies[0], |
| 167 { | 170 { |
| 168 'foo/dir1': ['foo'], | 171 'foo/dir1': ['foo'], |
| 169 'foo/dir1/dir2/dir3': ['foo', 'foo/dir1', 'foo/dir1/dir2'], | 172 'foo/dir1/dir2/dir3': ['foo', 'foo/dir1', 'foo/dir1/dir2'], |
| 170 'foo/dir1/dir2/dir3/dir4': | 173 'foo/dir1/dir2/dir3/dir4': |
| 171 ['foo', 'foo/dir1', 'foo/dir1/dir2', 'foo/dir1/dir2/dir3'], | 174 ['foo', 'foo/dir1', 'foo/dir1/dir2', 'foo/dir1/dir2/dir3'], |
| 172 'foo/dir1/dir2/dir5/dir6': | 175 'foo/dir1/dir2/dir5/dir6': |
| 173 ['foo', 'foo/dir1', 'foo/dir1/dir2', 'foo/dir1/dir2/dir3/dir4'], | 176 ['foo', 'foo/dir1', 'foo/dir1/dir2', 'foo/dir1/dir2/dir3/dir4'], |
| 174 }) | 177 }) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 185 'bar/empty': ['bar'], | 188 'bar/empty': ['bar'], |
| 186 }) | 189 }) |
| 187 | 190 |
| 188 def _check_requirements(self, solution, expected): | 191 def _check_requirements(self, solution, expected): |
| 189 for dependency in solution.dependencies: | 192 for dependency in solution.dependencies: |
| 190 self.assertEquals( | 193 self.assertEquals( |
| 191 expected.pop(dependency.name), sorted(dependency.requirements)) | 194 expected.pop(dependency.name), sorted(dependency.requirements)) |
| 192 self.assertEquals({}, expected) | 195 self.assertEquals({}, expected) |
| 193 | 196 |
| 194 def _get_processed(self): | 197 def _get_processed(self): |
| 198 """Retrieves the item in the order they were processed.""" | |
| 195 items = [] | 199 items = [] |
| 196 try: | 200 try: |
| 197 while True: | 201 while True: |
| 198 items.append(self.processed.get_nowait()) | 202 items.append(self.processed.get_nowait()) |
| 199 except Queue.Empty: | 203 except Queue.Empty: |
| 200 pass | 204 pass |
| 201 return items | 205 return items |
| 202 | 206 |
| 203 def testAutofix(self): | 207 def testAutofix(self): |
| 204 # Invalid urls causes pain when specifying requirements. Make sure it's | 208 # Invalid urls causes pain when specifying requirements. Make sure it's |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 232 obj.dependencies[0]._dependencies.append( | 236 obj.dependencies[0]._dependencies.append( |
| 233 gclient.Dependency( | 237 gclient.Dependency( |
| 234 obj.dependencies[0], 'foo/dir3', | 238 obj.dependencies[0], 'foo/dir3', |
| 235 gclient.GClientKeywords.FileImpl('url'), None, None, None, None, | 239 gclient.GClientKeywords.FileImpl('url'), None, None, None, None, |
| 236 'DEPS', True)) | 240 'DEPS', True)) |
| 237 obj.dependencies[0]._file_list.append('foo') | 241 obj.dependencies[0]._file_list.append('foo') |
| 238 self.assertEquals(434, len(str(obj)), '%d\n%s' % (len(str(obj)), str(obj))) | 242 self.assertEquals(434, len(str(obj)), '%d\n%s' % (len(str(obj)), str(obj))) |
| 239 | 243 |
| 240 | 244 |
| 241 if __name__ == '__main__': | 245 if __name__ == '__main__': |
| 246 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) | |
| 247 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) | |
| 248 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) | |
| 249 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) | |
| 242 logging.basicConfig( | 250 logging.basicConfig( |
| 243 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 251 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
| 244 min(sys.argv.count('-v'), 3)], | 252 min(sys.argv.count('-v'), 3)], |
| 245 format='%(asctime).19s %(levelname)s %(filename)s:' | 253 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' |
| 246 '%(lineno)s %(message)s') | 254 '%(lineno)d) %(message)s') |
| 247 unittest.main() | 255 unittest.main() |
| OLD | NEW |