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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/decorators_unittest.py
diff --git a/tools/telemetry/telemetry/decorators_unittest.py b/tools/telemetry/telemetry/decorators_unittest.py
index a39d9bb5d6f9b0dce9b144d178e9f9783241a04d..d76f83d268c0c57eed6dbdebb3e2d1999cc7cbd5 100644
--- a/tools/telemetry/telemetry/decorators_unittest.py
+++ b/tools/telemetry/telemetry/decorators_unittest.py
@@ -5,6 +5,10 @@
import unittest
from telemetry import decorators
+from telemetry.core import util
+
+util.AddDirToPythonPath(util.GetTelemetryDir(), 'third_party', 'mock')
+import mock # pylint:disable=import-error
class FakePlatform(object):
@@ -82,3 +86,78 @@ class TestShouldSkip(unittest.TestCase):
test.SetDisabledStrings(['another_os_name', 'another_os_version_name'])
self.assertFalse(decorators.ShouldSkip(test, possible_browser)[0])
+
+class TestDeprecation(unittest.TestCase):
+
+ @mock.patch('warnings.warn')
+ def testFunctionDeprecation(self, warn_mock):
+ @decorators.Deprecated(2015, 12, 1)
+ def Foo(x):
+ return x
+ Foo(1)
+ warn_mock.assert_called_with(
+ 'Function Foo is deprecated. It will no longer be supported on '
+ 'December 01, 2015. Please remove it or switch to an alternative '
+ 'before that time. \n', stacklevel=4)
+
+ @mock.patch('warnings.warn')
+ def testMethodDeprecated(self, warn_mock):
+
+ class Bar(object):
+ @decorators.Deprecated(2015, 12, 1, 'Testing only.')
+ def Foo(self, x):
+ return x
+
+ Bar().Foo(1)
+ warn_mock.assert_called_with(
+ 'Function Foo is deprecated. It will no longer be supported on '
+ 'December 01, 2015. Please remove it or switch to an alternative '
+ 'before that time. Testing only.\n', stacklevel=4)
+
+ @mock.patch('warnings.warn')
+ def testClassWithoutInitDefinedDeprecated(self, warn_mock):
+ @decorators.Deprecated(2015, 12, 1)
+ class Bar(object):
+ def Foo(self, x):
+ return x
+
+ Bar().Foo(1)
+ warn_mock.assert_called_with(
+ 'Class Bar is deprecated. It will no longer be supported on '
+ 'December 01, 2015. Please remove it or switch to an alternative '
+ 'before that time. \n', stacklevel=4)
+
+ @mock.patch('warnings.warn')
+ def testClassWithInitDefinedDeprecated(self, warn_mock):
+
+ @decorators.Deprecated(2015, 12, 1)
+ class Bar(object):
+ def __init__(self):
+ pass
+ def Foo(self, x):
+ return x
+
+ Bar().Foo(1)
+ warn_mock.assert_called_with(
+ 'Class Bar is deprecated. It will no longer be supported on '
+ 'December 01, 2015. Please remove it or switch to an alternative '
+ 'before that time. \n', stacklevel=4)
+
+ @mock.patch('warnings.warn')
+ def testInheritedClassDeprecated(self, warn_mock):
+ class Ba(object):
+ pass
+
+ @decorators.Deprecated(2015, 12, 1)
+ class Bar(Ba):
+ def Foo(self, x):
+ return x
+
+ class Baz(Bar):
+ pass
+
+ Baz().Foo(1)
+ warn_mock.assert_called_with(
+ 'Class Bar is deprecated. It will no longer be supported on '
+ 'December 01, 2015. Please remove it or switch to an alternative '
+ 'before that time. \n', stacklevel=4)
« 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