Skip to content

Commit e4d2e2b

Browse files
committed
Add (failing) tests for the profiling panel.
Refs #466.
1 parent efdd0ce commit e4d2e2b

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

tests/panels/test_profiling.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,51 @@
44
from django.db import IntegrityError, transaction
55
from django.test import TestCase
66
from django.test.utils import override_settings
7+
from django.utils import unittest
8+
9+
try:
10+
import line_profiler
11+
except ImportError:
12+
line_profiler = None
13+
14+
from debug_toolbar.panels import profiling
15+
16+
from ..base import BaseTestCase
17+
from ..views import regular_view
18+
19+
20+
@override_settings(DEBUG_TOOLBAR_PANELS=['debug_toolbar.panels.profiling.ProfilingDebugPanel'])
21+
class ProfilingPanelTestCase(BaseTestCase):
22+
23+
def setUp(self):
24+
super(ProfilingPanelTestCase, self).setUp()
25+
self.panel = self.toolbar.get_panel_by_id('ProfilingDebugPanel')
26+
27+
def _test_render_with_or_without_line_profiler(self):
28+
self.panel.process_view(self.request, regular_view, ('profiling',), {})
29+
self.panel.process_response(self.request, self.response)
30+
self.assertIn('func_list', self.panel.get_stats())
31+
self.assertIn('regular_view', self.panel.content())
32+
33+
@unittest.skipIf(line_profiler is None, "line_profiler isn't available")
34+
def test_render_with_line_profiler(self):
35+
self._test_render_with_or_without_line_profiler()
36+
37+
def test_without_line_profiler(self):
38+
_use_line_profiler = profiling.DJ_PROFILE_USE_LINE_PROFILER
39+
profiling.DJ_PROFILE_USE_LINE_PROFILER = False
40+
try:
41+
self._test_render_with_or_without_line_profiler()
42+
finally:
43+
profiling.DJ_PROFILE_USE_LINE_PROFILER = _use_line_profiler
44+
745

846

947
@override_settings(DEBUG=True,
1048
DEBUG_TOOLBAR_PANELS=['debug_toolbar.panels.profiling.ProfilingDebugPanel'])
1149
class ProfilingPanelIntegrationTestCase(TestCase):
1250

1351
def test_view_executed_once(self):
14-
1552
self.assertEqual(User.objects.count(), 0)
1653

1754
response = self.client.get('/new_user/')

0 commit comments

Comments
 (0)