aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAymeric Augustin2013-10-26 17:44:41 +0200
committerAymeric Augustin2013-10-26 17:44:41 +0200
commitcd1864026c62163c05fe5e22d964884d7b28afaa (patch)
tree3aef3a4030dd68f1b9c55e800c0344fcd36ef8d9
parentba9f739620d4955aabf112850122345828402f2b (diff)
downloaddjango-debug-toolbar-cd1864026c62163c05fe5e22d964884d7b28afaa.tar.bz2
Eliminate almost all flake8 messages.
-rw-r--r--Makefile3
-rw-r--r--debug_toolbar/management/commands/debugsqlshell.py2
-rw-r--r--debug_toolbar/middleware.py18
-rw-r--r--debug_toolbar/panels/cache.py11
-rw-r--r--debug_toolbar/panels/logger.py3
-rw-r--r--debug_toolbar/panels/profiling.py23
-rw-r--r--debug_toolbar/panels/request_vars.py12
-rw-r--r--debug_toolbar/panels/signals.py17
-rw-r--r--debug_toolbar/panels/sql.py9
-rw-r--r--debug_toolbar/panels/template.py6
-rw-r--r--debug_toolbar/panels/timer.py4
-rw-r--r--debug_toolbar/templatetags/debug_toolbar_utils.py1
-rw-r--r--debug_toolbar/urls.py2
-rw-r--r--debug_toolbar/utils/__init__.py2
-rw-r--r--debug_toolbar/utils/tracking/db.py10
-rw-r--r--debug_toolbar/views.py14
-rw-r--r--example/urls.py2
-rw-r--r--runtests.py4
-rw-r--r--setup.cfg3
-rw-r--r--setup.py3
-rw-r--r--test_pgsql.py18
-rw-r--r--tests/tests.py28
-rw-r--r--tests/urls.py4
23 files changed, 120 insertions, 79 deletions
diff --git a/Makefile b/Makefile
index 3631f34..40fc27c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,9 @@
# Make file to compress and join all JS files
all: compress_js compress_css
+flake8:
+ flake8 *.py debug_toolbar example tests
+
test:
pip install Django
python runtests.py
diff --git a/debug_toolbar/management/commands/debugsqlshell.py b/debug_toolbar/management/commands/debugsqlshell.py
index 120f0a2..a11af98 100644
--- a/debug_toolbar/management/commands/debugsqlshell.py
+++ b/debug_toolbar/management/commands/debugsqlshell.py
@@ -3,7 +3,7 @@ from __future__ import print_function, unicode_literals
from time import time
# 'debugsqlshell' is the same as the 'shell'.
-from django.core.management.commands.shell import Command
+from django.core.management.commands.shell import Command # noqa
from django.db.backends import util
import sqlparse
diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py
index f58d78c..2c47227 100644
--- a/debug_toolbar/middleware.py
+++ b/debug_toolbar/middleware.py
@@ -18,13 +18,15 @@ import debug_toolbar.urls
from debug_toolbar.toolbar.loader import DebugToolbar
_HTML_TYPES = ('text/html', 'application/xhtml+xml')
-threading._DummyThread._Thread__stop = lambda x: 1 # Handles python threading module bug - http://bugs.python.org/issue14308
+# Handles python threading module bug - http://bugs.python.org/issue14308
+threading._DummyThread._Thread__stop = lambda x: 1
def replace_insensitive(string, target, replacement):
"""
- Similar to string.replace() but is case insensitive
- Code borrowed from: http://forums.devshed.com/python-programming-11/case-insensitive-string-replace-490921.html
+ Similar to string.replace() but is case insensitive.
+ Code borrowed from:
+ http://forums.devshed.com/python-programming-11/case-insensitive-string-replace-490921.html
"""
no_case = string.lower()
index = no_case.rfind(target.lower())
@@ -75,7 +77,7 @@ class DebugToolbarMiddleware(object):
self.tag = '</' + tag + '>'
def process_request(self, request):
- __traceback_hide__ = True
+ __traceback_hide__ = True # noqa
if self.show_toolbar(request):
urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF)
if isinstance(urlconf, six.string_types):
@@ -83,8 +85,8 @@ class DebugToolbarMiddleware(object):
if urlconf not in self._urlconfs:
new_urlconf = imp.new_module('urlconf')
- new_urlconf.urlpatterns = debug_toolbar.urls.urlpatterns + \
- list(urlconf.urlpatterns)
+ new_urlconf.urlpatterns = (debug_toolbar.urls.urlpatterns +
+ list(urlconf.urlpatterns))
if hasattr(urlconf, 'handler403'):
new_urlconf.handler403 = urlconf.handler403
@@ -103,7 +105,7 @@ class DebugToolbarMiddleware(object):
self.__class__.debug_toolbars[threading.current_thread().ident] = toolbar
def process_view(self, request, view_func, view_args, view_kwargs):
- __traceback_hide__ = True
+ __traceback_hide__ = True # noqa
toolbar = self.__class__.debug_toolbars.get(threading.current_thread().ident)
if not toolbar:
return
@@ -115,7 +117,7 @@ class DebugToolbarMiddleware(object):
return result
def process_response(self, request, response):
- __traceback_hide__ = True
+ __traceback_hide__ = True # noqa
ident = threading.current_thread().ident
toolbar = self.__class__.debug_toolbars.get(ident)
if not toolbar or request.is_ajax() or getattr(response, 'streaming', False):
diff --git a/debug_toolbar/panels/cache.py b/debug_toolbar/panels/cache.py
index 1272dfc..b3cb540 100644
--- a/debug_toolbar/panels/cache.py
+++ b/debug_toolbar/panels/cache.py
@@ -18,7 +18,8 @@ from debug_toolbar.utils import (tidy_stacktrace, render_stacktrace,
get_template_info, get_stack)
-cache_called = Signal(providing_args=["time_taken", "name", "return_value", "args", "kwargs", "trace"])
+cache_called = Signal(providing_args=[
+ "time_taken", "name", "return_value", "args", "kwargs", "trace"])
def send_signal(method):
@@ -27,8 +28,8 @@ def send_signal(method):
value = method(self, *args, **kwargs)
t = time.time() - t
- enable_stacktraces = getattr(settings,
- 'DEBUG_TOOLBAR_CONFIG', {}).get('ENABLE_STACKTRACES', True)
+ debug_toolbar_config = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {})
+ enable_stacktraces = debug_toolbar_config.get('ENABLE_STACKTRACES', True)
if enable_stacktraces:
stacktrace = tidy_stacktrace(reversed(get_stack()))
else:
@@ -160,8 +161,8 @@ class CacheDebugPanel(DebugPanel):
cache_called.connect(self._store_call_info)
def _store_call_info(self, sender, name=None, time_taken=0,
- return_value=None, args=None, kwargs=None, trace=None,
- template_info=None, backend=None, **kw):
+ return_value=None, args=None, kwargs=None,
+ trace=None, template_info=None, backend=None, **kw):
if name == 'get':
if return_value is None:
self.misses += 1
diff --git a/debug_toolbar/panels/logger.py b/debug_toolbar/panels/logger.py
index 2c749ce..0617976 100644
--- a/debug_toolbar/panels/logger.py
+++ b/debug_toolbar/panels/logger.py
@@ -15,7 +15,8 @@ MESSAGE_IF_STRING_REPRESENTATION_INVALID = '[Could not get log message]'
class LogCollector(object):
def __init__(self):
if threading is None:
- raise NotImplementedError("threading module is not available, "
+ raise NotImplementedError(
+ "threading module is not available, "
"the logging panel cannot be used without it")
self.records = {} # a dictionary that maps threads to log records
diff --git a/debug_toolbar/panels/profiling.py b/debug_toolbar/panels/profiling.py
index 995cccb..0555f23 100644
--- a/debug_toolbar/panels/profiling.py
+++ b/debug_toolbar/panels/profiling.py
@@ -69,12 +69,15 @@ class FunctionCall(object):
file_path, file_name = file_name.rsplit(os.sep, 1)
- return mark_safe('<span class="path">{0}/</span><span class="file">{1}</span> in <span class="func">{3}</span>(<span class="lineno">{2}</span>)'.format(
- file_path,
- file_name,
- line_num,
- method,
- ))
+ return mark_safe(
+ '<span class="path">{0}/</span>'
+ '<span class="file">{1}</span>'
+ ' in <span class="func">{3}</span>'
+ '(<span class="lineno">{2}</span>)'.format(
+ file_path,
+ file_name,
+ line_num,
+ method))
def subfuncs(self):
i = 0
@@ -164,7 +167,7 @@ class ProfilingDebugPanel(DebugPanel):
self._unwrap_closure_and_profile(cell.cell_contents)
def process_view(self, request, view_func, view_args, view_kwargs):
- __traceback_hide__ = True
+ __traceback_hide__ = True # noqa
self.profiler = cProfile.Profile()
args = (request,) + view_args
if DJ_PROFILE_USE_LINE_PROFILER:
@@ -184,13 +187,13 @@ class ProfilingDebugPanel(DebugPanel):
if func.depth < max_depth:
for subfunc in func.subfuncs():
if (subfunc.stats[3] >= cum_time or
- (hasattr(self.stats, 'line_stats') and
- (subfunc.func in self.stats.line_stats.timings))):
+ (hasattr(self.stats, 'line_stats') and
+ (subfunc.func in self.stats.line_stats.timings))):
func.has_subfuncs = True
self.add_node(func_list, subfunc, max_depth, cum_time=cum_time)
def process_response(self, request, response):
- __traceback_hide__ = True
+ __traceback_hide__ = True # noqa
if not hasattr(self, 'profiler'):
return None
self.profiler.create_stats()
diff --git a/debug_toolbar/panels/request_vars.py b/debug_toolbar/panels/request_vars.py
index 5bf3e7f..326d014 100644
--- a/debug_toolbar/panels/request_vars.py
+++ b/debug_toolbar/panels/request_vars.py
@@ -35,11 +35,11 @@ class RequestVarsDebugPanel(DebugPanel):
'cookies': [(k, self.request.COOKIES.get(k)) for k in self.request.COOKIES],
})
view_info = {
- 'view_func': _('<no view>'),
- 'view_args': 'None',
- 'view_kwargs': 'None',
- 'view_urlname': 'None',
- }
+ 'view_func': _('<no view>'),
+ 'view_args': 'None',
+ 'view_kwargs': 'None',
+ 'view_urlname': 'None',
+ }
try:
match = resolve(self.request.path)
func, args, kwargs = match
@@ -56,4 +56,4 @@ class RequestVarsDebugPanel(DebugPanel):
self.record_stats({
'session': [(k, self.request.session.get(k))
for k in self.request.session.keys()]
- })
+ })
diff --git a/debug_toolbar/panels/signals.py b/debug_toolbar/panels/signals.py
index d3d9cfc..f7d4239 100644
--- a/debug_toolbar/panels/signals.py
+++ b/debug_toolbar/panels/signals.py
@@ -1,10 +1,11 @@
from __future__ import unicode_literals
from django.conf import settings
-from django.core.signals import (request_started, request_finished,
- got_request_exception)
-from django.db.models.signals import (class_prepared, pre_init, post_init,
- pre_save, post_save, pre_delete, post_delete, post_syncdb)
+from django.core.signals import (
+ request_started, request_finished, got_request_exception)
+from django.db.models.signals import (
+ class_prepared, pre_init, post_init, pre_save, post_save,
+ pre_delete, post_delete, post_syncdb)
from django.dispatch.dispatcher import WEAKREF_TYPES
from django.utils.translation import ugettext_lazy as _, ungettext
from django.utils.importlib import import_module
@@ -13,7 +14,7 @@ from django.utils.importlib import import_module
try:
from django.db.backends.signals import connection_created
except ImportError:
- connection_created = None # noqa
+ connection_created = None
from debug_toolbar.panels import DebugPanel
@@ -90,9 +91,11 @@ class SignalDebugPanel(DebugPanel):
receiver = getattr(receiver, '__wraps__', receiver)
receiver_name = getattr(receiver, '__name__', str(receiver))
if getattr(receiver, '__self__', None) is not None:
- text = "%s.%s" % (getattr(receiver.__self__, '__class__', type).__name__, receiver_name)
+ receiver_class_name = getattr(receiver.__self__, '__class__', type).__name__
+ text = "%s.%s" % (receiver_class_name, receiver_name)
elif getattr(receiver, 'im_class', None) is not None: # Python 2 only
- text = "%s.%s" % (receiver.im_class.__name__, receiver_name)
+ receiver_class_name = receiver.im_class.__name__
+ text = "%s.%s" % (receiver_class_name, receiver_name)
else:
text = "%s" % receiver_name
receivers.append(text)
diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py
index 709a5f5..660a794 100644
--- a/debug_toolbar/panels/sql.py
+++ b/debug_toolbar/panels/sql.py
@@ -171,9 +171,11 @@ class SQLDebugPanel(DebugPanel):
query['alias'] = alias
if 'iso_level' in query:
- query['iso_level'] = get_isolation_level_display(query['engine'], query['iso_level'])
+ query['iso_level'] = get_isolation_level_display(query['engine'],
+ query['iso_level'])
if 'trans_status' in query:
- query['trans_status'] = get_transaction_status_display(query['engine'], query['trans_status'])
+ query['trans_status'] = get_transaction_status_display(query['engine'],
+ query['trans_status'])
query['form'] = SQLSelectForm(auto_id=None, initial=copy(query))
@@ -182,7 +184,8 @@ class SQLDebugPanel(DebugPanel):
query['rgb_color'] = self._databases[alias]['rgb_color']
try:
query['width_ratio'] = (query['duration'] / self._sql_time) * 100
- query['width_ratio_relative'] = 100.0 * query['width_ratio'] / (100.0 - width_ratio_tally)
+ query['width_ratio_relative'] = (
+ 100.0 * query['width_ratio'] / (100.0 - width_ratio_tally))
except ZeroDivisionError:
query['width_ratio'] = 0
query['width_ratio_relative'] = 0
diff --git a/debug_toolbar/panels/template.py b/debug_toolbar/panels/template.py
index b3b6707..d8f96f2 100644
--- a/debug_toolbar/panels/template.py
+++ b/debug_toolbar/panels/template.py
@@ -75,8 +75,10 @@ class TemplateDebugPanel(DebugPanel):
temp_layer[key] = '<<languages>>'
# QuerySet would trigger the database: user can run the query from SQL Panel
elif isinstance(value, (QuerySet, RawQuerySet)):
- model_name = "%s.%s" % (value.model._meta.app_label, value.model.__name__)
- temp_layer[key] = '<<%s of %s>>' % (value.__class__.__name__.lower(), model_name)
+ model_name = "%s.%s" % (
+ value.model._meta.app_label, value.model.__name__)
+ temp_layer[key] = '<<%s of %s>>' % (
+ value.__class__.__name__.lower(), model_name)
else:
try:
recording(False)
diff --git a/debug_toolbar/panels/timer.py b/debug_toolbar/panels/timer.py
index 9b420cb..379f6ae 100644
--- a/debug_toolbar/panels/timer.py
+++ b/debug_toolbar/panels/timer.py
@@ -89,10 +89,6 @@ class TimerDebugPanel(DebugPanel):
(_('Total CPU time'), _('%(total)0.3f msec') % stats),
(_('Elapsed time'), _('%(total_time)0.3f msec') % stats),
(_('Context switches'), _('%(vcsw)d voluntary, %(ivcsw)d involuntary') % stats),
-# ('Memory use', '%d max RSS, %d shared, %d unshared' % (stats['rss'], stats.['srss'],
-# stats['urss'] + stats['usrss'])),
-# ('Page faults', '%d no i/o, %d requiring i/o' % (stats['minflt'], stats['majflt'])),
-# ('Disk operations', '%d in, %d out, %d swapout' % (stats['blkin'], stats['blkout'], stats['swap'])),
)
context = self.context.copy()
context.update({'rows': rows})
diff --git a/debug_toolbar/templatetags/debug_toolbar_utils.py b/debug_toolbar/templatetags/debug_toolbar_utils.py
index 7917a67..c96f868 100644
--- a/debug_toolbar/templatetags/debug_toolbar_utils.py
+++ b/debug_toolbar/templatetags/debug_toolbar_utils.py
@@ -10,4 +10,3 @@ register = template.Library()
def dotted_number(number):
number = float(number)
return format(number, '.', 6)
-
diff --git a/debug_toolbar/urls.py b/debug_toolbar/urls.py
index 524710d..1a6daf8 100644
--- a/debug_toolbar/urls.py
+++ b/debug_toolbar/urls.py
@@ -11,7 +11,7 @@ from django.conf.urls import patterns, url
_PREFIX = '__debug__'
-urlpatterns = patterns('debug_toolbar.views',
+urlpatterns = patterns('debug_toolbar.views', # noqa
url(r'^%s/sql_select/$' % _PREFIX, 'sql_select', name='sql_select'),
url(r'^%s/sql_explain/$' % _PREFIX, 'sql_explain', name='sql_explain'),
url(r'^%s/sql_profile/$' % _PREFIX, 'sql_profile', name='sql_profile'),
diff --git a/debug_toolbar/utils/__init__.py b/debug_toolbar/utils/__init__.py
index da2e3c3..73e38e2 100644
--- a/debug_toolbar/utils/__init__.py
+++ b/debug_toolbar/utils/__init__.py
@@ -68,7 +68,7 @@ def tidy_stacktrace(stack):
# inspection.
if '__traceback_hide__' in frame.f_locals:
continue
- if hide_django_sql and django_path in s_path and not 'django/contrib' in s_path:
+ if hide_django_sql and django_path in s_path and not 'django/contrib' in s_path:
continue
if omit_path(s_path):
continue
diff --git a/debug_toolbar/utils/tracking/db.py b/debug_toolbar/utils/tracking/db.py
index b4ceff0..5822270 100644
--- a/debug_toolbar/utils/tracking/db.py
+++ b/debug_toolbar/utils/tracking/db.py
@@ -16,8 +16,8 @@ from debug_toolbar.utils import tidy_stacktrace, get_template_info, get_stack
# TODO:This should be set in the toolbar loader as a default and panels should
# get a copy of the toolbar object with access to its config dictionary
-SQL_WARNING_THRESHOLD = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}) \
- .get('SQL_WARNING_THRESHOLD', 500)
+DEBUG_TOOLBAR_CONFIG = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {})
+SQL_WARNING_THRESHOLD = DEBUG_TOOLBAR_CONFIG.get('SQL_WARNING_THRESHOLD', 500)
class SQLQueryTriggered(Exception):
@@ -82,7 +82,7 @@ class NormalCursorWrapper(object):
return params
if isinstance(params, dict):
return dict((key, self._quote_expr(value))
- for key, value in params.items())
+ for key, value in params.items())
return list(map(self._quote_expr, params))
def _decode(self, param):
@@ -98,8 +98,8 @@ class NormalCursorWrapper(object):
finally:
stop_time = time()
duration = (stop_time - start_time) * 1000
- enable_stacktraces = getattr(settings,
- 'DEBUG_TOOLBAR_CONFIG', {}).get('ENABLE_STACKTRACES', True)
+ debug_toolbar_config = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {})
+ enable_stacktraces = debug_toolbar_config.get('ENABLE_STACKTRACES', True)
if enable_stacktraces:
stacktrace = tidy_stacktrace(reversed(get_stack()))
else:
diff --git a/debug_toolbar/views.py b/debug_toolbar/views.py
index 53ad3c9..436cb07 100644
--- a/debug_toolbar/views.py
+++ b/debug_toolbar/views.py
@@ -90,8 +90,18 @@ def sql_profile(request):
cursor.execute("SET PROFILING=1") # Enable profiling
cursor.execute(sql, params) # Execute SELECT
cursor.execute("SET PROFILING=0") # Disable profiling
- # The Query ID should always be 1 here but I'll subselect to get the last one just in case...
- cursor.execute("SELECT * FROM information_schema.profiling WHERE query_id=(SELECT query_id FROM information_schema.profiling ORDER BY query_id DESC LIMIT 1)")
+ # The Query ID should always be 1 here but I'll subselect to get
+ # the last one just in case...
+ cursor.execute("""
+ SELECT *
+ FROM information_schema.profiling
+ WHERE query_id = (
+ SELECT query_id
+ FROM information_schema.profiling
+ ORDER BY query_id DESC
+ LIMIT 1
+ )
+""")
headers = [d[0] for d in cursor.description]
result = cursor.fetchall()
except Exception:
diff --git a/example/urls.py b/example/urls.py
index 7b3ff35..2fe01dc 100644
--- a/example/urls.py
+++ b/example/urls.py
@@ -4,7 +4,7 @@ from django.views.generic import TemplateView
admin.autodiscover()
-urlpatterns = patterns('',
+urlpatterns = patterns('', # noqa
(r'^$', TemplateView.as_view(template_name='index.html')),
(r'^jquery/$', TemplateView.as_view(template_name='jquery/index.html')),
(r'^mootools/$', TemplateView.as_view(template_name='mootools/index.html')),
diff --git a/runtests.py b/runtests.py
index ed49824..544222c 100644
--- a/runtests.py
+++ b/runtests.py
@@ -46,7 +46,9 @@ def runtests(*test_args, **kwargs):
test_args = ['tests']
parent = dirname(abspath(__file__))
sys.path.insert(0, parent)
- test_runner = DjangoTestSuiteRunner(verbosity=kwargs.get('verbosity', 1), interactive=kwargs.get('interactive', False), failfast=kwargs.get('failfast'))
+ test_runner = DjangoTestSuiteRunner(verbosity=kwargs.get('verbosity', 1),
+ interactive=kwargs.get('interactive', False),
+ failfast=kwargs.get('failfast'))
failures = test_runner.run_tests(test_args)
sys.exit(failures)
diff --git a/setup.cfg b/setup.cfg
index 21cced6..f09e37b 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,2 +1,5 @@
[egg_info]
tag_svn_revision = false
+
+[flake8]
+max-line-length = 100
diff --git a/setup.py b/setup.py
index 967a814..1486f3c 100644
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,8 @@ from setuptools import setup, find_packages
setup(
name='django-debug-toolbar',
version='0.9.4',
- description='A configurable set of panels that display various debug information about the current request/response.',
+ description='A configurable set of panels that display various debug '
+ 'information about the current request/response.',
long_description=open('README.rst').read(),
author='Rob Hudson',
author_email='rob@cogit8.org',
diff --git a/test_pgsql.py b/test_pgsql.py
index 28c0178..7a2aa9b 100644
--- a/test_pgsql.py
+++ b/test_pgsql.py
@@ -1,5 +1,6 @@
from django.conf import global_settings
-DATABASES={
+
+DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
# Edit the below settings before use...
@@ -9,7 +10,8 @@ DATABASES={
'PASSWORD': '',
}
}
-INSTALLED_APPS=[
+
+INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
@@ -20,9 +22,13 @@ INSTALLED_APPS=[
'tests',
]
-MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES + (
+
+MIDDLEWARE_CLASSES = global_settings.MIDDLEWARE_CLASSES + (
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
-ROOT_URLCONF=''
-DEBUG=False
-SITE_ID=1
+
+ROOT_URLCONF = ''
+
+DEBUG = False
+
+SITE_ID = 1
diff --git a/tests/tests.py b/tests/tests.py
index 20b722b..9c5e5a7 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -20,8 +20,8 @@ from django.utils import six
from django.utils import unittest
from debug_toolbar.middleware import DebugToolbarMiddleware, show_toolbar
-from debug_toolbar.panels.logger import (LoggingPanel,
- MESSAGE_IF_STRING_REPRESENTATION_INVALID)
+from debug_toolbar.panels.logger import (
+ LoggingPanel, MESSAGE_IF_STRING_REPRESENTATION_INVALID)
from debug_toolbar.panels.sql import SQLDebugPanel
from debug_toolbar.panels.request_vars import RequestVarsDebugPanel
from debug_toolbar.panels.template import TemplateDebugPanel
@@ -47,7 +47,6 @@ class BaseTestCase(TestCase):
self.toolbar.stats = {}
-
@override_settings(DEBUG=True, INTERNAL_IPS=['127.0.0.1'])
class DebugToolbarTestCase(BaseTestCase):
@@ -74,8 +73,9 @@ class DebugToolbarTestCase(BaseTestCase):
self.assertFalse(isinstance(request.urlconf, six.string_types))
- self.assertTrue(hasattr(request.urlconf.urlpatterns[1], '_callback_str'))
- self.assertEqual(request.urlconf.urlpatterns[-1]._callback_str, 'tests.views.execute_sql')
+ patterns = request.urlconf.urlpatterns
+ self.assertTrue(hasattr(patterns[1], '_callback_str'))
+ self.assertEqual(patterns[-1]._callback_str, 'tests.views.execute_sql')
def test_request_urlconf_string_per_request(self):
request = rf.get('/')
@@ -89,8 +89,9 @@ class DebugToolbarTestCase(BaseTestCase):
self.assertFalse(isinstance(request.urlconf, six.string_types))
- self.assertTrue(hasattr(request.urlconf.urlpatterns[1], '_callback_str'))
- self.assertEqual(request.urlconf.urlpatterns[-1]._callback_str, 'tests.views.execute_sql')
+ patterns = request.urlconf.urlpatterns
+ self.assertTrue(hasattr(patterns[1], '_callback_str'))
+ self.assertEqual(patterns[-1]._callback_str, 'tests.views.execute_sql')
def test_request_urlconf_module(self):
request = rf.get('/')
@@ -102,8 +103,9 @@ class DebugToolbarTestCase(BaseTestCase):
self.assertFalse(isinstance(request.urlconf, six.string_types))
- self.assertTrue(hasattr(request.urlconf.urlpatterns[1], '_callback_str'))
- self.assertEqual(request.urlconf.urlpatterns[-1]._callback_str, 'tests.views.execute_sql')
+ patterns = request.urlconf.urlpatterns
+ self.assertTrue(hasattr(patterns[1], '_callback_str'))
+ self.assertEqual(patterns[-1]._callback_str, 'tests.views.execute_sql')
def test_tuple_urlconf(self):
request = rf.get('/')
@@ -191,8 +193,11 @@ class DebugToolbarIntegrationTestCase(TestCase):
ET.fromstring(response.content) # shouldn't raise ParseError
def test_view_executed_once(self):
- with self.settings(DEBUG=True, INTERNAL_IPS=['127.0.0.1'],
+ with self.settings(
+ DEBUG=True,
+ INTERNAL_IPS=['127.0.0.1'],
DEBUG_TOOLBAR_PANELS=['debug_toolbar.panels.profiling.ProfilingDebugPanel']):
+
self.assertEqual(User.objects.count(), 0)
response = self.client.get('/new_user/')
@@ -207,6 +212,7 @@ class DebugToolbarIntegrationTestCase(TestCase):
response = self.client.get('/new_user/')
self.assertEqual(User.objects.count(), 1)
+
class DebugToolbarNameFromObjectTest(BaseTestCase):
def test_func(self):
@@ -257,7 +263,7 @@ class SQLPanelTestCase(BaseTestCase):
list(User.objects.filter(username='café'))
self.assertEqual(len(panel._queries), 2)
- @unittest.skipUnless(connection.vendor=='postgresql',
+ @unittest.skipUnless(connection.vendor == 'postgresql',
'Test valid only on PostgreSQL')
def test_erroneous_query(self):
"""
diff --git a/tests/urls.py b/tests/urls.py
index 8f14a2d..93e77c4 100644
--- a/tests/urls.py
+++ b/tests/urls.py
@@ -10,11 +10,11 @@ from .models import NonAsciiRepr
admin.autodiscover()
-urlpatterns = patterns('tests.views',
+urlpatterns = patterns('tests.views', # noqa
url(r'^set_session/$', 'set_session'),
url(r'^resolving1/(.+)/(.+)/$', 'resolving_view', name='positional-resolving'),
url(r'^resolving2/(?P<arg1>.+)/(?P<arg2>.+)/$', 'resolving_view'),
- url(r'^resolving3/(.+)/$', 'resolving_view', { 'arg2' : 'default' }),
+ url(r'^resolving3/(.+)/$', 'resolving_view', {'arg2': 'default'}),
url(r'^regular/(?P<title>.*)/$', 'regular_view'),
url(r'^non_ascii_context/$', 'non_ascii_context'),
url(r'^non_ascii_bytes_in_db_params/$', 'new_user', {'username': 'djàngó'.encode('utf-8')}),