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 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 # fetched until 'src' is done. | 87 # fetched until 'src' is done. |
88 # jobs is the number of parallel jobs simulated. reverse is to reshuffle the | 88 # jobs is the number of parallel jobs simulated. reverse is to reshuffle the |
89 # list to see if it is still processed in order correctly. | 89 # list to see if it is still processed in order correctly. |
90 parser = gclient.Parser() | 90 parser = gclient.Parser() |
91 options, args = parser.parse_args(['--jobs', jobs]) | 91 options, args = parser.parse_args(['--jobs', jobs]) |
92 write( | 92 write( |
93 '.gclient', | 93 '.gclient', |
94 'solutions = [\n' | 94 'solutions = [\n' |
95 ' { "name": "foo", "url": "svn://example.com/foo" },\n' | 95 ' { "name": "foo", "url": "svn://example.com/foo" },\n' |
96 ' { "name": "bar", "url": "svn://example.com/bar" },\n' | 96 ' { "name": "bar", "url": "svn://example.com/bar" },\n' |
| 97 ' { "name": "bar/empty", "url": "svn://example.com/bar_empty" },\n' |
97 ']') | 98 ']') |
98 write( | 99 write( |
99 os.path.join('foo', 'DEPS'), | 100 os.path.join('foo', 'DEPS'), |
100 'deps = {\n' | 101 'deps = {\n' |
101 ' "foo/dir1": "/dir1",\n' | 102 ' "foo/dir1": "/dir1",\n' |
102 ' "foo/dir1/dir2/dir3": "/dir1/dir2/dir3",\n' | 103 ' "foo/dir1/dir2/dir3": "/dir1/dir2/dir3",\n' |
103 ' "foo/dir1/dir4": "/dir1/dir4",\n' | 104 ' "foo/dir1/dir4": "/dir1/dir4",\n' |
104 ' "foo/dir1/dir2/dir3/dir4": "/dir1/dir2/dir3/dir4",\n' | 105 ' "foo/dir1/dir2/dir3/dir4": "/dir1/dir2/dir3/dir4",\n' |
105 '}') | 106 '}') |
106 write( | 107 write( |
107 os.path.join('bar', 'DEPS'), | 108 os.path.join('bar', 'DEPS'), |
108 'deps = {\n' | 109 'deps = {\n' |
109 ' "foo/dir1/dir2": "/dir1/dir2",\n' | 110 ' "foo/dir1/dir2": "/dir1/dir2",\n' |
110 '}') | 111 '}') |
| 112 write( |
| 113 os.path.join('bar/empty', 'DEPS'), |
| 114 'deps = {\n' |
| 115 '}') |
111 | 116 |
112 obj = gclient.GClient.LoadCurrentConfig(options) | 117 obj = gclient.GClient.LoadCurrentConfig(options) |
113 self._check_requirements(obj.dependencies[0], {}) | 118 self._check_requirements(obj.dependencies[0], {}) |
114 self._check_requirements(obj.dependencies[1], {}) | 119 self._check_requirements(obj.dependencies[1], {}) |
115 obj.RunOnDeps('None', args) | 120 obj.RunOnDeps('None', args) |
116 # The trick here is to manually process the list to make sure it's out of | 121 # The trick here is to manually process the list to make sure it's out of |
117 # order. | 122 # order. |
118 obj.dependencies[0].dependencies.sort(key=lambda x: x.name, reverse=reverse) | 123 for i in obj.dependencies: |
| 124 i.dependencies.sort(key=lambda x: x.name, reverse=reverse) |
119 actual = self._get_processed() | 125 actual = self._get_processed() |
120 # We don't care of the ordering of this item. | 126 # We don't care of the ordering of these items: |
| 127 self.assertEquals( |
| 128 ['svn://example.com/bar', 'svn://example.com/foo'], sorted(actual[0:2])) |
| 129 actual = actual[2:] |
| 130 # Ordering may not be exact in case of parallel jobs. |
| 131 self.assertGreater( |
| 132 actual.index('svn://example.com/bar/dir1/dir2'), |
| 133 actual.index('svn://example.com/foo/dir1')) |
121 actual.remove('svn://example.com/bar/dir1/dir2') | 134 actual.remove('svn://example.com/bar/dir1/dir2') |
| 135 |
| 136 # Ordering may not be exact in case of parallel jobs. |
| 137 actual.remove('svn://example.com/bar_empty') |
122 self.assertEquals( | 138 self.assertEquals( |
123 [ | 139 [ |
124 'svn://example.com/foo', | |
125 'svn://example.com/bar', | |
126 'svn://example.com/foo/dir1', | 140 'svn://example.com/foo/dir1', |
127 'svn://example.com/foo/dir1/dir4', | 141 'svn://example.com/foo/dir1/dir4', |
128 'svn://example.com/foo/dir1/dir2/dir3', | 142 'svn://example.com/foo/dir1/dir2/dir3', |
129 'svn://example.com/foo/dir1/dir2/dir3/dir4', | 143 'svn://example.com/foo/dir1/dir2/dir3/dir4', |
130 ], | 144 ], |
131 actual) | 145 actual) |
132 self._check_requirements( | 146 self._check_requirements( |
133 obj.dependencies[0], | 147 obj.dependencies[0], |
134 { | 148 { |
135 'foo/dir1': ['foo'], | 149 'foo/dir1': ['foo'], |
136 'foo/dir1/dir2/dir3': ['foo', 'foo/dir1'], | 150 'foo/dir1/dir2/dir3': ['foo', 'foo/dir1', 'foo/dir1/dir2'], |
137 'foo/dir1/dir2/dir3/dir4': ['foo', 'foo/dir1', 'foo/dir1/dir2/dir3'], | 151 'foo/dir1/dir2/dir3/dir4': |
| 152 ['foo', 'foo/dir1', 'foo/dir1/dir2', 'foo/dir1/dir2/dir3'], |
138 'foo/dir1/dir4': ['foo', 'foo/dir1'], | 153 'foo/dir1/dir4': ['foo', 'foo/dir1'], |
139 }) | 154 }) |
140 self._check_requirements( | 155 self._check_requirements( |
141 obj.dependencies[1], | 156 obj.dependencies[1], |
142 { | 157 { |
143 'foo/dir1/dir2': ['bar'], | 158 'foo/dir1/dir2': ['bar', 'foo', 'foo/dir1'], |
| 159 }) |
| 160 self._check_requirements( |
| 161 obj, |
| 162 { |
| 163 'foo': [], |
| 164 'bar': [], |
| 165 'bar/empty': ['bar'], |
144 }) | 166 }) |
145 | 167 |
146 def _check_requirements(self, solution, expected): | 168 def _check_requirements(self, solution, expected): |
147 for dependency in solution.dependencies: | 169 for dependency in solution.dependencies: |
148 self.assertEquals(expected.pop(dependency.name), dependency.requirements) | 170 self.assertEquals( |
| 171 expected.pop(dependency.name), sorted(dependency.requirements)) |
149 self.assertEquals({}, expected) | 172 self.assertEquals({}, expected) |
150 | 173 |
151 def _get_processed(self): | 174 def _get_processed(self): |
152 items = [] | 175 items = [] |
153 try: | 176 try: |
154 while True: | 177 while True: |
155 items.append(self.processed.get_nowait()) | 178 items.append(self.processed.get_nowait()) |
156 except Queue.Empty: | 179 except Queue.Empty: |
157 pass | 180 pass |
158 return items | 181 return items |
159 | 182 |
160 | 183 |
161 if __name__ == '__main__': | 184 if __name__ == '__main__': |
162 logging.basicConfig( | 185 logging.basicConfig( |
163 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 186 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
164 min(sys.argv.count('-v'), 3)], | 187 min(sys.argv.count('-v'), 3)], |
165 format='%(asctime).19s %(levelname)s %(filename)s:' | 188 format='%(asctime).19s %(levelname)s %(filename)s:' |
166 '%(lineno)s %(message)s') | 189 '%(lineno)s %(message)s') |
167 unittest.main() | 190 unittest.main() |
OLD | NEW |