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 from telemetry.testing import fakes | |
9 | |
10 | |
11 class MockState(object): | |
12 def __init__(self): | |
13 self.platform = fakes.FakePlatform() | |
14 | |
15 | |
16 class MockStory(object): | |
17 def __init__(self, name): | |
18 self._name = name | |
19 | |
20 @property | |
21 def display_name(self): | |
22 return self._name | |
23 | |
24 | |
25 class TestConditionTest(unittest.TestCase): | |
26 def testAll(self): | |
27 p = fakes.FakePlatform() | |
28 self.assertTrue(expectations.ALL.ShouldDisable(p)) | |
29 | |
30 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.
| |
31 p = fakes.FakePlatform() | |
32 p.SetOSName('win') | |
33 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!
| |
34 p.SetOSName('not_windows') | |
35 self.assertFalse(expectations.ALL_WIN.ShouldDisable(p)) | |
36 | |
37 def testAllLinux(self): | |
38 p = fakes.FakePlatform() | |
39 p.SetOSName('linux') | |
40 self.assertTrue(expectations.ALL_LINUX.ShouldDisable(p)) | |
41 p.SetOSName('not_linux') | |
42 self.assertFalse(expectations.ALL_LINUX.ShouldDisable(p)) | |
43 | |
44 def testAllMac(self): | |
45 p = fakes.FakePlatform() | |
46 p.SetOSName('mac') | |
47 self.assertTrue(expectations.ALL_MAC.ShouldDisable(p)) | |
48 p.SetOSName('not_mac') | |
49 self.assertFalse(expectations.ALL_MAC.ShouldDisable(p)) | |
50 | |
51 def testAllAndroid(self): | |
52 p = fakes.FakePlatform() | |
53 p.SetOSName('android') | |
54 self.assertTrue(expectations.ALL_ANDROID.ShouldDisable(p)) | |
55 p.SetOSName('not_android') | |
56 self.assertFalse(expectations.ALL_ANDROID.ShouldDisable(p)) | |
57 | |
58 def testAllDesktop(self): | |
59 true_platforms = ['win', 'mac', 'linux'] | |
60 false_platforms = ['android'] | |
61 p = fakes.FakePlatform() | |
62 | |
63 for plat in true_platforms: | |
64 p.SetOSName(plat) | |
65 self.assertTrue(expectations.ALL_DESKTOP.ShouldDisable(p)) | |
66 for plat in false_platforms: | |
67 p.SetOSName(plat) | |
68 self.assertFalse(expectations.ALL_DESKTOP.ShouldDisable(p)) | |
69 | |
70 def testAllMobile(self): | |
71 false_platforms = ['win', 'mac', 'linux'] | |
72 true_platforms = ['android'] | |
73 p = fakes.FakePlatform() | |
74 | |
75 for plat in true_platforms: | |
76 p.SetOSName(plat) | |
77 self.assertTrue(expectations.ALL_MOBILE.ShouldDisable(p)) | |
78 for plat in false_platforms: | |
79 p.SetOSName(plat) | |
80 self.assertFalse(expectations.ALL_MOBILE.ShouldDisable(p)) | |
81 | |
82 def testNoBattOr(self): | |
83 p = fakes.FakePlatform() | |
84 p.SetBattOrDetected(False) | |
85 self.assertTrue(expectations.NO_BATTOR.ShouldDisable(p)) | |
86 p.SetBattOrDetected(True) | |
87 self.assertFalse(expectations.ALL_WIN.ShouldDisable(p)) | |
88 | |
89 | |
90 class StoryExpectationsTest(unittest.TestCase): | |
91 def setUp(self): | |
92 self.platform = fakes.FakePlatform() | |
93 | |
94 def testCantDisableAfterInit(self): | |
95 e = expectations.StoryExpectations() | |
96 with self.assertRaises(AssertionError): | |
97 e.DisableBenchmark(['test'], 'test') | |
98 with self.assertRaises(AssertionError): | |
99 e.DisableStory('story', ['platform'], 'reason') | |
100 | |
101 def testDisableBenchmark(self): | |
102 class FooExpectations(expectations.StoryExpectations): | |
103 def SetExpectations(self): | |
104 self.DisableBenchmark([expectations.ALL_WIN], 'crbug.com/123') | |
105 | |
106 e = FooExpectations() | |
107 self.platform.SetOSName('win') | |
108 | |
109 reason = e.IsBenchmarkDisabled(self.platform) | |
110 self.assertTrue(reason) | |
111 self.assertEqual(reason, 'crbug.com/123') | |
112 | |
113 self.platform.SetOSName('android') | |
114 reason = e.IsBenchmarkDisabled(self.platform) | |
115 self.assertIsNone(reason) | |
116 | |
117 def testDisableStoryMultipleConditions(self): | |
118 class FooExpectations(expectations.StoryExpectations): | |
119 def SetExpectations(self): | |
120 self.DisableStory( | |
121 'multi', [expectations.ALL_WIN], 'crbug.com/123') | |
122 self.DisableStory( | |
123 'multi', [expectations.ALL_MAC], 'crbug.com/456') | |
124 | |
125 e = FooExpectations() | |
126 | |
127 self.platform.SetOSName('mac') | |
128 reason = e.IsStoryDisabled( | |
129 MockStory('multi'), self.platform) | |
130 self.assertTrue(reason) | |
131 self.assertEqual(reason, 'crbug.com/456') | |
132 | |
133 def testDisableStoryOneCondition(self): | |
134 class FooExpectations(expectations.StoryExpectations): | |
135 def SetExpectations(self): | |
136 self.DisableStory( | |
137 'disable', [expectations.ALL_WIN], 'crbug.com/123') | |
138 | |
139 e = FooExpectations() | |
140 | |
141 self.platform.SetOSName('win') | |
142 reason = e.IsStoryDisabled( | |
143 MockStory('disable'), self.platform) | |
144 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.
| |
145 self.assertEqual(reason, 'crbug.com/123') | |
146 self.platform.SetOSName('mac') | |
147 reason = e.IsStoryDisabled( | |
148 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.
| |
149 self.assertFalse(reason) | |
150 self.assertIsNone(reason) | |
151 | |
152 def testDisableStoryWithLongName(self): | |
153 class FooExpectations(expectations.StoryExpectations): | |
154 def SetExpectations(self): | |
155 self.DisableStory( | |
156 '123456789012345678901234567890123456789012345678901', | |
157 [expectations.ALL], 'Too Long') | |
158 | |
159 with self.assertRaises(AssertionError): | |
160 FooExpectations() | |
OLD | NEW |