OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 git_common.py""" | 6 """Unit tests for git_common.py""" |
7 | 7 |
8 import binascii | 8 import binascii |
9 import collections | 9 import collections |
10 import os | 10 import os |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 result = [] | 79 result = [] |
80 with self.gc.ScopedPool(kind='threads') as pool: | 80 with self.gc.ScopedPool(kind='threads') as pool: |
81 result = list(pool.imap(slow_square, xrange(10))) | 81 result = list(pool.imap(slow_square, xrange(10))) |
82 self.assertEqual([0, 1, 4, 9, 16, 25, 36, 49, 64, 81], result) | 82 self.assertEqual([0, 1, 4, 9, 16, 25, 36, 49, 64, 81], result) |
83 | 83 |
84 def testThreadsCtrlC(self): | 84 def testThreadsCtrlC(self): |
85 result = [] | 85 result = [] |
86 with self.assertRaises(KeyboardInterrupt): | 86 with self.assertRaises(KeyboardInterrupt): |
87 with self.gc.ScopedPool(kind='threads') as pool: | 87 with self.gc.ScopedPool(kind='threads') as pool: |
88 # Make sure this pool is interrupted in mid-swing | 88 # Make sure this pool is interrupted in mid-swing |
89 for i in pool.imap(slow_square, xrange(1000000)): | 89 for i in pool.imap(slow_square, xrange(20)): |
90 if i > 32: | 90 if i > 32: |
91 os.kill(os.getpid(), self.CTRL_C) | 91 os.kill(os.getpid(), self.CTRL_C) |
92 result.append(i) | 92 result.append(i) |
93 self.assertEqual([0, 1, 4, 9, 16, 25], result) | 93 self.assertEqual([0, 1, 4, 9, 16, 25], result) |
94 | 94 |
95 def testProcs(self): | 95 def testProcs(self): |
96 result = [] | 96 result = [] |
97 with self.gc.ScopedPool() as pool: | 97 with self.gc.ScopedPool() as pool: |
98 result = list(pool.imap(slow_square, xrange(10))) | 98 result = list(pool.imap(slow_square, xrange(10))) |
99 self.assertEqual([0, 1, 4, 9, 16, 25, 36, 49, 64, 81], result) | 99 self.assertEqual([0, 1, 4, 9, 16, 25, 36, 49, 64, 81], result) |
100 | 100 |
101 def testProcsCtrlC(self): | 101 def testProcsCtrlC(self): |
102 result = [] | 102 result = [] |
103 with self.assertRaises(KeyboardInterrupt): | 103 with self.assertRaises(KeyboardInterrupt): |
104 with self.gc.ScopedPool() as pool: | 104 with self.gc.ScopedPool() as pool: |
105 # Make sure this pool is interrupted in mid-swing | 105 # Make sure this pool is interrupted in mid-swing |
106 for i in pool.imap(slow_square, xrange(1000000)): | 106 for i in pool.imap(slow_square, xrange(20)): |
107 if i > 32: | 107 if i > 32: |
108 os.kill(os.getpid(), self.CTRL_C) | 108 os.kill(os.getpid(), self.CTRL_C) |
109 result.append(i) | 109 result.append(i) |
110 self.assertEqual([0, 1, 4, 9, 16, 25], result) | 110 self.assertEqual([0, 1, 4, 9, 16, 25], result) |
111 | 111 |
112 | 112 |
113 class ProgressPrinterTest(GitCommonTestBase): | 113 class ProgressPrinterTest(GitCommonTestBase): |
114 class FakeStream(object): | 114 class FakeStream(object): |
115 def __init__(self): | 115 def __init__(self): |
116 self.data = set() | 116 self.data = set() |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 name = 'file%d' % i | 272 name = 'file%d' % i |
273 tree[name] = ('100644', 'blob', self._intern_data(name)) | 273 tree[name] = ('100644', 'blob', self._intern_data(name)) |
274 tree_hash = self.repo.run(self.gc.mktree, tree) | 274 tree_hash = self.repo.run(self.gc.mktree, tree) |
275 self.assertEquals('37b61866d6e061c4ba478e7eb525be7b5752737d', tree_hash) | 275 self.assertEquals('37b61866d6e061c4ba478e7eb525be7b5752737d', tree_hash) |
276 | 276 |
277 | 277 |
278 if __name__ == '__main__': | 278 if __name__ == '__main__': |
279 sys.exit(coverage_utils.covered_main( | 279 sys.exit(coverage_utils.covered_main( |
280 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py') | 280 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py') |
281 )) | 281 )) |
OLD | NEW |