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 owners_finder.py.""" | 6 """Unit tests for owners_finder.py.""" |
7 | 7 |
8 import os | 8 import os |
9 import sys | 9 import sys |
10 import unittest | 10 import unittest |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 '/content/baz/ugly.cc': '', | 58 '/content/baz/ugly.cc': '', |
59 '/content/baz/ugly.h': '', | 59 '/content/baz/ugly.h': '', |
60 '/content/views/OWNERS': owners_file(ben, john, owners.EVERYONE, | 60 '/content/views/OWNERS': owners_file(ben, john, owners.EVERYONE, |
61 noparent=True), | 61 noparent=True), |
62 '/content/views/pie.h': '', | 62 '/content/views/pie.h': '', |
63 }) | 63 }) |
64 | 64 |
65 | 65 |
66 class OutputInterceptedOwnersFinder(owners_finder.OwnersFinder): | 66 class OutputInterceptedOwnersFinder(owners_finder.OwnersFinder): |
67 def __init__(self, files, local_root, | 67 def __init__(self, files, local_root, |
68 fopen, os_path, glob, | 68 fopen, os_path, disable_color=False): |
69 disable_color=False): | |
70 super(OutputInterceptedOwnersFinder, self).__init__( | 69 super(OutputInterceptedOwnersFinder, self).__init__( |
71 files, local_root, None, | 70 files, local_root, None, |
72 fopen, os_path, glob, disable_color=disable_color) | 71 fopen, os_path, disable_color=disable_color) |
73 self.output = [] | 72 self.output = [] |
74 self.indentation_stack = [] | 73 self.indentation_stack = [] |
75 | 74 |
76 def resetText(self): | 75 def resetText(self): |
77 self.output = [] | 76 self.output = [] |
78 self.indentation_stack = [] | 77 self.indentation_stack = [] |
79 | 78 |
80 def indent(self): | 79 def indent(self): |
81 self.indentation_stack.append(self.output) | 80 self.indentation_stack.append(self.output) |
82 self.output = [] | 81 self.output = [] |
(...skipping 18 matching lines...) Expand all Loading... |
101 'content/bar/foo.cc', | 100 'content/bar/foo.cc', |
102 'content/baz/ugly.cc', | 101 'content/baz/ugly.cc', |
103 'content/baz/ugly.h', | 102 'content/baz/ugly.h', |
104 'content/views/pie.h' | 103 'content/views/pie.h' |
105 ] | 104 ] |
106 | 105 |
107 def setUp(self): | 106 def setUp(self): |
108 self.repo = test_repo() | 107 self.repo = test_repo() |
109 self.root = '/' | 108 self.root = '/' |
110 self.fopen = self.repo.open_for_reading | 109 self.fopen = self.repo.open_for_reading |
111 self.glob = self.repo.glob | |
112 | 110 |
113 def ownersFinder(self, files): | 111 def ownersFinder(self, files): |
114 finder = OutputInterceptedOwnersFinder(files, self.root, | 112 finder = OutputInterceptedOwnersFinder(files, self.root, |
115 fopen=self.fopen, | 113 fopen=self.fopen, |
116 os_path=self.repo, | 114 os_path=self.repo, |
117 glob=self.glob, | |
118 disable_color=True) | 115 disable_color=True) |
119 return finder | 116 return finder |
120 | 117 |
121 def defaultFinder(self): | 118 def defaultFinder(self): |
122 return self.ownersFinder(self.default_files) | 119 return self.ownersFinder(self.default_files) |
123 | 120 |
124 | 121 |
125 class OwnersFinderTests(_BaseTestCase): | 122 class OwnersFinderTests(_BaseTestCase): |
126 def test_constructor(self): | 123 def test_constructor(self): |
127 self.assertNotEquals(self.defaultFinder(), None) | 124 self.assertNotEquals(self.defaultFinder(), None) |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 228 |
232 def test_print_comments(self): | 229 def test_print_comments(self): |
233 finder = self.defaultFinder() | 230 finder = self.defaultFinder() |
234 finder.print_comments(darin) | 231 finder.print_comments(darin) |
235 self.assertEqual(finder.output, | 232 self.assertEqual(finder.output, |
236 [darin + ' is commented as:', ['foo (at content)']]) | 233 [darin + ' is commented as:', ['foo (at content)']]) |
237 | 234 |
238 | 235 |
239 if __name__ == '__main__': | 236 if __name__ == '__main__': |
240 unittest.main() | 237 unittest.main() |
OLD | NEW |