From: Frédéric Perrin Date: Sun, 9 Oct 2016 23:21:48 +0000 (+0100) Subject: Add a pyflakes check, and fix the warnings X-Git-Url: http://gitweb.fperrin.net/?p=djsite.git;a=commitdiff_plain;h=ba8a1a46983d9e26f70a6dab5a2a3aa9ebb5425b Add a pyflakes check, and fix the warnings --- diff --git a/quotes/test_pyflakes.py b/quotes/test_pyflakes.py new file mode 100644 index 0000000..535c13a --- /dev/null +++ b/quotes/test_pyflakes.py @@ -0,0 +1,22 @@ +from django.test import TestCase + +import pyflakes.api +import os + +class PyflakesTest(TestCase): + def setUp(self): + topdir = os.path.dirname(os.path.realpath(__file__)) + self.pythonfiles = [] + + for folder, subfolders, files in os.walk(topdir): + if 'migrations' in subfolders: + subfolders.remove('migrations') + + for file in files: + if not file.endswith('.py'): + continue + self.pythonfiles += [os.path.join(folder, file)] + + def test_pyflakes(self): + for file in self.pythonfiles: + self.assertEqual(pyflakes.api.checkPath(file), 0) diff --git a/quotes/tests.py b/quotes/tests.py index fe7e0a8..66ff00b 100644 --- a/quotes/tests.py +++ b/quotes/tests.py @@ -9,11 +9,13 @@ class QuoteTest(TestCase): a1 = Author.objects.create(name="JFK") w1 = Work.objects.create(name="Berlin speech", author=a1) q1 = Quote.objects.create(text="Ich bin...", work=w1) + self.q1 = q1 def test_one(self): q = Quote.objects.filter(text__startswith="Ich") self.assertEqual(q.count(), 1) q = q[0] + self.assertEqual(q, self.q1) self.assertEqual(q.work.author.name, "JFK") class ViewsTest(TestCase): diff --git a/quotes/views.py b/quotes/views.py index bd7f6f6..df4081d 100644 --- a/quotes/views.py +++ b/quotes/views.py @@ -1,6 +1,4 @@ from django.shortcuts import render -from django.http import HttpResponse -from django.template import loader from random import randint