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

Unified Diff: tools/telemetry/telemetry/telemetry_dependencies_unittest.py

Issue 1057553003: [Telemetry] Add test to prevents adding new dependencies to telemetry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update comment in TELEMETRY_DEPS Created 5 years, 8 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/telemetry/telemetry/TELEMETRY_DEPS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/telemetry_dependencies_unittest.py
diff --git a/tools/telemetry/telemetry/telemetry_dependencies_unittest.py b/tools/telemetry/telemetry/telemetry_dependencies_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..45603b9ff30ea937c8cb1cda8f11f16b6d7afa6d
--- /dev/null
+++ b/tools/telemetry/telemetry/telemetry_dependencies_unittest.py
@@ -0,0 +1,57 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import json
+import os
+import unittest
+
+from telemetry.util import path
+from telemetry.util import find_dependencies
+
+
+_TELEMETRY_DEPS_PATH = os.path.join(
+ path.GetTelemetryDir(), 'telemetry', 'TELEMETRY_DEPS')
+
+
+def _GetCurrentTelemetryDependencies():
+ parser = find_dependencies.FindDependenciesCommand.CreateParser()
+ find_dependencies.FindDependenciesCommand.AddCommandLineArgs(parser, None)
+ options, args = parser.parse_args([''])
+ options.positional_args = args
+ return find_dependencies.FindDependencies([], options=options)
+
+
+def _GetRestrictedTelemetryDeps():
+ with open(_TELEMETRY_DEPS_PATH, 'r') as f:
+ telemetry_deps = json.load(f)
+
+ # Normalize paths in telemetry_deps since TELEMETRY_DEPS file only contain
+ # the relative path in chromium/src/.
+ def NormalizePath(p):
+ p = p.replace('/', os.path.sep)
+ return os.path.realpath(os.path.join(path.GetChromiumSrcDir(), p))
+
+ telemetry_deps['file_deps'] = [
+ NormalizePath(p) for p in telemetry_deps['file_deps']]
+ telemetry_deps['directory_deps'] = [
+ NormalizePath(p) for p in telemetry_deps['directory_deps']]
+ return telemetry_deps
+
+
+class TelemetryDependenciesTest(unittest.TestCase):
+
+ def testNoNewTelemetryDependencies(self):
+ telemetry_deps = _GetRestrictedTelemetryDeps()
+ current_dependencies = _GetCurrentTelemetryDependencies()
+ extra_dep_paths = []
+ for dep_path in current_dependencies:
+ if not (dep_path in telemetry_deps['file_deps'] or
+ any(path.IsSubpath(dep_path, d)
+ for d in telemetry_deps['directory_deps'])):
+ extra_dep_paths.append(dep_path)
+ if extra_dep_paths:
+ self.fail(
+ 'Your patch adds new dependencies to telemetry. Please contact '
+ 'aiolos@,dtu@, or nednguyen@ on how to proceed with this change. '
+ 'Extra dependencies:\n%s' % '\n'.join(extra_dep_paths))
« no previous file with comments | « tools/telemetry/telemetry/TELEMETRY_DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698