Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: tools/checkteamtags/extract_components_test.py

Issue 2738123003: Add an option to include all subdirs into output (Closed)
Patch Set: Better name for a function Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/checkteamtags/extract_components.py ('k') | tools/checkteamtags/owners_file_tags.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/checkteamtags/extract_components_test.py
diff --git a/tools/checkteamtags/extract_components_test.py b/tools/checkteamtags/extract_components_test.py
index 0f99f4eab149c7239e9f586ebf26250f41c66e7f..b4fff062bfff88130963dcf5c60015ff4347531b 100644
--- a/tools/checkteamtags/extract_components_test.py
+++ b/tools/checkteamtags/extract_components_test.py
@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+from collections import OrderedDict
import json
import os
import sys
@@ -20,8 +21,11 @@ def mock_file_tree(tree):
os_walk_mocks = []
file_mocks = {}
for path in tree:
- os_walk_mocks.append((path, ('ignored'), ('OWNERS', 'dummy.cc')))
- file_mocks[os.path.join(path, 'OWNERS')] = tree[path]
+ if tree[path] is not None:
+ os_walk_mocks.append((path, ('ignored'), ('OWNERS', 'dummy.cc')))
+ file_mocks[os.path.join(path, 'OWNERS')] = tree[path]
+ else:
+ os_walk_mocks.append((path, ('ignored'), ('dummy.cc')))
def custom_mock_open(files_data):
def inner_open(path, mode='r'):
@@ -162,3 +166,35 @@ class ExtractComponentsTest(unittest.TestCase):
self.assertIn('3 (75.00%) OWNERS files have COMPONENT', output)
self.assertIn('2 (50.00%) OWNERS files have TEAM and COMPONENT', output)
self.assertIn('4 OWNERS files at depth 0', output)
+
+ # We use OrderedDict here to guarantee that mocked version of os.walk returns
+ # directories in the specified order (top-down).
+ @mock_file_tree(OrderedDict([
+ ('chromium/src', 'boss@chromium.org\n'),
+ ('chromium/src/dir1', 'dummy@chromium.org\n'
+ '# TEAM: dummy-team@chromium.org\n'
+ '# COMPONENT: Dummy>Component'),
+ ('chromium/src/dir2', 'dummy2@chromium.org\n'
+ '# TEAM: other-dummy-team@chromium.org\n'
+ '# COMPONENT: Dummy>Component2'),
+ ('chromium/src/dir1/subdir', 'dummy@chromium.org'),
+ ('chromium/src/dir2/subdir', None)]))
+ def testIncludesSubdirectoriesWithNoOwnersFileOrNoComponentTag(self):
+ self.maxDiff = None # This helps to see assertDictEqual errors in full.
+ saved_output = StringIO()
+ with mock.patch('sys.stdout', saved_output):
+ error_code = extract_components.main(['%prog', '--include-subdirs'])
+ self.assertEqual(0, error_code)
+ result_minus_readme = json.loads(saved_output.getvalue())
+ del result_minus_readme['AAA-README']
+ self.assertDictEqual(result_minus_readme, {
+ u'component-to-team': {
+ u'Dummy>Component2': u'other-dummy-team@chromium.org',
+ u'Dummy>Component': u'dummy-team@chromium.org'
+ },
+ u'dir-to-component': {
+ u'tools/checkteamtags/chromium/src/dir1': u'Dummy>Component',
+ u'tools/checkteamtags/chromium/src/dir1/subdir': u'Dummy>Component',
+ u'tools/checkteamtags/chromium/src/dir2': u'Dummy>Component2',
+ u'tools/checkteamtags/chromium/src/dir2/subdir': u'Dummy>Component2'
+ }})
« no previous file with comments | « tools/checkteamtags/extract_components.py ('k') | tools/checkteamtags/owners_file_tags.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698