summaryrefslogtreecommitdiff
path: root/osprofiler/tests
diff options
context:
space:
mode:
authorVipin Balachandran <vbala@vmware.com>2017-08-01 13:30:08 -0700
committerVipin Balachandran <vbala@vmware.com>2017-08-01 18:10:59 -0700
commit88c1e8b9d39f11cde47c67d20cca186ef8a3ed16 (patch)
tree971bbff08c606fd17fc311abed222c9ccf63870a /osprofiler/tests
parent08eaf7de63c66de7a15e35f7332ee25f07249bb9 (diff)
downloadosprofiler-88c1e8b9d39f11cde47c67d20cca186ef8a3ed16.tar.gz
Improve unit test coverage
Adding a unit test for the "trace" decorator to check the case where the decorated function raises an exception. It also fixes a typo in a dummy function name. Change-Id: I1c62e5aa7cbc8d5082d9323f6965c13b3a7be9ff
Diffstat (limited to 'osprofiler/tests')
-rw-r--r--osprofiler/tests/unit/test_profiler.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/osprofiler/tests/unit/test_profiler.py b/osprofiler/tests/unit/test_profiler.py
index 6edd467..88ae9a9 100644
--- a/osprofiler/tests/unit/test_profiler.py
+++ b/osprofiler/tests/unit/test_profiler.py
@@ -171,7 +171,7 @@ class WithTraceTestCase(test.TestCase):
@profiler.trace("function", info={"info": "some_info"})
-def tracede_func(i):
+def traced_func(i):
return i
@@ -180,6 +180,11 @@ def trace_hide_args_func(a, i=10):
return (a, i)
+@profiler.trace("foo", hide_args=True)
+def test_fn_exc():
+ raise ValueError()
+
+
class TraceDecoratorTestCase(test.TestCase):
@mock.patch("osprofiler.profiler.stop")
@@ -198,11 +203,11 @@ class TraceDecoratorTestCase(test.TestCase):
@mock.patch("osprofiler.profiler.stop")
@mock.patch("osprofiler.profiler.start")
def test_with_args(self, mock_start, mock_stop):
- self.assertEqual(1, tracede_func(1))
+ self.assertEqual(1, traced_func(1))
expected_info = {
"info": "some_info",
"function": {
- "name": "osprofiler.tests.unit.test_profiler.tracede_func",
+ "name": "osprofiler.tests.unit.test_profiler.traced_func",
"args": str((1,)),
"kwargs": str({})
}
@@ -223,6 +228,20 @@ class TraceDecoratorTestCase(test.TestCase):
mock_start.assert_called_once_with("hide_args", info=expected_info)
mock_stop.assert_called_once_with()
+ @mock.patch("osprofiler.profiler.stop")
+ @mock.patch("osprofiler.profiler.start")
+ def test_with_exception(self, mock_start, mock_stop):
+
+ self.assertRaises(ValueError, test_fn_exc)
+ expected_info = {
+ "function": {
+ "name": "osprofiler.tests.unit.test_profiler.test_fn_exc"
+ }
+ }
+ expected_stop_info = {"etype": "ValueError"}
+ mock_start.assert_called_once_with("foo", info=expected_info)
+ mock_stop.assert_called_once_with(info=expected_stop_info)
+
class FakeTracedCls(object):