From ba8a1a46983d9e26f70a6dab5a2a3aa9ebb5425b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Perrin?= Date: Mon, 10 Oct 2016 00:21:48 +0100 Subject: [PATCH] Add a pyflakes check, and fix the warnings --- quotes/test_pyflakes.py | 22 ++++++++++++++++++++++ quotes/tests.py | 2 ++ quotes/views.py | 2 -- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 quotes/test_pyflakes.py 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 -- 2.43.0