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

Unified Diff: tools/telemetry/telemetry/page/page_set_expectations.py

Issue 16158006: Defining the test expectations object (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added expectations integration Created 7 years, 5 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
Index: tools/telemetry/telemetry/page/page_set_expectations.py
diff --git a/tools/telemetry/telemetry/page/page_set_expectations.py b/tools/telemetry/telemetry/page/page_set_expectations.py
new file mode 100644
index 0000000000000000000000000000000000000000..e83ac971f7235d87ef123bee1e77ddc7d4e5ddd7
--- /dev/null
+++ b/tools/telemetry/telemetry/page/page_set_expectations.py
@@ -0,0 +1,86 @@
+# Copyright (c) 2013 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 fnmatch
+
+OS_MODIFIERS = ['win', 'xp', 'vista', 'win7',
+ 'mac', 'leopard', 'snowleopard', 'lion', 'mountainlion',
+ 'linux', 'chromeos']
+GPU_MODIFIERS = ['nvidia', 'amd', 'intel']
+CONFIG_MODIFIERS = ['debug', 'release']
+
+class TestExpectation(object):
+ def __init__(self, bug, modifiers, name, expectation):
dtu 2013/07/16 09:50:49 "url_pattern" instead of "name". Same with "url" b
+ self.bug = bug
+ self.name = name
+ self.expectation = expectation
+
+ self.os_modifiers = []
+ self.gpu_modifiers = []
+ self.config_modifiers = []
+
+ # Make sure that non-absolute paths are searchable
+ if not "://" in self.name:
dtu 2013/07/16 09:50:49 Single quotes for all strings.
+ self.name = "*/" + self.name
+
+ if modifiers:
dtu 2013/07/16 09:50:49 Make the argument explicitly optional in the param
+ for m in modifiers:
+ mod = m.lower()
+ if mod in OS_MODIFIERS:
+ self.os_modifiers.append(mod)
+ elif mod in GPU_MODIFIERS:
+ self.gpu_modifiers.append(mod)
+ elif mod in CONFIG_MODIFIERS:
+ self.config_modifiers.append(mod)
dtu 2013/07/16 09:50:49 else raise ValueError
+
+ @classmethod
+ def FromDict(cls, url, data):
+ bug = data.get('bug')
+ modifiers = data.get('modifiers')
+ expect = data.get('expect')
+ expectation = cls(bug, modifiers, url, expect)
+ return expectation
+
+class PageSetExpectations(object):
dtu 2013/07/16 09:50:49 TestExpectations
+ """A class which defines the expectations for a page set test execution"""
+
+ def __init__(self):
+ self.expectations = []
+
+ def Pass(self, bug, modifiers, name):
dtu 2013/07/16 09:50:49 I'm okay with this being extensible and not just a
+ self.Expect(bug, modifiers, name, "pass")
+
+ def Fail(self, bug, modifiers, name):
+ self.Expect(bug, modifiers, name, "fail")
+
+ def Skip(self, bug, modifiers, name):
+ self.Expect(bug, modifiers, name, "skip")
+
+ def Expect(self, bug, modifiers, name, expectation):
dtu 2013/07/16 09:50:49 I don't want to allow arbitrary expectation string
+ self.AddExpectation(TestExpectation(bug, modifiers, name,
+ expectation.lower()))
+
+ def AddExpectation(self, test_expectation):
+ self.expectations.append(test_expectation)
+
+ def GetExpectationForPage(self, platform, page):
+ for e in self.expectations:
+ if fnmatch.fnmatch(page.url, e.name):
+ if self._ModifiersApply(platform, e):
+ return e.expectation
+ return "pass"
+
+ def _ModifiersApply(self, platform, expectation):
+ """Determines if the modifiers for an expectation apply to this system."""
+
+ if not expectation:
dtu 2013/07/16 09:50:49 Disallow calling this method with no expectation a
+ return False
+
+ os_matches = (len(expectation.os_modifiers) == 0 or
+ platform.GetOSName() in expectation.os_modifiers or
+ platform.GetOSVersionName() in expectation.os_modifiers)
+
+ # TODO: Add checks against other modifiers (GPU, configuration, etc.)
+
+ return os_matches

Powered by Google App Engine
This is Rietveld 408576698