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

Side by Side Diff: tools/telemetry/telemetry/decorators_unittest.py

Issue 1171113002: [Telemetry] Add Deprecated decorators and apply it for page_set (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unittest after grammar fix Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « tools/telemetry/telemetry/decorators.py ('k') | tools/telemetry/telemetry/page/page_set.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import unittest 5 import unittest
6 6
7 from telemetry import decorators 7 from telemetry import decorators
8 from telemetry.core import util
9
10 util.AddDirToPythonPath(util.GetTelemetryDir(), 'third_party', 'mock')
11 import mock # pylint:disable=import-error
8 12
9 13
10 class FakePlatform(object): 14 class FakePlatform(object):
11 def GetOSName(self): 15 def GetOSName(self):
12 return 'os_name' 16 return 'os_name'
13 17
14 def GetOSVersionName(self): 18 def GetOSVersionName(self):
15 return 'os_version_name' 19 return 'os_version_name'
16 20
17 21
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 self.assertTrue(decorators.ShouldSkip(test, possible_browser)[0]) 79 self.assertTrue(decorators.ShouldSkip(test, possible_browser)[0])
76 80
77 test.SetDisabledStrings(['os_name', 'another_os_name']) 81 test.SetDisabledStrings(['os_name', 'another_os_name'])
78 self.assertTrue(decorators.ShouldSkip(test, possible_browser)[0]) 82 self.assertTrue(decorators.ShouldSkip(test, possible_browser)[0])
79 83
80 test.SetDisabledStrings(['another_os_name', 'os_name']) 84 test.SetDisabledStrings(['another_os_name', 'os_name'])
81 self.assertTrue(decorators.ShouldSkip(test, possible_browser)[0]) 85 self.assertTrue(decorators.ShouldSkip(test, possible_browser)[0])
82 86
83 test.SetDisabledStrings(['another_os_name', 'another_os_version_name']) 87 test.SetDisabledStrings(['another_os_name', 'another_os_version_name'])
84 self.assertFalse(decorators.ShouldSkip(test, possible_browser)[0]) 88 self.assertFalse(decorators.ShouldSkip(test, possible_browser)[0])
89
90 class TestDeprecation(unittest.TestCase):
91
92 @mock.patch('warnings.warn')
93 def testFunctionDeprecation(self, warn_mock):
94 @decorators.Deprecated(2015, 12, 1)
95 def Foo(x):
96 return x
97 Foo(1)
98 warn_mock.assert_called_with(
99 'Function Foo is deprecated. It will no longer be supported on '
100 'December 01, 2015. Please remove it or switch to an alternative '
101 'before that time. \n', stacklevel=4)
102
103 @mock.patch('warnings.warn')
104 def testMethodDeprecated(self, warn_mock):
105
106 class Bar(object):
107 @decorators.Deprecated(2015, 12, 1, 'Testing only.')
108 def Foo(self, x):
109 return x
110
111 Bar().Foo(1)
112 warn_mock.assert_called_with(
113 'Function Foo is deprecated. It will no longer be supported on '
114 'December 01, 2015. Please remove it or switch to an alternative '
115 'before that time. Testing only.\n', stacklevel=4)
116
117 @mock.patch('warnings.warn')
118 def testClassWithoutInitDefinedDeprecated(self, warn_mock):
119 @decorators.Deprecated(2015, 12, 1)
120 class Bar(object):
121 def Foo(self, x):
122 return x
123
124 Bar().Foo(1)
125 warn_mock.assert_called_with(
126 'Class Bar is deprecated. It will no longer be supported on '
127 'December 01, 2015. Please remove it or switch to an alternative '
128 'before that time. \n', stacklevel=4)
129
130 @mock.patch('warnings.warn')
131 def testClassWithInitDefinedDeprecated(self, warn_mock):
132
133 @decorators.Deprecated(2015, 12, 1)
134 class Bar(object):
135 def __init__(self):
136 pass
137 def Foo(self, x):
138 return x
139
140 Bar().Foo(1)
141 warn_mock.assert_called_with(
142 'Class Bar is deprecated. It will no longer be supported on '
143 'December 01, 2015. Please remove it or switch to an alternative '
144 'before that time. \n', stacklevel=4)
145
146 @mock.patch('warnings.warn')
147 def testInheritedClassDeprecated(self, warn_mock):
148 class Ba(object):
149 pass
150
151 @decorators.Deprecated(2015, 12, 1)
152 class Bar(Ba):
153 def Foo(self, x):
154 return x
155
156 class Baz(Bar):
157 pass
158
159 Baz().Foo(1)
160 warn_mock.assert_called_with(
161 'Class Bar is deprecated. It will no longer be supported on '
162 'December 01, 2015. Please remove it or switch to an alternative '
163 'before that time. \n', stacklevel=4)
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/decorators.py ('k') | tools/telemetry/telemetry/page/page_set.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698