Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added pyflakes test

  • Loading branch information...
commit 35f48bba2a22e833efe357a8d54054e0abdb0075 1 parent 4c147b8
@ojii ojii authored
View
42 cms/test_utils/util/static_analysis.py
@@ -0,0 +1,42 @@
+import os
+import sys
+
+from pyflakes import api
+from pyflakes.checker import Checker
+from pyflakes.reporter import Reporter
+
+import cms
+import menus
+
+
+def _pyflakes_report_with_nopyflakes(self, messageClass, node, *args, **kwargs):
+ with open(self.filename, 'r') as code:
+ if code.readlines()[node.lineno - 1].strip().endswith('# nopyflakes'):
+ return
+ self.messages.append(messageClass(self.filename, node, *args, **kwargs))
+
+
+def _pyflakes_no_migrations(self, tree, filename='(none)', builtins=None):
+ if os.path.basename(os.path.dirname(filename)) == 'migrations':
+ self.messages = []
+ else:
+ Checker.___init___(self, tree, filename, builtins)
+
+
+def pyflakes():
+ """
+ Unfortunately, pyflakes does not have a way to suppress certain errors or
+ a way to configure the checker class, so we have to monkey patch it.
+
+ Returns number of warnings
+ """
+ Checker.___init___ = Checker.__init__
+ Checker.__init__ = _pyflakes_no_migrations
+ Checker.report = _pyflakes_report_with_nopyflakes
+ reporter = Reporter(sys.stdout, sys.stderr)
+ paths = [
+ os.path.abspath(os.path.dirname(cms.__file__)),
+ os.path.abspath(os.path.dirname(menus.__file__)),
+ os.path.abspath(__file__),
+ ]
+ return api.checkRecursive(paths, reporter)
View
87 cms/tests/__init__.py
@@ -1,46 +1,47 @@
# -*- coding: utf-8 -*-
-from cms.tests.admin import *
-from cms.tests.api import *
-from cms.tests.apphooks import *
-from cms.tests.docs import *
-from cms.tests.extensions import *
-from cms.tests.forms import *
-from cms.tests.i18n import *
-from cms.tests.mail import *
-from cms.tests.menu import *
-from cms.tests.menu_utils import *
-from cms.tests.multilingual import *
-from cms.tests.navextender import *
-from cms.tests.nonroot import *
-from cms.tests.page import *
-from cms.tests.permissions import *
-from cms.tests.permmod import *
-from cms.tests.placeholder import *
-from cms.tests.plugins import *
-from cms.tests.po import *
-from cms.tests.publisher import *
-from cms.tests.rendering import *
-from cms.tests.reversion_tests import *
-from cms.tests.security import *
-from cms.tests.settings import *
-from cms.tests.site import *
-from cms.tests.sitemap import *
-from cms.tests.static_placeholder import *
-from cms.tests.staticfiles import *
-from cms.tests.templatetags import *
-from cms.tests.toolbar import *
-from cms.tests.toolbar_pool import *
-from cms.tests.urlutils import *
-from cms.tests.views import *
-from cms.tests.management import *
-from cms.tests.fixture_loading import *
-from cms.tests.menu_page_viewperm import *
-from cms.tests.menu_page_viewperm_staff import *
-from cms.tests.nested_plugins import *
-from cms.tests.check import *
-from cms.tests.frontend import *
-from cms.tests.signals import *
-from cms.tests.no_i18n import *
-from cms.tests.cache import *
+from cms.tests.admin import * # nopyflakes
+from cms.tests.api import * # nopyflakes
+from cms.tests.apphooks import * # nopyflakes
+from cms.tests.docs import * # nopyflakes
+from cms.tests.extensions import * # nopyflakes
+from cms.tests.forms import * # nopyflakes
+from cms.tests.i18n import * # nopyflakes
+from cms.tests.mail import * # nopyflakes
+from cms.tests.menu import * # nopyflakes
+from cms.tests.menu_utils import * # nopyflakes
+from cms.tests.multilingual import * # nopyflakes
+from cms.tests.navextender import * # nopyflakes
+from cms.tests.nonroot import * # nopyflakes
+from cms.tests.page import * # nopyflakes
+from cms.tests.permissions import * # nopyflakes
+from cms.tests.permmod import * # nopyflakes
+from cms.tests.placeholder import * # nopyflakes
+from cms.tests.plugins import * # nopyflakes
+from cms.tests.po import * # nopyflakes
+from cms.tests.publisher import * # nopyflakes
+from cms.tests.rendering import * # nopyflakes
+from cms.tests.reversion_tests import * # nopyflakes
+from cms.tests.security import * # nopyflakes
+from cms.tests.settings import * # nopyflakes
+from cms.tests.site import * # nopyflakes
+from cms.tests.sitemap import * # nopyflakes
+from cms.tests.static_placeholder import * # nopyflakes
+from cms.tests.staticfiles import * # nopyflakes
+from cms.tests.templatetags import * # nopyflakes
+from cms.tests.toolbar import * # nopyflakes
+from cms.tests.toolbar_pool import * # nopyflakes
+from cms.tests.urlutils import * # nopyflakes
+from cms.tests.views import * # nopyflakes
+from cms.tests.management import * # nopyflakes
+from cms.tests.fixture_loading import * # nopyflakes
+from cms.tests.menu_page_viewperm import * # nopyflakes
+from cms.tests.menu_page_viewperm_staff import * # nopyflakes
+from cms.tests.nested_plugins import * # nopyflakes
+from cms.tests.check import * # nopyflakes
+from cms.tests.frontend import * # nopyflakes
+from cms.tests.signals import * # nopyflakes
+from cms.tests.no_i18n import * # nopyflakes
+from cms.tests.cache import * # nopyflakes
+from cms.tests.static_analysis import StaticAnalysisTest # nopyflakes
View
7 cms/tests/static_analysis.py
@@ -0,0 +1,7 @@
+from unittest import TestCase
+from cms.test_utils.util.static_analysis import pyflakes
+
+
+class StaticAnalysisTest(TestCase):
+ def test_pyflakes(self):
+ self.assertEqual(pyflakes(), 0)
View
30 develop.py 100644 → 100755
@@ -1,4 +1,4 @@
-#!/bin/env python
+#!/usr/bin/env python
from __future__ import print_function, with_statement
import contextlib
import multiprocessing
@@ -13,8 +13,9 @@
from django import VERSION
from django.utils import autoreload
-from cms import __version__
+import cms
from cms.test_utils.cli import configure
+from cms.test_utils.util import static_analysis
from cms.test_utils.tmpdir import temp_dir
__doc__ = '''django CMS development helper script.
@@ -31,6 +32,7 @@
develop.py shell
develop.py compilemessages
develop.py makemessages
+ develop.py pyflakes
Options:
-h --help Show this screen.
@@ -86,6 +88,7 @@ def server(bind='127.0.0.1', port=8000, migrate=False):
'use_threading': True
})
+
def _split(itr, num):
split = []
size = int(len(itr) / num)
@@ -93,6 +96,7 @@ def _split(itr, num):
split.append(itr[size * index:size * (index + 1)])
return split
+
def _get_test_labels():
test_labels = []
for module in [name for _, name, _ in pkgutil.iter_modules([os.path.join("cms","tests")])]:
@@ -103,6 +107,7 @@ def _get_test_labels():
test_labels.append('cms.%s.%s' % (clsname, method))
return test_labels
+
def _test_run_worker(test_labels, failfast=False, test_runner='django.test.simple.DjangoTestSuiteRunner'):
warnings.filterwarnings(
'error', r"DateTimeField received a naive datetime",
@@ -116,9 +121,11 @@ def _test_run_worker(test_labels, failfast=False, test_runner='django.test.simpl
failures = test_runner.run_tests(test_labels)
return failures
+
def _test_in_subprocess(test_labels):
return subprocess.call(['python', 'develop.py', 'test'] + test_labels)
+
def isolated(test_labels, parallel=False):
test_labels = test_labels or _get_test_labels()
if parallel:
@@ -130,9 +137,11 @@ def isolated(test_labels, parallel=False):
failures = [test_label for test_label, return_code in zip(test_labels, results) if return_code != 0]
return failures
+
def timed(test_labels):
return _test_run_worker(test_labels, test_runner='cms.test_utils.runners.TimedTestRunner')
+
def test(test_labels, parallel=False, failfast=False):
test_labels = test_labels or _get_test_labels()
if parallel:
@@ -144,22 +153,29 @@ def test(test_labels, parallel=False, failfast=False):
else:
return _test_run_worker(test_labels, failfast)
+
def compilemessages():
from django.core.management import call_command
os.chdir('cms')
call_command('compilemessages', all=True)
+
def makemessages():
from django.core.management import call_command
os.chdir('cms')
call_command('makemessages', locale='en')
+
def shell():
from django.core.management import call_command
call_command('shell')
-if __name__ == '__main__':
- args = docopt(__doc__, version=__version__)
+
+def main():
+ args = docopt(__doc__, version=cms.__version__)
+
+ if args['pyflakes']:
+ return static_analysis.pyflakes()
# configure django
warnings.filterwarnings(
@@ -186,7 +202,7 @@ def shell():
if args['test']:
configs['SESSION_ENGINE'] = "django.contrib.sessions.backends.cache"
-
+
# Command line option takes precedent over environment variable
auth_user_model = args['--user']
@@ -245,3 +261,7 @@ def null_context():
compilemessages()
elif args['makemessages']:
compilemessages()
+
+
+if __name__ == '__main__':
+ main()
Please sign in to comment.
Something went wrong with that request. Please try again.