Skip to content

Commit 0e3aecd

Browse files
author
Pamela McA'Nulty
committed
Make flake8 happy
1 parent 738d3a4 commit 0e3aecd

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

django_coverage_plugin/plugin.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@ def check_debug():
4747
from django.conf import settings
4848

4949
if not settings.configured:
50-
#print("check_debug: settings not configured")
5150
return False
5251

5352
if django.VERSION >= (1, 8):
5453

5554
from django.apps import apps
5655
if not apps.ready:
57-
#print("check_debug: apps not ready")
5856
return False
5957

6058
# Django 1.8+ handles both old and new-style settings and converts them
@@ -64,14 +62,11 @@ def check_debug():
6462
# django.template.backends.django gets loaded lazily, so return false
6563
# until they've been loaded
6664
if not hasattr(django.template, "backends"):
67-
#print("check_debug: no 'backends' in django.template")
6865
return False
6966
if not hasattr(django.template.backends, "django"):
70-
#print("check_debug: no 'django' in django.template.backends")
7167
return False
7268

7369
if not hasattr(django.template.backends.django, "DjangoTemplates"):
74-
#print("check_debug: no 'DjangoTemplates' in django.template.backends.django")
7570
raise DjangoTemplatePluginException("Can't use non-Django templates.")
7671

7772
for engine in django.template.engines.all():

tests/test_integration.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,11 @@ def lower(value):
8686
"""
8787

8888

89-
9089
class IntegrationTest(DjangoPluginTestCase):
9190
"""Tests greenfield settings initializations and other weirdnesses"""
9291

9392
def setUp(self):
9493
self.python = os.path.abspath(os.environ['_'])
95-
#print("PYTHON:", self.python)
9694
if ".tox" in self.python:
9795
self.env_bin = os.path.dirname(self.python)
9896
else:
@@ -103,14 +101,15 @@ def set_cwd(self, path):
103101
self.cwd = path
104102

105103
def _cmd(self, *args, **kwargs):
106-
#print args, kwargs
107104
try:
108105
output = subprocess.check_output(args, cwd=self.cwd, stderr=subprocess.STDOUT, **kwargs)
109106
return output.decode("utf-8").strip()
110107
except subprocess.CalledProcessError as e:
111-
raise Exception("Called Processed Error:\n cmd: %s\n exc: %s\ncwd: %s\n output:\n%s" % (args, e, self.cwd, e.output))
108+
fmt = "Called Processed Error:\n cmd: %s\n exc: %s\ncwd: %s\n output:\n%s"
109+
raise Exception(fmt % (args, e, self.cwd, e.output))
112110
except OSError as e:
113-
raise Exception("OS Error:\n cmd: %s\n exc: %s\ncwd: %s\n" % (args, e, self.cwd))
111+
fmt = "OS Error:\n cmd: %s\n exc: %s\ncwd: %s\n"
112+
raise Exception(fmt % (args, e, self.cwd))
114113

115114
def _pycmd(self, *args, **kwargs):
116115
args = [self.python] + list(args)
@@ -133,15 +132,14 @@ def _start_project(self, project_name):
133132
data = f.read()
134133
data = data.replace("'django.db.backends.'", "'django.db.backends.sqlite3'")
135134
with open(self.settings_file, "w") as f:
136-
f.write(data)
135+
f.write(data)
137136
self._add_installed_app("django_coverage_plugin")
138-
#self.addCleanup(shutil.rmtree, self.project_dir)
137+
self.addCleanup(shutil.rmtree, self.project_dir)
139138
return output
140139

141140
def _add_installed_app(self, app_name):
142141
with open(self.settings_file) as f:
143142
settings_data = f.read()
144-
#self._print_file(settings_data, self.settings_file)
145143

146144
sep_open, sep_close = ("(", ")") if django.VERSION < (1, 9) else ("[", "]")
147145
try:
@@ -185,18 +183,21 @@ def _run_coverage(self, *args):
185183
self.assertNotIn("Disabling plugin", output)
186184
env = os.environ.copy()
187185
env['DJANGO_SETTINGS_MODULE'] = self.settings_file
188-
coverage_report = self._cmd_global("coverage", "report", "-m", "--rcfile", self.config_file, env=env)
186+
coverage_report = self._cmd_global(
187+
"coverage", "report", "-m", "--rcfile", self.config_file,
188+
env=env
189+
)
189190
coverage_report = self.parse_coverage_report(coverage_report)
190191
return output, coverage_report
191192

192193
def _create_django_project(self, project_name, app_name):
193194
self.cwd = os.getcwd()
194195
self._start_project(project_name)
195196
self._start_app(app_name)
196-
#with open(self.settings_file) as f:
197-
# print f.read()
198197
self.config_file = self._add_project_file(COVERAGE_CFG_FILE_TEXT, "coverage.cfg")
199-
self.template_file = self._add_project_file(TEMPLATE_FILE_TEXT, app_name, "templates", "target_template.html")
198+
self.template_file = self._add_project_file(
199+
TEMPLATE_FILE_TEXT, app_name, "templates", "target_template.html"
200+
)
200201

201202
if django.VERSION < (1, 8):
202203
define_target_view = '"app_template_render.views.target_view"'
@@ -213,7 +214,9 @@ def _create_django_project(self, project_name, app_name):
213214
self.views_file = os.path.join(self.project_dir, app_name, "views.py")
214215
self.urls_file = os.path.join(self.project_dir, project_name, "urls.py")
215216
self.test_views_file = self._add_project_file("", app_name, "templatetags", "__init__.py")
216-
self.test_views_file = self._add_project_file(TEMPLATE_TAG_TEXT, app_name, "templatetags", "test_tags.py")
217+
self.test_views_file = self._add_project_file(
218+
TEMPLATE_TAG_TEXT, app_name, "templatetags", "test_tags.py"
219+
)
217220

218221
self._add_view_function(app_name, VIEW_FUNC_TEXT)
219222
self._add_url(project_name, app_name, "target_view", "target_view")
@@ -235,20 +238,24 @@ def _add_view_function(self, app_name, view_text):
235238
views_data = "%s\n%s\n" % (views_data, view_text)
236239
self._save_py_file(self.views_file, views_data)
237240

238-
239241
def _add_url(self, project_name, app_name, view_func, view_name):
240242
with open(self.urls_file) as f:
241243
urls_data = f.read()
242244

243245
if django.VERSION < (1, 8):
246+
before = "\n)\n"
247+
fmt = " url(r'^$', '%(app_name)s.views.target_view', name='target_view')\n)\n"
248+
after = fmt % locals()
249+
urls_data = urls_data.replace(before, after)
250+
251+
else:
244252
urls_data = urls_data.replace(
245-
"\n)\n",
246-
" url(r'^$', '%(app_name)s.views.target_view', name='target_view')\n)\n" % locals(),
253+
"urlpatterns = [",
254+
"import %s.views\n\nurlpatterns = [" % app_name
247255
)
248-
else:
249-
urls_data = urls_data.replace("urlpatterns = [", "import %s.views\n\nurlpatterns = [" % app_name)
250256
fmt = ''' url(r'^%(app_name)s/', %(app_name)s.views.%(view_func)s),\n]'''
251257
urls_data = urls_data.replace("]", fmt % locals())
258+
252259
self._save_py_file(self.urls_file, urls_data)
253260

254261
@django_start_at(1, 8)
@@ -261,7 +268,7 @@ def test_template_render(self):
261268
self.assertNotIn("ERROR", output)
262269
self.assertNotIn("FAIL", output)
263270

264-
import pprint;pprint.pprint(coverage_report)
271+
# import pprint;pprint.pprint(coverage_report)
265272
self.assertIsCovered(coverage_report, "integration_template_render/settings.py")
266273
self.assertIsCovered(coverage_report, "integration_template_render/__init__.py")
267274
self.assertIsCovered(coverage_report, "integration_template_render/urls.py")
@@ -306,10 +313,12 @@ def __init__(self, num_lines, num_missing, pct, missing):
306313
self.missing = missing
307314

308315
def __unicode__(self):
309-
return u"%s/%s/%s%%%%/%s" % (self.num_lines, self.num_missing, self.pct, self.missing)
316+
fmt = u"%s/%s/%s%%%%/%s"
317+
return fmt % (self.num_lines, self.num_missing, self.pct, self.missing)
310318

311319
def __repr__(self):
312-
return u"ReportInfo(num_lines=%r, num_missing=%r, pct=%r, missing=%r)" % (self.num_lines, self.num_missing, self.pct, self.missing)
320+
fmt = u"ReportInfo(num_lines=%r, num_missing=%r, pct=%r, missing=%r)"
321+
return fmt % (self.num_lines, self.num_missing, self.pct, self.missing)
313322

314323
def missing_line_numbers(self):
315324
for chunk in self.missing.split(","):

0 commit comments

Comments
 (0)