summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVipin Balachandran <vbala@vmware.com>2016-03-15 05:11:55 -0700
committerVipin Balachandran <vbala@vmware.com>2016-03-16 00:02:29 -0700
commit1984abe9e5fd5f13edff52918b83fa8040773ed7 (patch)
treefe0f06eabb93494b9093f4295413ace11844cbaf
parent0cb213faeb4db8af4300b13488a3cee634b3c7f7 (diff)
downloadosprofiler-1984abe9e5fd5f13edff52918b83fa8040773ed7.tar.gz
Improve unit test coverage
This patch adds unit tests to cover the following cases: * Disable tracing of static methods * Disable tracing of class methods Change-Id: I16183c83b0dbf5ec974894c35bc77fd44bfe5455
-rw-r--r--osprofiler/tests/test_profiler.py44
1 files changed, 39 insertions, 5 deletions
diff --git a/osprofiler/tests/test_profiler.py b/osprofiler/tests/test_profiler.py
index 2219c09..13288e7 100644
--- a/osprofiler/tests/test_profiler.py
+++ b/osprofiler/tests/test_profiler.py
@@ -240,13 +240,33 @@ class FakeTracePrivate(FakeTracedCls):
pass
-@profiler.trace_cls("rpc")
-class FakeTraceStatic(FakeTracedCls):
+class FakeTraceStaticMethodBase(FakeTracedCls):
@staticmethod
- def method4(arg):
+ def static_method(arg):
return arg
+@profiler.trace_cls("rpc", trace_static_methods=True)
+class FakeTraceStaticMethod(FakeTraceStaticMethodBase):
+ pass
+
+
+@profiler.trace_cls("rpc")
+class FakeTraceStaticMethodSkip(FakeTraceStaticMethodBase):
+ pass
+
+
+class FakeTraceClassMethodBase(FakeTracedCls):
+ @classmethod
+ def class_method(cls, arg):
+ return arg
+
+
+@profiler.trace_cls("rpc")
+class FakeTraceClassMethodSkip(FakeTraceClassMethodBase):
+ pass
+
+
def py3_info(info):
# NOTE(boris-42): py33 I hate you.
info_py3 = copy.deepcopy(info)
@@ -353,9 +373,9 @@ class TraceClsDecoratorTestCase(test.TestCase):
"Static method tracing was disabled due the bug. This test should be "
"skipped until we find the way to address it.")
def test_static(self, mock_start, mock_stop):
- fake_cls = FakeTraceStatic()
+ fake_cls = FakeTraceStaticMethod()
- self.assertEqual(25, fake_cls.method4(25))
+ self.assertEqual(25, fake_cls.static_method(25))
expected_info = {
"function": {
@@ -377,6 +397,20 @@ class TraceClsDecoratorTestCase(test.TestCase):
possible_mock_calls("rpc", expected_info))
mock_stop.assert_called_once_with()
+ @mock.patch("osprofiler.profiler.stop")
+ @mock.patch("osprofiler.profiler.start")
+ def test_static_method_skip(self, mock_start, mock_stop):
+ self.assertEqual(25, FakeTraceStaticMethodSkip.static_method(25))
+ self.assertFalse(mock_start.called)
+ self.assertFalse(mock_stop.called)
+
+ @mock.patch("osprofiler.profiler.stop")
+ @mock.patch("osprofiler.profiler.start")
+ def test_class_method_skip(self, mock_start, mock_stop):
+ self.assertEqual("foo", FakeTraceClassMethodSkip.class_method("foo"))
+ self.assertFalse(mock_start.called)
+ self.assertFalse(mock_stop.called)
+
@six.add_metaclass(profiler.TracedMeta)
class FakeTraceWithMetaclassBase(object):