Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import unittest | |
| 6 | |
| 7 from telemetry.story import expectations | |
| 8 | |
| 9 | |
| 10 class MockState(object): | |
| 11 | |
| 12 class Platform(object): | |
| 13 def __init__(self): | |
| 14 self._os_name = expectations.TestConditions.WIN | |
| 15 self._battor = False | |
| 16 | |
| 17 def GetOSName(self): | |
| 18 return self._os_name | |
| 19 | |
| 20 def SetOSName(self, os): | |
| 21 self._os_name = os | |
| 22 | |
| 23 def SetBattOrDetected(self, b): | |
| 24 assert isinstance(b, bool) | |
| 25 self._battor = b | |
| 26 | |
| 27 def HasBattOrConnected(self): | |
| 28 return self._battor | |
| 29 | |
| 30 def __init__(self): | |
| 31 self.platform = self.Platform() | |
| 32 | |
|
perezju
2017/05/02 09:19:52
nit: extra blank line here
rnephew (Reviews Here)
2017/05/10 19:45:13
Done.
| |
| 33 class StoryExpectationsTest(unittest.TestCase): | |
| 34 def setUp(self): | |
| 35 self._state = MockState() | |
| 36 | |
| 37 def testInitialization(self): | |
| 38 e = expectations.StoryExpectations() | |
| 39 self.assertTrue(e._frozen) | |
| 40 self.assertDictEqual(e._expectations, {'disabled_platforms': []}) | |
| 41 | |
| 42 def testCantDisableAfterInit(self): | |
| 43 e = expectations.StoryExpectations() | |
| 44 with self.assertRaises(AssertionError): | |
| 45 e.DisableBenchmark(['test'], 'test') | |
| 46 with self.assertRaises(AssertionError): | |
| 47 e.DisableStory('story', ['platform'], 'reason') | |
| 48 | |
| 49 def testDisableBenchmarkOnPlatform(self): | |
| 50 class FooExpectations(expectations.StoryExpectations): | |
| 51 def SetExpectations(self): | |
| 52 self.DisableBenchmark( | |
| 53 [expectations.TestConditions.WIN, | |
| 54 expectations.TestConditions.MAC], | |
| 55 'TEST') | |
|
perezju
2017/05/02 09:19:52
nit: use 'crbug/123' (or something like that) rath
rnephew (Reviews Here)
2017/05/10 19:45:13
Done.
| |
| 56 | |
| 57 e = FooExpectations() | |
| 58 | |
| 59 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
| 60 self.assertTrue(is_disabled) | |
| 61 self.assertEqual(reason, 'TEST') | |
| 62 | |
| 63 self._state.platform.SetOSName(expectations.TestConditions.ANDROID) | |
| 64 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
| 65 self.assertFalse(is_disabled) | |
| 66 self.assertIsNone(reason) | |
| 67 | |
| 68 def testDisabledBenchmarkNoBattOr(self): | |
| 69 class FooExpectations(expectations.StoryExpectations): | |
| 70 def SetExpectations(self): | |
| 71 self.DisableBenchmark( | |
| 72 [expectations.TestConditions.NO_BATTOR], 'BATTOR') | |
| 73 | |
| 74 e = FooExpectations() | |
| 75 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
| 76 self.assertTrue(is_disabled) | |
| 77 self.assertEqual(reason, 'BATTOR') | |
| 78 | |
| 79 self._state.platform.SetBattOrDetected(True) | |
| 80 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
| 81 self.assertFalse(is_disabled) | |
| 82 self.assertIsNone(reason) | |
| 83 | |
| 84 | |
| 85 def testDisableBenchmarkDesktop(self): | |
| 86 class FooExpectations(expectations.StoryExpectations): | |
| 87 def SetExpectations(self): | |
| 88 self.DisableBenchmark( | |
| 89 [expectations.TestConditions.DESKTOP], 'TEST') | |
| 90 | |
| 91 e = FooExpectations() | |
| 92 | |
| 93 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
| 94 self.assertTrue(is_disabled) | |
| 95 self.assertEqual(reason, 'TEST') | |
| 96 | |
| 97 self._state.platform.SetOSName(expectations.TestConditions.ANDROID) | |
| 98 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
| 99 self.assertFalse(is_disabled) | |
| 100 self.assertIsNone(reason) | |
| 101 | |
| 102 def testDisableBenchmarkMobile(self): | |
| 103 class FooExpectations(expectations.StoryExpectations): | |
| 104 def SetExpectations(self): | |
| 105 self.DisableBenchmark( | |
| 106 [expectations.TestConditions.MOBILE], 'TEST') | |
| 107 | |
| 108 e = FooExpectations() | |
| 109 | |
| 110 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
| 111 self.assertFalse(is_disabled) | |
| 112 self.assertIsNone(reason) | |
| 113 | |
| 114 self._state.platform.SetOSName(expectations.TestConditions.ANDROID) | |
| 115 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
| 116 self.assertTrue(is_disabled) | |
| 117 self.assertEqual(reason, 'TEST') | |
| 118 | |
| 119 def testDisableBenchmarkAll(self): | |
| 120 class FooExpectations(expectations.StoryExpectations): | |
| 121 def SetExpectations(self): | |
| 122 self.DisableBenchmark( | |
| 123 [expectations.TestConditions.MAC], 'Mac') | |
| 124 self.DisableBenchmark( | |
| 125 [expectations.TestConditions.ALL], 'ALL') | |
| 126 | |
| 127 e = FooExpectations() | |
| 128 | |
| 129 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
| 130 self.assertTrue(is_disabled) | |
| 131 self.assertEqual(reason, 'ALL') | |
| 132 | |
| 133 def testDisableStoryNoBattOrWithoutBattOr(self): | |
| 134 class FooExpectations(expectations.StoryExpectations): | |
| 135 def SetExpectations(self): | |
| 136 self.DisableStory( | |
| 137 'battor', [expectations.TestConditions.NO_BATTOR], 'TEST') | |
| 138 | |
| 139 e = FooExpectations() | |
| 140 | |
| 141 self._state.platform.SetBattOrDetected(False) | |
| 142 is_disabled, reason = e.IsStoryDisabled('battor', self._state) | |
| 143 self.assertTrue(is_disabled) | |
| 144 self.assertEqual(reason, 'TEST') | |
| 145 | |
| 146 def testDisableStoryNoBattOrWithBattOr(self): | |
| 147 class FooExpectations(expectations.StoryExpectations): | |
| 148 def SetExpectations(self): | |
| 149 self.DisableStory( | |
| 150 'battor', [expectations.TestConditions.NO_BATTOR], 'TEST') | |
| 151 | |
| 152 e = FooExpectations() | |
| 153 | |
| 154 self._state.platform.SetBattOrDetected(True) | |
| 155 is_disabled, reason = e.IsStoryDisabled('battor', self._state) | |
| 156 self.assertFalse(is_disabled) | |
| 157 self.assertIsNone(reason) | |
| 158 | |
| 159 def testDisableStoryMultiplePlatforms(self): | |
| 160 class FooExpectations(expectations.StoryExpectations): | |
| 161 def SetExpectations(self): | |
| 162 self.DisableStory( | |
| 163 'multi-platform', [expectations.TestConditions.WIN], 'TESTa') | |
| 164 self.DisableStory( | |
| 165 'multi-platform', [expectations.TestConditions.MAC], 'TESTb') | |
| 166 | |
| 167 e = FooExpectations() | |
| 168 | |
| 169 self._state.platform.SetOSName(expectations.TestConditions.MAC) | |
| 170 is_disabled, reason = e.IsStoryDisabled('multi-platform', self._state) | |
| 171 self.assertTrue(is_disabled) | |
| 172 self.assertEqual(reason, 'TESTb') | |
| 173 | |
| 174 self._state.platform.SetOSName(expectations.TestConditions.WIN) | |
| 175 is_disabled, reason = e.IsStoryDisabled('multi-platform', self._state) | |
| 176 self.assertTrue(is_disabled) | |
| 177 self.assertEqual(reason, 'TESTa') | |
| 178 | |
| 179 self._state.platform.SetOSName(expectations.TestConditions.ANDROID) | |
| 180 is_disabled, reason = e.IsStoryDisabled('multi-platform', self._state) | |
| 181 self.assertFalse(is_disabled) | |
| 182 self.assertIsNone(reason) | |
| 183 | |
| 184 def testDisableStoryAllPlatforms(self): | |
| 185 class FooExpectations(expectations.StoryExpectations): | |
| 186 def SetExpectations(self): | |
| 187 self.DisableStory( | |
| 188 'disable-all', [expectations.TestConditions.ALL], 'TEST') | |
| 189 | |
| 190 e = FooExpectations() | |
| 191 | |
| 192 self._state.platform.SetOSName(expectations.TestConditions.WIN) | |
| 193 is_disabled, reason = e.IsStoryDisabled('disable-all', self._state) | |
| 194 self.assertTrue(is_disabled) | |
| 195 self.assertEqual(reason, 'TEST') | |
| 196 | |
| 197 self._state.platform.SetOSName(expectations.TestConditions.MAC) | |
| 198 is_disabled, reason = e.IsStoryDisabled('disable-all', self._state) | |
| 199 self.assertTrue(is_disabled) | |
| 200 self.assertEqual(reason, 'TEST') | |
| 201 | |
| 202 self._state.platform.SetOSName(expectations.TestConditions.ANDROID) | |
| 203 is_disabled, reason = e.IsStoryDisabled('disable-all', self._state) | |
| 204 self.assertTrue(is_disabled) | |
| 205 self.assertEqual(reason, 'TEST') | |
| 206 | |
| 207 self._state.platform.SetOSName('JUNK_PLATFORM_NAME') | |
| 208 is_disabled, reason = e.IsStoryDisabled('disable-all', self._state) | |
| 209 self.assertTrue(is_disabled) | |
| 210 self.assertEqual(reason, 'TEST') | |
| 211 | |
| 212 def testDisableStoryOnePlatform(self): | |
| 213 class FooExpectations(expectations.StoryExpectations): | |
| 214 def SetExpectations(self): | |
| 215 self.DisableStory( | |
| 216 'disable-win', [expectations.TestConditions.WIN], 'TEST') | |
| 217 | |
| 218 e = FooExpectations() | |
| 219 | |
| 220 # Test disabling on one platform. | |
| 221 self._state.platform.SetOSName(expectations.TestConditions.WIN) | |
| 222 is_disabled, reason = e.IsStoryDisabled('disable-win', self._state) | |
| 223 self.assertTrue(is_disabled) | |
| 224 self.assertEqual(reason, 'TEST') | |
| 225 self._state.platform.SetOSName(expectations.TestConditions.MAC) | |
| 226 is_disabled, reason = e.IsStoryDisabled('disbled-win', self._state) | |
| 227 self.assertFalse(is_disabled) | |
| 228 self.assertIsNone(reason) | |
| 229 | |
| 230 def testDisableStoryDesktop(self): | |
| 231 class FooExpectations(expectations.StoryExpectations): | |
| 232 def SetExpectations(self): | |
| 233 self.DisableStory( | |
| 234 'disable-desktop', [expectations.TestConditions.DESKTOP], 'TEST') | |
| 235 | |
| 236 e = FooExpectations() | |
| 237 | |
| 238 self._state.platform.SetOSName(expectations.TestConditions.WIN) | |
| 239 is_disabled, reason = e.IsStoryDisabled('disable-desktop', self._state) | |
| 240 self.assertTrue(is_disabled) | |
| 241 self.assertEqual(reason, 'TEST') | |
| 242 self._state.platform.SetOSName(expectations.TestConditions.ANDROID) | |
| 243 is_disabled, reason = e.IsStoryDisabled('disable-desktop', self._state) | |
| 244 self.assertFalse(is_disabled) | |
| 245 self.assertIsNone(reason) | |
| 246 | |
| 247 def testDisableStoryMobile(self): | |
| 248 class FooExpectations(expectations.StoryExpectations): | |
| 249 def SetExpectations(self): | |
| 250 self.DisableStory( | |
| 251 'disable-mobile', [expectations.TestConditions.MOBILE], 'TEST') | |
| 252 | |
| 253 e = FooExpectations() | |
| 254 | |
| 255 # Test disabling on mobile platforms. | |
| 256 self._state.platform.SetOSName(expectations.TestConditions.ANDROID) | |
| 257 is_disabled, reason = e.IsStoryDisabled('disable-mobile', self._state) | |
| 258 self.assertTrue(is_disabled) | |
| 259 self.assertEqual(reason, 'TEST') | |
| 260 self._state.platform.SetOSName(expectations.TestConditions.LINUX) | |
| 261 is_disabled, reason = e.IsStoryDisabled('disable-mobile', self._state) | |
| 262 self.assertFalse(is_disabled) | |
| 263 self.assertIsNone(reason) | |
| OLD | NEW |