diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-04-21 02:57:34 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-04-21 02:57:34 +0000 |
commit | aedfd079f11831b73fd997d801fa0a44c20957d6 (patch) | |
tree | 059755af31e7ec446043b38f440da32ca406ea1b | |
parent | b7520ab12f7d2d7628c72d2f881237cdd27035ed (diff) | |
parent | 1984abe9e5fd5f13edff52918b83fa8040773ed7 (diff) | |
download | osprofiler-aedfd079f11831b73fd997d801fa0a44c20957d6.tar.gz |
Merge "Improve unit test coverage"
-rw-r--r-- | osprofiler/tests/test_profiler.py | 44 |
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): |