Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Unit tests for owners_finder.py.""" | |
| 7 | |
| 8 import os | |
| 9 import sys | |
| 10 import unittest | |
| 11 | |
| 12 | |
| 13 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| 14 | |
| 15 from testing_support import filesystem_mock | |
| 16 | |
| 17 import owners_finder | |
| 18 import owners | |
| 19 | |
| 20 | |
| 21 ben = 'ben@example.com' | |
| 22 brett = 'brett@example.com' | |
| 23 darin = 'darin@example.com' | |
| 24 john = 'john@example.com' | |
| 25 ken = 'ken@example.com' | |
| 26 peter = 'peter@example.com' | |
| 27 tom = 'tom@example.com' | |
| 28 | |
| 29 | |
| 30 def owners_file(*email_addresses, **kwargs): | |
| 31 s = '' | |
| 32 if kwargs.get('comment'): | |
| 33 s += '# %s\n' % kwargs.get('comment') | |
| 34 if kwargs.get('noparent'): | |
| 35 s += 'set noparent\n' | |
| 36 s += '\n'.join(kwargs.get('lines', [])) + '\n' | |
| 37 return s + '\n'.join(email_addresses) + '\n' | |
| 38 | |
| 39 | |
| 40 def test_repo(): | |
| 41 return filesystem_mock.MockFileSystem(files={ | |
| 42 '/DEPS': '', | |
| 43 '/OWNERS': owners_file(ken, peter, tom), | |
| 44 '/base/vlog.h': '', | |
| 45 '/chrome/OWNERS': owners_file(ben, brett), | |
| 46 '/chrome/browser/OWNERS': owners_file(brett), | |
| 47 '/chrome/browser/defaults.h': '', | |
| 48 '/chrome/gpu/OWNERS': owners_file(ken), | |
| 49 '/chrome/gpu/gpu_channel.h': '', | |
| 50 '/chrome/renderer/OWNERS': owners_file(peter), | |
| 51 '/chrome/renderer/gpu/gpu_channel_host.h': '', | |
| 52 '/chrome/renderer/safe_browsing/scorer.h': '', | |
| 53 '/content/OWNERS': owners_file(john, darin, comment='foo', noparent=True), | |
| 54 '/content/content.gyp': '', | |
| 55 '/content/bar/foo.cc': '', | |
| 56 '/content/baz/OWNERS': owners_file(brett), | |
| 57 '/content/baz/froboz.h': '', | |
| 58 '/content/baz/ugly.cc': '', | |
| 59 '/content/baz/ugly.h': '', | |
| 60 '/content/views/OWNERS': owners_file(ben, john, owners.EVERYONE, | |
| 61 noparent=True), | |
| 62 '/content/views/pie.h': '', | |
| 63 }) | |
| 64 | |
| 65 | |
| 66 class OutputInterceptedOwnersFinder(owners_finder.OwnersFinder): | |
| 67 output = '' | |
| 68 | |
| 69 def resetText(self): | |
| 70 self.output = '' | |
| 71 | |
| 72 def indent(self): | |
| 73 self.output += '{' | |
| 74 | |
| 75 def unindent(self): | |
| 76 self.output += '}' | |
| 77 | |
| 78 def writeln(self, text=''): | |
| 79 self.output += text + '\n' | |
| 80 | |
| 81 | |
| 82 class _BaseTestCase(unittest.TestCase): | |
| 83 default_files = [ | |
| 84 'base/vlog.h', | |
| 85 'chrome/browser/defaults.h', | |
| 86 'chrome/gpu/gpu_channel.h', | |
| 87 'chrome/renderer/gpu/gpu_channel_host.h', | |
| 88 'chrome/renderer/safe_browsing/scorer.h', | |
| 89 'content/content.gyp', | |
| 90 'content/bar/foo.cc', | |
| 91 'content/baz/ugly.cc', | |
| 92 'content/baz/ugly.h', | |
| 93 'content/views/pie.h' | |
| 94 ] | |
| 95 | |
| 96 def setUp(self): | |
| 97 self.repo = test_repo() | |
| 98 self.root = '/' | |
| 99 self.fopen = self.repo.open_for_reading | |
| 100 self.glob = self.repo.glob | |
| 101 | |
| 102 def ownersFinder(self, files): | |
| 103 finder = OutputInterceptedOwnersFinder(files, self.root, | |
| 104 fopen=self.fopen, | |
| 105 os_path=self.repo, | |
| 106 glob=self.glob, | |
| 107 disable_color=True) | |
| 108 return finder | |
| 109 | |
| 110 def defaultFinder(self): | |
| 111 return self.ownersFinder(self.default_files) | |
| 112 | |
| 113 | |
| 114 class OwnersFinderTests(_BaseTestCase): | |
| 115 def test_constructor(self): | |
| 116 self.assertNotEquals(self.defaultFinder(), None) | |
| 117 | |
| 118 def test_reset(self): | |
| 119 finder = self.defaultFinder() | |
| 120 self.assertEquals(finder.owners_queue, | |
| 121 [brett, peter, ken, tom, john, darin, ben]) | |
| 122 self.assertEquals(finder.unreviewed_files, { | |
| 123 'base/vlog.h', | |
| 124 'chrome/browser/defaults.h', | |
| 125 'chrome/gpu/gpu_channel.h', | |
| 126 'chrome/renderer/gpu/gpu_channel_host.h', | |
| 127 'chrome/renderer/safe_browsing/scorer.h', | |
| 128 'content/content.gyp', | |
| 129 'content/bar/foo.cc', | |
| 130 'content/baz/ugly.cc', | |
| 131 'content/baz/ugly.h' | |
| 132 }) | |
| 133 self.assertEquals(finder.selected_owners, set()) | |
|
M-A Ruel
2013/04/24 01:32:20
assertEquals is deprecated, use assertEqual.
Bei Zhang
2013/04/24 03:29:02
Done.
| |
| 134 self.assertEquals(finder.deselected_owners, set()) | |
| 135 self.assertEquals(finder.reviewed_by, {}) | |
| 136 self.assertEquals(finder.output, '') | |
| 137 | |
| 138 def test_select(self): | |
| 139 finder = self.defaultFinder() | |
| 140 finder.select_owner(john) | |
| 141 self.assertEquals(finder.owners_queue, [brett, peter, ken, tom, ben]) | |
| 142 self.assertEquals(finder.selected_owners, {john}) | |
| 143 self.assertEquals(finder.deselected_owners, {darin}) | |
| 144 self.assertEquals(finder.reviewed_by, {'content/bar/foo.cc': john, | |
| 145 'content/baz/ugly.cc': john, | |
| 146 'content/baz/ugly.h': john, | |
| 147 'content/content.gyp': john}) | |
| 148 self.assertEquals(finder.output, | |
| 149 'Selected: john@example.com\n' | |
| 150 'Deselected: darin@example.com\n') | |
| 151 | |
| 152 finder = self.defaultFinder() | |
| 153 finder.select_owner(darin) | |
| 154 self.assertEquals(finder.owners_queue, [brett, peter, ken, tom, ben]) | |
| 155 self.assertEquals(finder.selected_owners, {darin}) | |
| 156 self.assertEquals(finder.deselected_owners, {john}) | |
| 157 self.assertEquals(finder.reviewed_by, {'content/bar/foo.cc': darin, | |
| 158 'content/baz/ugly.cc': darin, | |
| 159 'content/baz/ugly.h': darin, | |
| 160 'content/content.gyp': darin}) | |
| 161 self.assertEquals(finder.output, | |
| 162 'Selected: darin@example.com\n' | |
| 163 'Deselected: john@example.com\n') | |
| 164 | |
| 165 finder = self.defaultFinder() | |
| 166 finder.select_owner(brett) | |
| 167 self.assertEquals(finder.owners_queue, [peter, ken, tom, john, darin]) | |
| 168 self.assertEquals(finder.selected_owners, {brett}) | |
| 169 self.assertEquals(finder.deselected_owners, {ben}) | |
| 170 self.assertEquals(finder.reviewed_by, | |
| 171 {'chrome/browser/defaults.h': brett, | |
| 172 'chrome/gpu/gpu_channel.h': brett, | |
| 173 'chrome/renderer/gpu/gpu_channel_host.h': brett, | |
| 174 'chrome/renderer/safe_browsing/scorer.h': brett, | |
| 175 'content/baz/ugly.cc': brett, | |
| 176 'content/baz/ugly.h': brett}) | |
| 177 self.assertEquals(finder.output, | |
| 178 'Selected: brett@example.com\n' | |
| 179 'Deselected: ben@example.com\n') | |
| 180 | |
| 181 def test_deselect(self): | |
| 182 finder = self.defaultFinder() | |
| 183 finder.deselect_owner(john) | |
| 184 self.assertEquals(finder.owners_queue, [brett, peter, ken, tom, ben]) | |
| 185 self.assertEquals(finder.selected_owners, {darin}) | |
| 186 self.assertEquals(finder.deselected_owners, {john}) | |
| 187 self.assertEquals(finder.reviewed_by, {'content/bar/foo.cc': darin, | |
| 188 'content/baz/ugly.cc': darin, | |
| 189 'content/baz/ugly.h': darin, | |
| 190 'content/content.gyp': darin}) | |
| 191 self.assertEquals(finder.output, | |
| 192 'Deselected: john@example.com\n' | |
| 193 'Selected: darin@example.com\n') | |
| 194 | |
| 195 def test_print_file_info(self): | |
| 196 finder = self.defaultFinder() | |
| 197 finder.print_file_info('chrome/browser/defaults.h') | |
| 198 self.assertEquals(finder.output, '{chrome/browser/defaults.h [5]\n}') | |
| 199 finder.resetText() | |
| 200 | |
| 201 finder.print_file_info('chrome/renderer/gpu/gpu_channel_host.h') | |
| 202 self.assertEquals(finder.output, | |
| 203 '{chrome/renderer/gpu/gpu_channel_host.h [5]\n}') | |
| 204 | |
| 205 def test_print_file_info_detailed(self): | |
| 206 finder = self.defaultFinder() | |
| 207 finder.print_file_info_detailed('chrome/browser/defaults.h') | |
| 208 self.assertEquals(finder.output, | |
| 209 'chrome/browser/defaults.h\n' | |
| 210 '{ben@example.com\n' | |
| 211 'brett@example.com\n' | |
| 212 'ken@example.com\n' | |
| 213 'peter@example.com\n' | |
| 214 'tom@example.com\n}') | |
| 215 finder.resetText() | |
| 216 | |
| 217 finder.print_file_info_detailed('chrome/renderer/gpu/gpu_channel_host.h') | |
| 218 self.assertEquals(finder.output, | |
| 219 'chrome/renderer/gpu/gpu_channel_host.h\n' | |
| 220 '{ben@example.com\n' | |
| 221 'brett@example.com\n' | |
| 222 'ken@example.com\n' | |
| 223 'peter@example.com\n' | |
| 224 'tom@example.com\n}') | |
| 225 | |
| 226 def test_print_comments(self): | |
| 227 finder = self.defaultFinder() | |
| 228 finder.print_comments(darin) | |
| 229 self.assertEquals(finder.output, | |
| 230 'darin@example.com is commented as:\n' | |
| 231 '{foo (at content)\n}') | |
| 232 | |
| 233 | |
| 234 if __name__ == '__main__': | |
| 235 unittest.main() | |
| OLD | NEW |