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

Unified Diff: telemetry/telemetry/story/expectations_unittest.py

Issue 2843403005: [Telemetry] Add Expectation module that enables disabling benchmarks/stories (Closed)
Patch Set: 30 -> 50 Created 3 years, 7 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: telemetry/telemetry/story/expectations_unittest.py
diff --git a/telemetry/telemetry/story/expectations_unittest.py b/telemetry/telemetry/story/expectations_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..25b658ea7b13df6a5c6dce692acd07138aa38bfb
--- /dev/null
+++ b/telemetry/telemetry/story/expectations_unittest.py
@@ -0,0 +1,160 @@
+# Copyright 2017 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 unittest
+
+from telemetry.story import expectations
+from telemetry.testing import fakes
+
+
+class MockState(object):
+ def __init__(self):
+ self.platform = fakes.FakePlatform()
+
+
+class MockStory(object):
+ def __init__(self, name):
+ self._name = name
+
+ @property
+ def display_name(self):
+ return self._name
+
+
+class TestConditionTest(unittest.TestCase):
+ def testAll(self):
+ p = fakes.FakePlatform()
+ self.assertTrue(expectations.ALL.ShouldDisable(p))
+
+ def testAllWin(self):
charliea (OOO until 10-5) 2017/05/15 21:15:42 nit: I think you should actually split most of the
rnephew (Reviews Here) 2017/05/15 21:36:06 Done.
+ p = fakes.FakePlatform()
+ p.SetOSName('win')
+ self.assertTrue(expectations.ALL_WIN.ShouldDisable(p))
charliea (OOO until 10-5) 2017/05/15 21:15:42 Rather than asserting true, I think you should ass
rnephew (Reviews Here) 2017/05/15 21:36:07 Thats part of the StoryExpectation, not part of th
charliea (OOO until 10-5) 2017/05/16 16:09:27 Ah, okay, sorry about that. Thanks!
+ p.SetOSName('not_windows')
+ self.assertFalse(expectations.ALL_WIN.ShouldDisable(p))
+
+ def testAllLinux(self):
+ p = fakes.FakePlatform()
+ p.SetOSName('linux')
+ self.assertTrue(expectations.ALL_LINUX.ShouldDisable(p))
+ p.SetOSName('not_linux')
+ self.assertFalse(expectations.ALL_LINUX.ShouldDisable(p))
+
+ def testAllMac(self):
+ p = fakes.FakePlatform()
+ p.SetOSName('mac')
+ self.assertTrue(expectations.ALL_MAC.ShouldDisable(p))
+ p.SetOSName('not_mac')
+ self.assertFalse(expectations.ALL_MAC.ShouldDisable(p))
+
+ def testAllAndroid(self):
+ p = fakes.FakePlatform()
+ p.SetOSName('android')
+ self.assertTrue(expectations.ALL_ANDROID.ShouldDisable(p))
+ p.SetOSName('not_android')
+ self.assertFalse(expectations.ALL_ANDROID.ShouldDisable(p))
+
+ def testAllDesktop(self):
+ true_platforms = ['win', 'mac', 'linux']
+ false_platforms = ['android']
+ p = fakes.FakePlatform()
+
+ for plat in true_platforms:
+ p.SetOSName(plat)
+ self.assertTrue(expectations.ALL_DESKTOP.ShouldDisable(p))
+ for plat in false_platforms:
+ p.SetOSName(plat)
+ self.assertFalse(expectations.ALL_DESKTOP.ShouldDisable(p))
+
+ def testAllMobile(self):
+ false_platforms = ['win', 'mac', 'linux']
+ true_platforms = ['android']
+ p = fakes.FakePlatform()
+
+ for plat in true_platforms:
+ p.SetOSName(plat)
+ self.assertTrue(expectations.ALL_MOBILE.ShouldDisable(p))
+ for plat in false_platforms:
+ p.SetOSName(plat)
+ self.assertFalse(expectations.ALL_MOBILE.ShouldDisable(p))
+
+ def testNoBattOr(self):
+ p = fakes.FakePlatform()
+ p.SetBattOrDetected(False)
+ self.assertTrue(expectations.NO_BATTOR.ShouldDisable(p))
+ p.SetBattOrDetected(True)
+ self.assertFalse(expectations.ALL_WIN.ShouldDisable(p))
+
+
+class StoryExpectationsTest(unittest.TestCase):
+ def setUp(self):
+ self.platform = fakes.FakePlatform()
+
+ def testCantDisableAfterInit(self):
+ e = expectations.StoryExpectations()
+ with self.assertRaises(AssertionError):
+ e.DisableBenchmark(['test'], 'test')
+ with self.assertRaises(AssertionError):
+ e.DisableStory('story', ['platform'], 'reason')
+
+ def testDisableBenchmark(self):
+ class FooExpectations(expectations.StoryExpectations):
+ def SetExpectations(self):
+ self.DisableBenchmark([expectations.ALL_WIN], 'crbug.com/123')
+
+ e = FooExpectations()
+ self.platform.SetOSName('win')
+
+ reason = e.IsBenchmarkDisabled(self.platform)
+ self.assertTrue(reason)
+ self.assertEqual(reason, 'crbug.com/123')
+
+ self.platform.SetOSName('android')
+ reason = e.IsBenchmarkDisabled(self.platform)
+ self.assertIsNone(reason)
+
+ def testDisableStoryMultipleConditions(self):
+ class FooExpectations(expectations.StoryExpectations):
+ def SetExpectations(self):
+ self.DisableStory(
+ 'multi', [expectations.ALL_WIN], 'crbug.com/123')
+ self.DisableStory(
+ 'multi', [expectations.ALL_MAC], 'crbug.com/456')
+
+ e = FooExpectations()
+
+ self.platform.SetOSName('mac')
+ reason = e.IsStoryDisabled(
+ MockStory('multi'), self.platform)
+ self.assertTrue(reason)
+ self.assertEqual(reason, 'crbug.com/456')
+
+ def testDisableStoryOneCondition(self):
+ class FooExpectations(expectations.StoryExpectations):
+ def SetExpectations(self):
+ self.DisableStory(
+ 'disable', [expectations.ALL_WIN], 'crbug.com/123')
+
+ e = FooExpectations()
+
+ self.platform.SetOSName('win')
+ reason = e.IsStoryDisabled(
+ MockStory('disable'), self.platform)
+ self.assertTrue(reason)
charliea (OOO until 10-5) 2017/05/15 21:15:42 (here and elsewhere in this file where you assert
rnephew (Reviews Here) 2017/05/15 21:36:06 Done.
+ self.assertEqual(reason, 'crbug.com/123')
+ self.platform.SetOSName('mac')
+ reason = e.IsStoryDisabled(
+ MockStory('disbled'), self.platform)
charliea (OOO until 10-5) 2017/05/15 21:15:42 nit: disabled?
rnephew (Reviews Here) 2017/05/15 21:36:06 Done.
+ self.assertFalse(reason)
+ self.assertIsNone(reason)
+
+ def testDisableStoryWithLongName(self):
+ class FooExpectations(expectations.StoryExpectations):
+ def SetExpectations(self):
+ self.DisableStory(
+ '123456789012345678901234567890123456789012345678901',
+ [expectations.ALL], 'Too Long')
+
+ with self.assertRaises(AssertionError):
+ FooExpectations()

Powered by Google App Engine
This is Rietveld 408576698