4
4
import unittest
5
5
from django .conf import settings
6
6
from pylint .testutils import make_tests , LintTestUsingFile , cb_test_gen , linter
7
+ from pylint_django .compat import django_version
7
8
8
9
9
10
settings .configure ()
20
21
linter .global_set_option ('disable' , ('E0012' ,))
21
22
22
23
24
+ SKIP_TESTS_FOR_DJANGO_VERSION = {
25
+ # if the value of the dict key is False, skip the test, otherwise run it
26
+ 'func_noerror_protected_meta_access' : django_version >= (1 , 8 )
27
+ }
28
+
29
+
23
30
def module_exists (module_name ):
24
31
try :
25
32
__import__ (module_name )
@@ -35,7 +42,22 @@ def tests(input_dir, messages_dir):
35
42
input_dir = os .path .join (HERE , input_dir )
36
43
messages_dir = os .path .join (HERE , messages_dir )
37
44
38
- return make_tests (input_dir , messages_dir , None , callbacks )
45
+ # first tests which pass for all Django versions
46
+ tests = make_tests (input_dir , messages_dir , None , callbacks )
47
+
48
+ # now skip some tests test for specific versions - for example,
49
+ # _meta access should not work for django<1.8 but should run and
50
+ # pass for django 1.4 - skip the tests which will be checking
51
+ # a piece of functionality in pylint-django that should only
52
+ # in higher versions.
53
+ specific_tests = []
54
+ for test_name , version_range in SKIP_TESTS_FOR_DJANGO_VERSION .iteritems ():
55
+ if not version_range :
56
+ specific_tests .append (test_name )
57
+ filter_rgx = '(%s)' % '|' .join (specific_tests )
58
+
59
+ tests += make_tests (os .path .join (input_dir , 'versions' ), messages_dir , filter_rgx , callbacks )
60
+ return tests
39
61
40
62
41
63
def suite ():
0 commit comments