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): | |
nednguyen
2017/05/10 21:07:58
You can use https://github.com/catapult-project/ca
rnephew (Reviews Here)
2017/05/10 21:58:47
Done.
| |
13 def __init__(self): | |
14 self._os_name = '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 | |
33 | |
34 class MockStory(object): | |
35 def __init__(self, name): | |
36 self._name = name | |
37 | |
38 @property | |
39 def display_name(self): | |
40 return self._name | |
41 | |
42 | |
43 class StoryExpectationsTest(unittest.TestCase): | |
44 def setUp(self): | |
45 self._state = MockState() | |
46 | |
47 def testInitialization(self): | |
48 e = expectations.StoryExpectations() | |
49 self.assertTrue(e._frozen) | |
50 self.assertFalse(e._expectations, {}) | |
51 self.assertFalse(e._disabled_platforms) | |
52 | |
53 def testCantDisableAfterInit(self): | |
54 e = expectations.StoryExpectations() | |
55 with self.assertRaises(AssertionError): | |
56 e.DisableBenchmark(['test'], 'test') | |
57 with self.assertRaises(AssertionError): | |
58 e.DisableStory('story', ['platform'], 'reason') | |
59 | |
60 def testDisableBenchmarkOnPlatform(self): | |
61 class FooExpectations(expectations.StoryExpectations): | |
62 def SetExpectations(self): | |
63 self.DisableBenchmark( | |
64 [expectations.ALL_WIN, | |
65 expectations.ALL_MAC], | |
66 'crbug/123') | |
67 | |
68 e = FooExpectations() | |
69 | |
70 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
71 self.assertTrue(is_disabled) | |
72 self.assertEqual(reason, 'crbug/123') | |
73 | |
74 self._state.platform.SetOSName('android') | |
75 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
76 self.assertFalse(is_disabled) | |
77 self.assertIsNone(reason) | |
78 | |
79 def testDisabledBenchmarkNoBattOr(self): | |
80 class FooExpectations(expectations.StoryExpectations): | |
81 def SetExpectations(self): | |
82 self.DisableBenchmark( | |
83 [expectations.NO_BATTOR], 'BATTOR') | |
84 | |
85 e = FooExpectations() | |
86 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
87 self.assertTrue(is_disabled) | |
88 self.assertEqual(reason, 'BATTOR') | |
89 | |
90 self._state.platform.SetBattOrDetected(True) | |
91 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
92 self.assertFalse(is_disabled) | |
93 self.assertIsNone(reason) | |
94 | |
95 | |
96 def testDisableBenchmarkDesktop(self): | |
97 class FooExpectations(expectations.StoryExpectations): | |
98 def SetExpectations(self): | |
99 self.DisableBenchmark( | |
100 [expectations.ALL_DESKTOP], 'crbug/123') | |
101 | |
102 e = FooExpectations() | |
103 | |
104 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
105 self.assertTrue(is_disabled) | |
106 self.assertEqual(reason, 'crbug/123') | |
107 | |
108 self._state.platform.SetOSName('android') | |
109 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
110 self.assertFalse(is_disabled) | |
111 self.assertIsNone(reason) | |
112 | |
113 def testDisableBenchmarkMobile(self): | |
114 class FooExpectations(expectations.StoryExpectations): | |
115 def SetExpectations(self): | |
116 self.DisableBenchmark( | |
117 [expectations.ALL_MOBILE], 'crbug/123') | |
118 | |
119 e = FooExpectations() | |
120 | |
121 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
122 self.assertFalse(is_disabled) | |
123 self.assertIsNone(reason) | |
124 | |
125 self._state.platform.SetOSName('android') | |
126 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
127 self.assertTrue(is_disabled) | |
128 self.assertEqual(reason, 'crbug/123') | |
129 | |
130 def testDisableBenchmarkAll(self): | |
131 class FooExpectations(expectations.StoryExpectations): | |
132 def SetExpectations(self): | |
133 self.DisableBenchmark( | |
134 [expectations.ALL_MAC], 'Mac') | |
135 self.DisableBenchmark( | |
136 [expectations.ALL], 'ALL') | |
137 | |
138 e = FooExpectations() | |
139 | |
140 is_disabled, reason = e.IsBenchmarkDisabled(self._state) | |
141 self.assertTrue(is_disabled) | |
142 self.assertEqual(reason, 'ALL') | |
143 | |
144 def testDisableStoryNoBattOrWithoutBattOr(self): | |
145 class FooExpectations(expectations.StoryExpectations): | |
146 def SetExpectations(self): | |
147 self.DisableStory( | |
148 'battor', [expectations.NO_BATTOR], 'crbug/123') | |
149 | |
150 e = FooExpectations() | |
151 | |
152 self._state.platform.SetBattOrDetected(False) | |
153 is_disabled, reason = e.IsStoryDisabled(MockStory('battor'), self._state) | |
154 self.assertTrue(is_disabled) | |
155 self.assertEqual(reason, 'crbug/123') | |
156 | |
157 def testDisableStoryNoBattOrWithBattOr(self): | |
158 class FooExpectations(expectations.StoryExpectations): | |
159 def SetExpectations(self): | |
160 self.DisableStory( | |
161 'battor', [expectations.NO_BATTOR], 'crbug/123') | |
162 | |
163 e = FooExpectations() | |
164 | |
165 self._state.platform.SetBattOrDetected(True) | |
166 is_disabled, reason = e.IsStoryDisabled(MockStory('battor'), self._state) | |
167 self.assertFalse(is_disabled) | |
168 self.assertIsNone(reason) | |
169 | |
170 def testDisableStoryMultiplePlatforms(self): | |
171 class FooExpectations(expectations.StoryExpectations): | |
172 def SetExpectations(self): | |
173 self.DisableStory( | |
174 'multi', [expectations.ALL_WIN], 'crbug/123') | |
175 self.DisableStory( | |
176 'multi', [expectations.ALL_MAC], 'crbug/456') | |
177 | |
178 e = FooExpectations() | |
179 | |
180 self._state.platform.SetOSName('mac') | |
181 is_disabled, reason = e.IsStoryDisabled(MockStory('multi'), self._state) | |
182 self.assertTrue(is_disabled) | |
183 self.assertEqual(reason, 'crbug/456') | |
184 | |
185 self._state.platform.SetOSName('win') | |
186 is_disabled, reason = e.IsStoryDisabled(MockStory('multi'), self._state) | |
187 self.assertTrue(is_disabled) | |
188 self.assertEqual(reason, 'crbug/123') | |
189 | |
190 self._state.platform.SetOSName('android') | |
191 is_disabled, reason = e.IsStoryDisabled(MockStory('multi'), self._state) | |
192 self.assertFalse(is_disabled) | |
193 self.assertIsNone(reason) | |
194 | |
195 def testDisableStoryAllPlatforms(self): | |
196 class FooExpectations(expectations.StoryExpectations): | |
197 def SetExpectations(self): | |
198 self.DisableStory('all', [expectations.ALL], 'crbug/123') | |
199 | |
200 e = FooExpectations() | |
201 | |
202 self._state.platform.SetOSName('win') | |
203 is_disabled, reason = e.IsStoryDisabled(MockStory('all'), self._state) | |
204 self.assertTrue(is_disabled) | |
205 self.assertEqual(reason, 'crbug/123') | |
206 | |
207 self._state.platform.SetOSName('mac') | |
208 is_disabled, reason = e.IsStoryDisabled(MockStory('all'), self._state) | |
209 self.assertTrue(is_disabled) | |
210 self.assertEqual(reason, 'crbug/123') | |
211 | |
212 self._state.platform.SetOSName('android') | |
213 is_disabled, reason = e.IsStoryDisabled(MockStory('all'), self._state) | |
214 self.assertTrue(is_disabled) | |
215 self.assertEqual(reason, 'crbug/123') | |
216 | |
217 self._state.platform.SetOSName('JUNK_PLATFORM_NAME') | |
218 is_disabled, reason = e.IsStoryDisabled(MockStory('all'), self._state) | |
219 self.assertTrue(is_disabled) | |
220 self.assertEqual(reason, 'crbug/123') | |
221 | |
222 def testDisableStoryOnePlatform(self): | |
223 class FooExpectations(expectations.StoryExpectations): | |
224 def SetExpectations(self): | |
225 self.DisableStory( | |
226 'disable', [expectations.ALL_WIN], 'crbug/123') | |
227 | |
228 e = FooExpectations() | |
229 | |
230 # Test disabling on one platform. | |
231 self._state.platform.SetOSName('win') | |
232 is_disabled, reason = e.IsStoryDisabled(MockStory('disable'), self._state) | |
233 self.assertTrue(is_disabled) | |
234 self.assertEqual(reason, 'crbug/123') | |
235 self._state.platform.SetOSName('mac') | |
236 is_disabled, reason = e.IsStoryDisabled(MockStory('disbled'), self._state) | |
237 self.assertFalse(is_disabled) | |
238 self.assertIsNone(reason) | |
239 | |
240 def testDisableStoryDesktop(self): | |
241 class FooExpectations(expectations.StoryExpectations): | |
242 def SetExpectations(self): | |
243 self.DisableStory( | |
244 'desktop', [expectations.ALL_DESKTOP], 'crbug/123') | |
245 | |
246 e = FooExpectations() | |
247 | |
248 self._state.platform.SetOSName('win') | |
249 is_disabled, reason = e.IsStoryDisabled(MockStory('desktop'), self._state) | |
250 self.assertTrue(is_disabled) | |
251 self.assertEqual(reason, 'crbug/123') | |
252 self._state.platform.SetOSName('android') | |
253 is_disabled, reason = e.IsStoryDisabled(MockStory('desktop'), self._state) | |
254 self.assertFalse(is_disabled) | |
255 self.assertIsNone(reason) | |
256 | |
257 def testDisableStoryMobile(self): | |
258 class FooExpectations(expectations.StoryExpectations): | |
259 def SetExpectations(self): | |
260 self.DisableStory( | |
261 'mobile', [expectations.ALL_MOBILE], 'crbug/123') | |
262 | |
263 e = FooExpectations() | |
264 | |
265 # Test disabling on mobile platforms. | |
266 self._state.platform.SetOSName('android') | |
267 is_disabled, reason = e.IsStoryDisabled(MockStory('mobile'), self._state) | |
268 self.assertTrue(is_disabled) | |
269 self.assertEqual(reason, 'crbug/123') | |
270 self._state.platform.SetOSName(expectations.ALL_LINUX) | |
271 is_disabled, reason = e.IsStoryDisabled(MockStory('mobile'), self._state) | |
272 self.assertFalse(is_disabled) | |
273 self.assertIsNone(reason) | |
OLD | NEW |